Page 120 - Making PIC Microcontroller Instruments and Controllers
P. 120
IIO TII'EES AND COUI{TEFS
-
:iiFiliiliieii a,? Timerl as counter (Timerl counls slgnals lrcm a molor encode4
(Continued)
X VAR }IORD ; spare tariable for experinenlation
Y VAR WORD ; spare variable for experinentarlon
PAUSE 500 , pause for LcD to slrart up
T,CDOIIT gFE, 1 ; cLear Display and cursor hone
; set uP ihe register I/O
ERIsc = %11110001 ; PoRTc- 0 is qloing to be the InpuL
ccPlcoN = %ooooo101 ; caplure ewerv rising edge
rlcotir = %OOooOO1l ; no prescale/osc offlsvnc on
; external source/TMRl on
; sLart the notor, usinq a notor encoder
PORTC.3-0 ; enabLe Lhe n'olor
PORTC - 2-1 ; set the rotation direction
; Next fe go inLo the bodv of Lhe prograi. fhe toop stails watn
; Lhree potenlioneters though tne are using onlv rhe frrst one Lo
; set the Pover
; and thus the speed of the notor.
a.DclN 0, a.DvAl,o read chamel 0 to aDvAL!
A.DCIN 1, ADI/AI,I
ADCIN 3, A.DVA'"2
; If Lhe duty cycLe of the notor is tess Lhan 20 out of 255 lhe
; notor wiLl noL cone on
; so we make an allowance for ihat and displav ihe condition on
IF ADVAI,O>zo IEIIEN
HP9!M 2. AD\rBlo, 32000
*Pl'l![ = \, '?
r,cDour sFE, 9C0, DEC ADVAIJ0,
El,SE
'Pl{li .,DEC / \
t cDour $FE, Sco, TOO LOW ltDVArJo,
ENDIF
Then we read the cwo tiner regislers to see hov nanv coun's
In our case the counts were too Lo{ to shou up in the high
it can be isnored but j.f vou hawe a faster coun! input, vou
ro add this infornatiod to the readout
tMRlE = 0 ; clear Tinerl high 8_bits
TMR1L = 0 ; clear Tinerl low 8-bits
T1CON.o = 1 , slarL 16 bit tiner
PAUSE 1OO ; caplure 100 ns of Input clock Frequencv