Many ways to do it. A simple, non elegant, way:Obviously this will "hang" the PIC while measuring and there may be some (in the us region) error due to polling the inputs but it should work. Another, more elegant way, would be to use the timer in conjuction with one of the CCP modules set up in capture mode. As it happens they have a mode where it captures the value of the timer, in the backgroud, on every rising edge.Code:TimerTicks VAR WORD TMR1H = 0 TMR1L = 0 'Reset TMR1 While PortB.0 = 0 : WEND 'Wait for rising edge T1CON.0 = 1 'Start timer WHILE PortB.0 = 1 : WEND 'Wait for falling edge WHILE PortB.0 = 0 : WEND 'Wait for second rising edge T1CON.0 = 0 'Stop timer TimerTicks.HighByte = TMR1H TimerTicks.LowByte = TMR1L HSEROUT [#TimerTicks, 10,13]
/Henrik.




Bookmarks