Page 276 - Making PIC Microcontroller Instruments and Controllers
P. 276
SUILDI G THE ARIIFICIAL HOFIZOII TAELE 275
The preceding exercise denonstrates the rclative ease with which we can make a fairly
sophisticated instrumenl, lile an artificial horizon, when we use a PIC microcontroller
as our logic engine,
This instrument could easily be modilied to show how may g-forces you went through
as you turned a corner in a car. ln this case, the sensing axis of the sensor would have
to be placed left to right acrcss the automobile, and a m ltiplier would have to be
adjusted to give a rcasonable display on the LCD.
TWO-AXIS SOFTWABE
To make a fwo servo table that keeps the table top horizontal in both directions, we have
to add the code for the second servo (see Program 19.3) The LCD paft of the progran
does not change. Afterthat...
lri-P.diiiiiiiitlt€r Program lor the dual-axis artilicial horizon
; Set up the variables lo be used
At PtlA VAR WORD ; set yariable alpha
BEIA VAA WORD i second variable for second axis
i body of nain loop
LOOP: ) start loop
PttrsIN PoRIc.2r 1, arpnA ed.- e pL_ e _!on M-ms: -oL x
PIII,SIN PORTC.z, 1, BETA i edr- - pL ^ Ilom M-ms: Io_ x
r.cDouT sFE, s80. DEc4 Aj-pHA,. ., DEC4 BE!A, . Men6ic"
; print conditions
LCDOUT SFE, SCo, DEC4 ((5*(AT,PIIA-493))+1310)," Itulse !o Eervo\
; print conditions
PORTC.o = t ; start servo l pulse
(
P A U S E U S 1 3 1 0 + ( 5 * ( A L P I I A - 4 9 3 ) ) ) e ' g L h o t p r - , - - o ! c r v o 2
PORIFC.0 = 0 ; end pulse 1
POREC.I = 1 ; slar! servo 2 pulse
(
P A U S E U S 1 3 1 0 + ( 5 * ( B E T A - 4 9 3 ) ) ) p - s ^ - o r ' e r v o -
PORTC.I = 0 ; end pulse 2
PAUSE 15
GOIO LOOP
END ; always end with end
Buildins the Artificial Horizon Table
The easiest way for us to build the table is to build two rables one above the otherwith
the two controlled axes at nghtangles to one another. The problem is that thetwo axes
will not be completcly independert because ofthe mechanical interactions in a simple,