Thanks Henrik,
I was concerned that stopping the timer and restarting it would throw off the measurement, as I am sure it would. I tried it with just clearing the timer registers and tested it, and all seems good. Just checking for a timer overflow which if occurred will exit the capture routine.
Code:
TMR1H=0 'Clear 8-bit register
TMR1L=0 'Clear 8-bit register
T1CON.0=1 'starts timer
overflow=0 'Clear overflow bit
capture=0 'Clear Timer
Trash:
If Capture = 0 then
if overflow=1 then
rpm=0
T1Con.0=0
return
endif
Goto Trash
endif
TMR1H=0 'Clear 8-bit register
TMR1L=0 'Clear 8-bit register
Capture=0 'waste first capture
Overflow=0 'Clear overflow bit
CaptureLoop:
If Capture = 0 then
if overflow=1 then
rpm=0
T1Con.0=0
return
endif
Goto CaptureLoop
endif
T1Con.0=0
period.LowByte=CCPR1L
period.HighByte=CCPR1H
TMR1H = 0
TMR1L = 0
Capture = 0
Overflow = 0
Bookmarks