No, two's complement maths takes all that into account. You don't need to think about the overflow, just blindly subtract.Yes, but if TMR1 overflows during a read, it screws things up, doesn't it? So, you would need to check for that.
An example, count1 = 65036, count2 = 100; count2 - count1 = -64936, which as an unsigned 16-bit integer is 600 (which is the expected result).
I meant missed incoming PWM cycles. If you run the code you provided in a loop, every second PWM cycle is ignored.The calculation came out exact (according to the sim). That was nice to see. There were no lost cycles as happened while I started and stopped TMR1 in the polling method. Now, I have to decide whether to do some of the math at the 683 side and save a few milliseconds of transmission time, or just send the raw data and do it all at the 16F1519 side (both are only at 8 MHz). The subtraction is fairly quick, so I am thinking of doing that with the 683.
I did mention starting TMR1 partway through a cycle, which is not relevant to the code you provided, which takes this into account (by ignoring a cycle).
The code I'm getting at is more like the following, which doesn't miss PWM cycles or TMR counts:
Code:
setup CCP
start TMR1
wait for falling edge
lastCount = CCPR1
loopstart:
wait for rising edge
lowCount = CCPR1 - lastCount
lastCount += lowCount ; this simply sets lastCount to the value read from CCPR1
wait for falling edge
highCount = CCPR1 - lastCount
lastCount += highCount ; this simply sets lastCount to the value read from CCPR1
; we now have the high and low counts... can do something with them, perhaps?
goto loopstart