Hello,
I solved the problem with another strategy.
I use Timer 1 and wait until Something happens on the input pin. with:
T1CON = 0b0000_0100 ; timer1 is deasabled
while (Sig_in == 0) loop end loop
When Sig_in changes, I clear Timer1 registers
tmr1l = 0 tmr1h = 0 ; reset timer1 counters
Then timer 1 is enabled
T1CON = 0b0000_0101 ; timer1 is enabled
Then do nothing while Input is on (the counter counts)
while (Sig_in == 1) loop end loop
When the input changes again to "0" the program leaves the loop and
stops the timer
T1CON = 0b0000_0100 ; timer1 is disabled
then the program reads the value.
Time_TMR1 = (word(tmr1h))*256 + word (tmr1l); read timer1 value
here the program which can be put in the main or in a procedure
Time_TMR1 is a declared as a word
; start "no edge"
T1CON = 0b0000_0100 ; timer1 is deasabled
while (input_pin == 0) loop end loop
;asm clrwdt ; if pin_in = 0 more than 1 sec, Reset with WDT
; input_pin goes to 1
tmr1l = 0 tmr1h = 0 ; reset timer1 counters
T1CON = 0b0000_0101 ; timer1 is enabled
; start with the rising edge
while (input_pin == 1) loop end loop
;asm clrwdt ; if pin_in = 1 more than 1 sec, Reset with WDT
; input_pin goes again at 0
T1CON = 0b0000_0100 ; timer1 is deasabled
Time_TMR1 = (word(tmr1h))*256 + word (tmr1l); read timer1 value
An other trick to read value inside a program with an oscilloscope:
put in your program
alias Meas_Time_Xis pin_XY
Meas_Time_X = on
delay_10us(value) ; or value/10
Meas_Time_X = off
The number representing the time in x*10µs is the same as the value, or if the value is big enough you use value/10.
Remember if the variable is a word, you need to use byte(value) or byte of value/10 or 100 or more to get a byte value <= at 255.
Note about the shift function, >> or << . I used it to multiply or divide by 2,4,8,16....it works fine for byte but not to make a word with two bytes
Time_TMR1 = (word(tmr1h))<<8 + word (tmr1l); doesn't work at all, use
Time_TMR1 = (word(tmr1h))*256 + word (tmr1l); is ok
Patrick