Why not just let hardware handle most all of this for you?
Code:
' include your hardware/config stuff here
Revs VAR BYTE ' holds up to 255 revolutions
ANSEL = 0 ' disable A/D so RA4 is digital
CMCON = 7 ' disable comparators
OPTION_REG = %00110001 ' RA4 = count input
' inc count every 4th falling edge with 1:4 prescale
' assigned to TMR0
Mainloop:
TMR0 = 0 ' clear count before pause
PAUSE 20 ' Adjust this to set how long it counts revolutions here
Revs = TMR0 ' TMR0 counts 1 rev for every 4 pulses
LCDOUT $FE,1,"Revs: ",DEC Revs
' do other stuff here, then return to get more counts
GOTO Mainloop
This will be a LOT faster than interrupting on every single pulse, and counting
in software. You should be able to give the wheel a pretty good spin without
missing anything.
Bookmarks