Hi,
Questions:
1) Pulse 2 and 3 both falls within the envelope of pulse 1 but is pulse 3 always trailing pulse 2 or can it equally well be leading pulse 2?
2) Once you've got your PIC doing these measurements, what else (if anything) do you need it to do?
(I ask because quite often around here you come up with a possible implementation only to then get something like: Oh, that's great! Now I need to add this and that and..... - Which may render the initial idea and work useless.
3) Will there always be two pulses or is it possible that one (or both) will be missing?
Here's a bare bones aproach, it expects the pulses to be "in order" and there's no timeout or anything. Both can be easily accommodated for though.
/Henrik.Code:Time1 VAR WORD Time2 VAR WORD Pulse1 VAR PortB.0 Pulse2 VAR PortB.1 Pulse3 VAR PortB.2 Main: GOSUB Measure ' Do whatever with the measurements Goto Main Measure: T1CON.0 = 0 ' Stop Timer TMR1H = 0 : TMR1L = 0 ' Clear timer While Pulse1 : WEND ' Wait until the 60Hz Square wave signal is low before "arming" While Not Pulse1 : WEND ' Now wait for rising edge T1CON.0 = 1 ' Start timer WHILE Not Pulse2 : WEND ' Wait for leading edge of second pulse Time1.HighWord = TMR1H Time1.LowWord = TMR1L While Not Pulse3 : WEND ' Wait for leading edge of third pulse Time2.HighWord = TMR1H Time2.LowWord = TMR1L RETURN




Bookmarks