That'll work too ... if you have a PIC with the TMR1 gate option.
Code:' PIC12F609 using Timer1 gate input to record pulse widths @ __config _INTRC_OSC_NOCLKOUT & _WDT_OFF & _MCLRE_OFF & _IOSCFS_4MHZ & _CP_OFF CMCON0 = 0 ' comparator disabled CMCON1 = %00000010 ' TMR1 gate source is T1G pin GPIO = 0 ' outputs all low at POR TRISIO = %00010000 ' GPIO.4 = TMR1 gate input PVAL VAR WORD ' holds pulse time TMR1H = 0 TMR1L = 0 T1CON = %11000001 ' TMR1 gate active-high, Fosc/4 clock, TMR1 on Main: ' apply a pulse < 65536uS to TMR1 gate input GPIO.4 to use WHILE !GPIO.4 ' wait for high signal to trigger TMR1 gate pin WEND WHILE GPIO.4 ' wait for signal to return low (stops TMR1) WEND PVAL.LowByte = TMR1L ' get TMR1 counts into PVAL PVAL.HighByte = TMR1H ' from TMR1 TMR1H = 0 ' reset TMR1 TMR1L = 0 GOTO Main END




Bookmarks