Continue to Site

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.

  • 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.

Reading PWM with PIC

Status
Not open for further replies.

MathGeek

New Member
I need to read pulses of varing length with PIC.

Should I just do it with software, by sampling at a certain time interval with a delay routine and sampling routine and store this info to a register?
 
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.
 
Status
Not open for further replies.

Latest threads

Back
Top