Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.
Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.
You want to use the Compare Capture Module. You set it up to capture the value of a free running timer when either a rising or falling edge is detected. Then you set it up to do the same thing for the opposite edge. The difference in the two timer values is the elapsed time of the pulse. You do need to be concerned with the timer wrapping around between edges but that is a minor problem.
Another feature of newer PIC microcontrollers is the Timer1 Gate feature. Timer1 will increment when its gate is active.
When your input signal is low, you can configure the Timer1 Gate to increment when the incoming signal is high, wait for the signal to go high (allowing the Timer to increment) and then wait until it is low again. The value in the Timer1 registers will be the number of counts while the signal was high.
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.