Go Down

Topic: Help! Counting time between pulses from two sensors (Read 492 times) previous topic - next topic


Hi :-)

I doing a project where i'm measuring two places on a rotating shaft with two IR sensor.
I've made the code for the two sensors, but can't figure out how to do the code, that counts the time between the two pulses.

Anyone can help with that?


Sep 30, 2016, 01:08 pm Last Edit: Sep 30, 2016, 01:10 pm by Bainesbunch
put the output of the Ir sensors onto interrupt pins. The in the ISR for those pins take a millis() count on one pulses and then a second on the next pulse detected the first from the second and you have your time between pulses.

If you wanted to then connect each sensor to its own interrupt pin and then use the two ISR to calculate the time difference. this way you will be sure the the correct pulse triggers the start of the count.

using interrupts this way removes any error caused by testing in a loop

Be sure to specify if you want to trigger the ISR on the falling or rising edge of the pin change.

Cheers Pete.
EmbeddedAT .. From Concept to Prototype to Production
Electronics and firmware design and project mentoring
I do answer personal requests for help when accompanied with a PayPal receipt ;)


To expand on Bainesbunch comment...
His suggestins are perfectly valid.
What sort of timing precision are we talking about?
When posting - use the toolbar and read the stickies if you're not sure!  </code> tags are our friend!
You can lead a plug to an outlet, but you can't make them turn it on.


Electronics and firmware/software design and assistance. No project too small

Go Up