Calculate the duration of a pulse with Arduino nano

Status
Not open for further replies.

adwnis123

Full Member level 4
Joined
Jun 19, 2014
Messages
214
Helped
0
Reputation
0
Reaction score
1
Trophy points
18
Activity points
1,737
Hello,

I use an Arduino nano. In the digital input 2, I send rectangular pulses, which means I have only two levels: 0 Volts and 5 Volts. I want to measure the duration of a pulse from the time the pulse rises to the time it falls. Of course, Arduino nano cannot support nanosecond accuracy, so I would like to measure the ON (5 Volts) level of the pulse in microseconds level accuracy. How do I realize this? Is there any example code I could follow in order to make this feasible?
 

Hi,

from hardware side the AVR usually has a "timer capture" feature.

But I don´t know if one can use this with Arduino software, because it usually needs fast software reaction time.

Klaus
 
You can attach I/O interrupt to the Arduino code and check how fast it can handle the input; it is a standard feature.
 
You can attach I/O interrupt to the Arduino code and check how fast it can handle the input; it is a standard feature.

"and check how fast it can handle the input" -> How do I do that?
 

The easy mode, something like that:

  • Interrupt, detect low edge,
  • Take time (ms)
  • Interrupt, detect high edge
  • Take time (ms)
  • Subtract both measured times
  • Check the smaller pulse width able to be detected
The suited mode:

As Klaus mentioned, use timer capture feature to have more resolution.​
 
That's why I am interested in example code for Timers/Counter in Arduino, in order to see how it works. Is is very new to me Timers/Counter, I have no experience...
 

Status
Not open for further replies.

Similar threads

Cookies are required to use this site. You must accept them to continue using the site. Learn more…