Page 114 - Build Your Own Quadcopter_ Power Up Your Designs with the Parallax Elev-8
P. 114
Chapter 4: Prog ramming the P arallax Propeller Chip 93
pulse[i] += ((_pulseList[i] - pulse[i]) #> -_stepList[i]
<# _stepList[i])
if ((_enableMask >> i) & 1)
spr[PHS + ch] := -((pulse[i] #> -1000 <# 1000) * us +
center)
waitcnt(t += frame)
repeat until not lockset(lockID)
longmove(@_pinlist, @pinList, 48)
lockclr(lockID)
waitcnt(t += cycleEnd)
You should first notice that the method begins with a PRI identifier, which is short for
PRIVATE. This means that the Servos method is available only to other methods within the
PropBOE Servos object and no other external object can call it. This restriction helps promote
an important OO principle known as encapsulation. Objects should not reveal too much
information on how they work internally so that unintentional changes are minimized.
The variable array _pinList[i] is set up to handle multiple servos operating
simultaneously. This is a key advantage for the parallel processing that the Prop chip
supports. It definitely is a great asset in this application.
There are two key statements in the above code that begin with the identifier spr. This is
a Spin instruction that is short for Special Purpose Register (SPR), which allows you to
indirectly access some specialized registers that are present in each cog. A register, for those
unfamiliar with the term, is a named storage area where data can be read or written. I have
included a list of a cog’s SPRs taken from the Propeller User's Manual in Figure 4.24 because
I think that you should be aware of them. They are an extremely valuable asset used in
creating code that executes quickly and efficiently.
Figure 4.24 Cog Special Purpose Registers (SPR).