Ok. I've hit a wall - & I can't get passed it - I need a leg up!
Te recap, I'm using a PIC to measure frequency (80Hz thru 1.4Khz) by counting the number of clock pulses between successive comparator interrupts. It works well.
I now need to measure phase shift .....but how to actually use the PIC hardware options available, to detect the amount of clock pulse between the non phase shifted signal & phase shifted signal's leading edges?
Here's a schematic of my test circuit...

I detect frequency as follows...
DT's Comp1 interrupt - start a timer
DT's Comp1 interrupts again - stop a timer.
so want to add in phase shift detect by bringing in another timer and measuring the clock counts until the second (lagging) signal's leading edge arrives, therefore the enlarged picture....
Comp1 interrupt - start a timer
Comp1 interrupts again - stop a timer.
start another timer
second (phase shifted) signal's leading edge arrives - stop the other timer.
here's the bit I'm using for frequency detection (for clarity I've ommited the config/registers as this bit works)...
Code:
INCLUDE "DT_INTS-14.bas" ' Base Interrupt System PO90OOO9
INCLUDE "ReEnterPBP.bas" ' Include if using PBP interrupts
ASM
INT_LIST macro ; IntSource, Label, Type, ResetFlag?
INT_Handler CMP2_INT, _Comp2_Int, PBP, yes
endm
INT_CREATE ; Creates the interrupt processor
ENDASM
@ INT_ENABLE CMP1_INT ; enable Comparator 1 interrupts
@ INT_ENABLE CMP2_INT ; enable Comparator 1 interrupts
Comp1Time = 0 'clear down Comp1Time, prior to starting.
comp2Time = 0 'clear down Comp2Time, prior to starting
'Main body of Code*********************************************************************************************
Main:
HSEROUT ["comp2=", dec comp2Time,9,"comp1=", dec Comp1Time, 13, 10]
goto Main
end
'Comparator1 Interrupt Handler+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Comp2_Int:
if T1CON.0= 0 then 'if timer1 is not running then...
TMR1H = 0 'Set the high part of the timer value to 0
TMR1L = 0 'Set the low part of the timer value to 0
T1CON.0= 1 'start timer
else
T1CON.0= 0 'stop timer1
Comp2Time.Lowbyte = TMR1L 'puts the timer's low byte in Comp1Time's lower 8 bits
Comp2Time.Highbyte = TMR1H 'puts the timer's high byte in Comp1Time's upper 8 bits
Comp2Time = Comp2Time
endif
@ INT_RETURN
but when I add in a little bit extra (bolded below in red), the HSEROUT chokes....
Code:
@ INT_ENABLE CMP1_INT ; enable Comparator 1 interrupts
@ INT_ENABLE CMP2_INT ; enable Comparator 1 interrupts
Comp1Time = 0 'clear down Comp1Time, prior to starting.
comp2Time = 0 'clear down Comp2Time, prior to starting
'Main body of Code*********************************************************************************************
Main:
HSEROUT ["comp2=", dec comp2Time,9,"comp1=", dec Comp1Time, 13, 10]
goto Main
end
'Comparator1 Interrupt Handler+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Comp2_Int:
if T1CON.0= 0 then 'if timer1 is not running then...
TMR1H = 0 'Set the high part of the timer value to 0
TMR1L = 0 'Set the low part of the timer value to 0
T1CON.0= 1 'start timer1
else
T1CON.0= 0 'stop timer1
TMR2 = 0 'clear tmr2
T2CON.2 = 1 'start tmr2
Comp2Time.Lowbyte = TMR1L 'puts the timer's low byte in Comp1Time's lower 8 bits
Comp2Time.Highbyte = TMR1H 'puts the timer's high byte in Comp1Time's upper 8 bits
Comp2Time = Comp2Time
endif
@ INT_RETURN
Comp1_Int: ' store the amount of clock pulses elapsed since routine above finished
T2CON.2 = 0
COMP1TIME = TMR2
TMR2= 0
@ INT_RETURN
Bookmarks