reset_delay mov bittimer, resettix
add bittimer, cnt
waitcnt bittimer, #0
One of the big changes with this new driver is that it
doesn’t contain its own pixel buffer; this means that we
have to create them in our application:
This probably looks more complicated than it is —
we’re simply shifting each bit of colorbits using MSBFIRST
mode. Since the new driver uses left-aligned color values,
there is no prep required; we simply sample bit31 using
rcl (rotate carry left) and saving the bit in the carry flag.
The timing for high and low periods is loaded into bittimer
based on the state of the carry flag, and timing is
accomplished with waitcnt. Once all bits of the current
pixel are transmitted, we jump back to frame_loop for the
In this case, I’ve actually defined three buffers that we
can switch between at any time. This is handy for
animations. Matt uses this strategy with pixel strings in
some of his arcade games and animatronic displays.
After all pixels have been transmitted, the program
drops to reset_delay. This creates the quiet period
between transmissions. When that time expires, we jump
all the way back to rgbx_main where the connection is
retested. Perhaps now you can see why I recommend
keeping the reset delay period short. We cannot change
connection properties until the reset period has expired.
When starting the driver, we’ll select the method that
matches our pixel type. The Adafruit rings use WS2812b
pixels; hence, we start the driver like this:
strip.start_2812b(@pixbuf1, STRIP_LEN, LEDS,
It’s been a while since we’ve gone top-to-bottom
through the PASM code of a driver. I hope that if you’ve
been fearful of trying PASM you’ll reconsider. As with
Remember to use with the name of the pixel buffer
as the driver needs a pointer. If we leave out the @, what
gets passed is the value of pixbuf1 — which will be zero
when the program starts.
Switching between buffers is handled by the use()
method. Let’s look at a simple demo with primary colors:
Spin, PASM is simple and elegant, and allows anyone to
jump in. Yes, there are some programmers
in the Propeller world that do crazy tricks
in PASM; the good news is we don’t have
to go that direction until we’re ready.
I have a friend named Marko who is
one of those amazing programmers. From
time to time, he’ll take a bit of my PASM
code and show me his variation. There
have been moments when I thought my
head was going to explode like a victim in
Scanners. It can take me some time to
understand what he’s doing.
The thing is, Marko’s code always
works and is amazingly efficient. I suggest
that we code for clarity first, and then look
for opportunities to be more efficient.
■ FIGURE 4. PAB driving NeoPixel ring.
Let’s put the new driver to work. Like many,
I love the Adafruit NeoPixel rings and have used
these in several projects. The image in Figure 4
shows a PAB-WX equipped with a couple shields
I created for my friends at Adventure Sports HQ
in Dallas. This happens to be part of a laser-tag
On the main shield, I have my favorite level-shifting circuit using the TC4427 for the pixel
output. I love this chip because it provides level
shifting and a really stiff output which lets us
drive a long signal line. See Figure 5 for a two-string level shifter using the TC4427.
■ FIGURE 5. Two-line pixel driver.
March 2017 57