Quote Originally Posted by HankMcSpank View Post
I use a 16f690 @20Mhz

The 16F690's Comparator 1 receives the non lagged signal (set to internal VREF to trip at about 1/2 VCC)
The 16F690's Comparator 2 receives the phase lagged signal (set to internal VREF to trip about 1/2 VCC too)

Identical signals are fed into both comparators (bar the phase lag)

DT's interrupts enabled for CMP1 & CMP2.

On the scope the lag time measures about 20us - below which Comp2 will not decrement.

I don't know enough about what's going on under the hood wrt interrupts (or timer1 zero-ing) to shine any more light on why the comp2 count won't go below 336...when clearly it should as the leading edge of the lagged signal gets close to zero lag. So being a bit wet nehind the ears, is there any other possible method I can use that circumvent this problem?
I'm coming into this sort of late, although I've been more-or-less following this thread. Very interesting stuff!

Anyway, here's an idea that may help--just use a single interrupt. When the first comparator causes the interrupt, get your tmr1 count and zero it, then wait in a tight loop, checking PIR2.6. That should reduce latency to an absolute minimum.

something like
Code:
'Make sure the Comparator 2 interrupt handler is disabled!
'Comparator1 Interrupt Handler++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 
Comp1_Int:
        Comp1Time.Lowbyte = TMR1L  'Store away the timer1 count - this  will be the non lagged signal 'period' count.
        Comp1Time.Highbyte = TMR1H    
        TMR1H = 0                     'Set timer1 value to 0
        TMR1L = 0
        PIR2.6 = 0                     'Clear the Comparator C2 Interrupt Flag bit
Keep_Waiting:
        WHILE  PIR2.6 = 0         'Check to see if the Comparator 2 interrupt flag has flipped
            goto Keep_Wating
        WEND
        Comp2Time.Lowbyte = TMR1L    'Store away the timer1 count again (ie once the lagged signal leading edge arrives - this is the lag count)
        Comp2Time.Highbyte = TMR1H    
@ INT_RETURN
You could also add some sort of check so that it would exit the loop if an unreasonable amount of time has elapsed.

Best Regards,
Paul