IT’S BETTER TO FADE AWAY ...
PROPELLER PLATFORM KITS!
Let’s jump into the driver one more time and add a
final feature: brightness control. As you’d expect, this
is going to be accomplished with PWM (pulse width
modulation) of the LED, but there is a catch: We’re
using a bi-color LED and current can be flowing in
either direction (or alternating), so how do we modulate
brightness? The answer is actually pretty simple: We
modulate the direction control pin of one of the anodes.
You see, if we make either anode control pin an input
there will be no current flow — in any direction —
through the LED.
Here’s another reason why I went with a 10us
inner loop: multiplying that by 100, we get a convenient
one millisecond timing interval and we also have a
counter to use for on-off control of the PWM cycle in
1% increments. Let’s look at the code that gets inserted
before the loopwait section (you’ll find this in
Good news, gang! The response to the Propeller
Platform was so positive (one Parallax forum member
dubbed it “Propellerino”) that my good friend, Ken
Gracey, has agreed to make kits available through Parallax.
This will certainly simplify building the P/P and save you
money over having to buy raw PCBs yourself. Figure 2
shows the final prototype; I really like the way it turned
out. The only change from the original design is the
regulators. We changed from the LM108x series to the
LM29xx series to simplify parts procurement. My original
thought for the high-current regulators was that I could
use them for powering servos. Well, having worked with
a lot of servo animatronics between the first version
and now I found that this doesn’t help and for big
animatronics an external servo power supply is in order.
test level, level wz
andn dira, gMask
cmp loopCntr, level wc
or dira, gMask
andn dira, gMask
The top of the pwmctrl section first checks the value
of level (brightness setting) for zero; when it is, we will
turn off the output (by making the green pin an input) and
skip right to loopwait. When level is something greater
than zero, it is compared to loopCntr and when loopCntr
is below the level setting we will turn the LED on. When
loopCntr reaches level, the on-cycle is complete and we
turn the LED off.
In the end, what we get is fixed-frequency,
variable duty-cycle PWM that causes the LED to be
on for the percentage set in level. So, what happens
if we set level greater than 100? Nothing harmful; at
100 or higher, the LED will be on all the time as the
value of loopCntr cycles between 0 and 99.
I like this kind-of fixed-frequency PWM code
because it’s easy to configure. I recently used
it in an RGB LED object and it worked really
Before I close, I want to tell you something
about jw_bicolor_v3_demo2.spin. This
program shows how we can launch another
cog to control the brightness of the LED
object in the background; for example, to
handle automated fades. The key here is
having the LED object reveal the hub address
of its brightness control variable. With this
information, another object can manipulate
brightness for advanced control. Check it out,
it’s pretty neat.
Okay, admit it … when you first started reading this
column you groaned, “Come on, Williams, LEDs again?
Are you nuts?” Yeah, I get it, but I think I’ve shown that
the lowly LED can become a thing of wonder with some
cool code in the Propeller chip. I’m a big believer in
learning new coding techniques with simple hardware and
you can’t get much simpler than an LED, right?
Okay, it’s time to go experiment because we’ve laid
the groundwork for a pretty serious project next time: Waldo
Part Deux. Yep, the Waldo project from back in September
2007 was hugely popular, so for its two year anniversary
we’re going to recreate it for the Propeller and even add
two more channels. The hardware will be a plug-in module
for the Propeller platform that includes mini joysticks and
all the support circuitry. In addition to the LED object we
just created, we’ll also create and use background ADC and
servo control objects — it’s going to be a lot of fun and a
very cool project for use in your holiday animatronics displays.
Until next time, then, here’s to spinning and winning
with the Propeller. NV
■ FIGURE 2. Propeller Platform.
July 2009 21