Page 104 - Build Your Own Quadcopter_ Power Up Your Designs with the Parallax Elev-8
P. 104
Chapter 4: Prog ramming the P arallax Propeller Chip 83
soon discuss some programming approaches to mitigate the potentially adverse effects for
this clock cycle variability.
There is one other RC clock mode that may be of some interest especially for extremely
low-power applications. This mode is the slow RC clock mode in which the clock rate is only
20,000 Hz, which is almost 1000 times slower than the default RCFAST mode. Figure 4.12
shows the PST Full Source code view for the program named SlowBlinker1 that demonstrates
this slow-speed operation. The Delay numbers have also been significantly reduced by a
factor of 1000 due to the long times caused by using a slow clock speed.
The timing experiment was repeated for pin 15 and revealed a similar time of 13.36
seconds, which makes perfect sense, since the clock rate and delay were both scaled down
by the same factor of 1000. A review of the SlowBlinker1 source code reveals that there is
a new section named CON (which is short for CONSTANT). There is only one statement in
the CON section:
_CLKMODE = RCSLOW
The name _CLKMODE is a built-in constant that the Spin software uses to set the desired
clock mode. The name RCSLOW is simply equivalent to an integer that represents the clock
mode. It does not matter what the actual number value is because Spin is programmed to
respond to a given number to set a specific clock mode. Using this approach prevents an
unfortunate programming practice known as magic numbers. To make this a bit clearer, let
us suppose that the actual number for setting a slow RC clock mode is 8. Using this
information would change the above clock mode expression to:
_CLKMODE = 8
This expression by itself makes no sense without the additional information that the
number 8 actually represents the slow RC clock mode. That is why using 8 in the above
Figure 4.12 SlowBlinker1, Full Source view.