Author
Topic: Pulse Width (Read 1754 times)

I have been facing a problem of measuring pulse width using arduino nano board. The pulses are very short 5 to 15 microseconds duration and they are coming at a frequency of 1 Hz. My code is listed below but all I am getting is that I can read the pulses after every 1 microsecond or more, means if I apply 2 microsecond width it can measure it and then if it is 2.2 or 2.3 it will still display 2 or even if it is 2.5 and so on until it reaches near to 3 microsecond then it would display either 2.5 or 3. So my results are not accurate and I need help with my code, I have just joined this forum after watching that someone previously answered this but the code was different so I hope that I would get some help from here. I would be grateful to all of you. here is my code

If you just wait for high, you could miss the start of a pulse, because the pulse may already be happening when you start waiting for it. Try making sure the line is low first, then start waiting for it to go high.

Also be aware that floating point arithmetic is going to slow things down, see if you can do whatever you're doing with integer arithmetic.