Ryan,
Don't know if you looked at my previous idea or not. It was an initial idea but had some issues (and syntax errors).
Unfortunately you won't be able to use HPWM to generate the 60Hz output signal - it won't go that low in frequency. There are other ways of doing it of course but for now I've been focusing on the measurments. Here's a second attempt based on the same idea as the previous code, this time with a bit more features and it does compile - I haven't tested it though.
/Henrik.Code:Time1 VAR WORD ' Time between leading edge of Pulse1 and leading edge of Pulse2 Time2 VAR WORD ' Time between leading edge of Pulse1 and leading edge of Pulse3 Temp VAR BYTE ' Temporary variable, use at will Trig VAR PortB.0 Pulse1 VAR PortB.1 Pulse2 VAR PortB.2 TMR1IF VAR PIR1.0 Main: GOSUB Measure ' Do whatever with the measurements Goto Main Measure: T1CON.0 = 0 : TMR1IF = 0 ' Stop Timer, Clear Interrupt flag TMR1H = 0 : TMR1L = 0 ' Clear timer Time1 = 0 : Time2 = 0 ' Clear measurments While Trig : WEND ' Wait until the 60Hz Square wave signal is low before "arming" While Not Trig : WEND ' Now wait for the rising edge of the 60Hz signal T1CON.0 = 1 ' Start timer DO '------------------------------------------------------------------------------- ' Do we have a rising edge on Pulse1 input? ' Capture value ONLY if we haven't already done so. IF Pulse1 AND (Time1 = 0) THEN Time1.HighBYTE = TMR1H Time1.LowBYTE = TMR1L ' Make sure TMR1L didn't overflow inbetween reading the high and low byte Temp = TMR1H If Temp <> Time1.HIGHBYTE THEN Time1.HighBYTE = TMR1H Time1.LowBYTE = TMR1L ENDIF ENDIF '------------------------------------------------------------------------------- ' Do we have a rising edge on Pulse2 input? ' Capture value ONLY if we haven't already done so. IF Pulse2 AND (Time2 = 0) THEN Time2.HIGHBYTE = TMR1H Time2.LOWBYTE = TMR1H ' Make sure TMR1L didn't overflow inbetween reading the high and low byte Temp = TMR1H If Temp <> Time2.HIGHBYTE THEN Time2.HighBYTE = TMR1H Time2.LowBYTE = TMR1L ENDIF ENDIF '------------------------------------------------------------------------------- LOOP UNTIL ((Time1 <> 0) AND (Time2 <> 0)) OR TMR1IF RETURN




Bookmarks