Hi capitano,
Could be a simple problem.
You're starting off with the Capture triggering on the rising edge, and State = 0
CCP1CON = %00000101
On the first interrupt, it starts the timer and changes the State to 1. But I think at this point you also need to change the capture mode to trigger on the Falling edge.
CCP1CON = %00000100
On the next time through the interrupt, take the reading, clear the timer and State, then set it to trigger on the Rising edge again.
This would measure a HIGH pulse. To measure the LOW pulse just reverse the Rising/Falling edges.
Something like this:
Code:
interr:
'************************************
'Interrupt Speed
If pir1.2=1 then
If state=0 then
T1CON.0=1 ' Enable Timer
CCP1CON = %00000100 ' Next trigger is Falling edge
pir1.2=0 ' Reset Capture Flag
state =1
else
Speed.lowbyte = CCPR1L
Speed.highbyte = CCPR1H
' Store the captured value in period variable
T1CON.0=0 ' Timer is OFF
CCP1CON=0 ' Capture is OFF
TMR1L=0 ' Reset Timer
TMR1H=0 ' Remember Timer is OFF
pir1.2=0 ' Reset Capture Flag
CCP1CON = %00000101 ' Next trigger is Rising edge
state=0
endif
endif
Resume
HTH,
Darrel
Bookmarks