Create successful ePaper yourself
Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.
worldmags<br />
PWM(), respectively. Examining these methods, you would<br />
notice they each have an infinite loop that would never<br />
finish. Quad continuously monitors <strong>and</strong> updates the<br />
quadrature state count, <strong>and</strong> PWM() ensures the PWM<br />
signal is constantly updated.<br />
In traditional interrupt or event-driven programming,<br />
these loops would have to be “interrupted” occasionally to<br />
allow for the rest of the program to execute. Also, since<br />
they would be running together you wouldn’t be able to<br />
put them in two separate loops like we have them now.<br />
Furthermore, due to the interruptions their actions would<br />
not be fully deterministic, meaning that the system may<br />
have signaling jitter <strong>and</strong> missed pulse counts while other<br />
tasks are being h<strong>and</strong>led by the processor.<br />
In the Propeller chip, these two methods run fully in<br />
parallel in their own cogs eliminating the need for<br />
interrupts. Notice the statements that call CogNew() in the<br />
Start() methods in both figures. This function launches the<br />
associated method (subroutine) into one of the eight cogs.<br />
Once a cog is started, it will continuously do its tasks<br />
independently of other cogs. However, notice how in<br />
Figure 11 the PWM duty level is set. This is the way to<br />
communicate between the cog that is<br />
running the main program <strong>and</strong> the cog that<br />
carries out the PWM work. We just set a<br />
value within the hub RAM which PWM()<br />
knows about <strong>and</strong> can read. Upon reading<br />
this value, it will change the duty level of the<br />
PWM signal.<br />
Likewise, the quadrature encoder cog<br />
will continue to interrogate the infrared<br />
hardware <strong>and</strong> update the state count into a<br />
variable in the hub RAM. The cog running<br />
the main program reads this count when<br />
needed from that variable.<br />
We do not have to worry about<br />
contention h<strong>and</strong>ling because the Propeller<br />
chip does that for us by ensuring that each<br />
cog can only read or write to the hub RAM<br />
in a round robin fashion. This guarantees<br />
that no two cogs can simultaneously read<br />
<strong>and</strong> write to the shared memory.<br />
The round robin contention prevention<br />
works on a long (32 bits) by long basis.<br />
Should you need to ensure exclusive access<br />
to a block of memory over multiple round<br />
robin turns, the Propeller chip also provides<br />
hardware-based semaphores (eight of them,<br />
called locks) which simplify semaphore<br />
programming tremendously. In our programs,<br />
we do not need them since we are only<br />
using longs for the PWM duty <strong>and</strong> the<br />
quadrature state count.<br />
Putting A Fresh Spin<br />
On Things<br />
The RobotBASIC program was necessary<br />
in the original project because we needed a GUI for the<br />
operator of the system to be able to comm<strong>and</strong> it.<br />
Additionally, the simulator aspect was powerful for the<br />
purposes of operator training <strong>and</strong> for tweaking system<br />
parameters like PID factors. With the Propeller-based<br />
project, you are able to dispense with the PC system (with a<br />
caveat).<br />
With the Propeller chip <strong>and</strong> a few pre-written powerful<br />
objects <strong>and</strong> some resistors, you can add a PS/2 mouse <strong>and</strong><br />
keyboard, as well as a VGA (or TV) display to the system.<br />
The Propeller can also do floating point math (using an<br />
object) which would enable the implementation of an<br />
accurate PID control algorithm. You can therefore<br />
implement the user interface for the operator, as well as<br />
the PID control using just the Propeller chip.<br />
This is definitely a powerful option, but the graphics<br />
<strong>and</strong> GUI are not going to be as powerful as you can<br />
achieve on a PC. Also, a PC system can provide additional<br />
processing <strong>and</strong> other services that can enhance a Propellerbased<br />
project (e.g., the simulator in this project). SV<br />
www.servomagazine.com/index.php?/magazine/article/<br />
december2010_Blankenship<br />
FIGURE 13. PWM<br />
controller program.<br />
SERVO 12.2010 75<br />
worldmags