Page 198 - Build Your Own Quadcopter_ Power Up Your Designs with the Parallax Elev-8
P. 198
Chapter 7: Ser v o Motors and Extending the Ser v o Control System 177
long[pulsewidth_address][1]~
active1 := false
active2 := false
synCnt := clkfreq/4 + cnt
repeat until synCnt =< cnt ‘ wait 1/4 second to check if
pins are active
if ina[p1] == 1
active1 := true
if ina[p2] == 1
active2 := true
repeat
if active1 == true
waitPEQ(0, |< p1, 0) ‘wait for low state, do not
start counting when high
phsa~ ‘counter set to zero
waitPEQ( |< p1 , |< p1, 0) ‘wait for high
waitPEQ(0, |< p1, 0) ‘wait for low state i.e.
pulse ended
long[pulsewidth_address][0] := phsa/uS
if active2 == true
waitPEQ(0, |< p2, 0)
phsb~
waitPEQ( |< p2, |< p2, 0)
waitPEQ(0, |< p2, 0)
long[pulsewidth_address][1] := phsb/uS
DAT
The RX_demo and RX programs exchange data using a common technique called
indirection, where variables represent the physical memory addresses of the data. In C and
C++, these indirect variables are called pointers. It is a powerful and very efficient means to
exchange data, but be aware that it has inherent dangers, since you can easily misuse a
pointer and crash your program and maybe the whole computer. Two references are created
in the RX_demo program, as shown below:
VAR
long pulsewidth[4]
DAT
pins LONG 14, 15, 16
The array named pulsewidth has four “long” word elements that may be indexed
as pulsewidth[0] to pulsewidth[3]. Data may be written to and/or read from