With the exception of being fixed at 16 bits, this
code is just like the Spin code to transfer bits to the
For MSBFIRST output, we shift outbits left by 16 to
position our MSB in outbits.bit31. At :loop, we shift
outbits to the left by one, capturing bit31 in the Carry
flag. We transfer the Carry flag to the data output using
muxc and the data pin mask. A nop is inserted to let the
data pin settle before bringing the clock pin high. Again,
This process is repeated for all bits. When all have
been shifted, the latch pin is taken high, then back low —
you've seen this before.
The cycle counter is incremented and ANDed with
$FF to keep 0 to 255. At this point, we jump back to the
top and do it all over again.
In this object, we're not using discrete bits, but DMX-compatible byte values (0 to 255)
for each output, so we have to run
the PWM loop 256 times. There is a
little bit of loop "wobble" due to the
way a zero level is handled, but for
LEDs I don't see this as a problem.
A quick test showed that the PWM
frequency is better than 150 Hz.
More Oomph for
I fibbed a bit about Matt's
board. We're not actually using
74HC595 shift registers on it. What
we are using is the signal-compatible
TPIC6A595. From a code
standpoint, this chip works just like
the 74HC595 — even with PWM.
The difference is in the outputs. The
TPIC6A595 uses open-drain
MOSFET outputs that are capable of
handling up to 50V at 350 mA each,
and they cannot be tri-stated. This
chip is well-suited for controlling
relays and solenoids, hence found in
a lot of industrial applications.
Okay ... as if you needed an
excuse to hook-up and control that
box full of LEDs you've got sitting on
your workbench — now you have a
way to do it without using up all
your Propeller I/O pins.
Happy New Year! Until next
time, keep spinning and winning
with the Propeller! NV
18 January 2014
Jon "JonnyMac" McPhalen
Propeller chips and