Go Down

Topic: microseconds (Read 350 times) previous topic - next topic

Sprak

Is there a way to measure microseconds? I want to find out the interval between certain events (in this case, bytes received by the arduino) and milliseconds is a bit too crude.

jims

There is not a call for measuring microseconds.
You could use delayMicroseconds() and polling to repeatedly wait a while and check to get a rough idea of how long it was.
You could also look at TCNT1 which is a 16 bit register that increments every 4 microseconds in the standard Arduino configuration. It is going to roll over frequently, and you really should block interrupts around reads to it, like this...
Code: [Select]
cli();
myVar = TCNT1;
sei();

... which assumes you know interrupts were off when you started. (true for normal Arduino code).

Go Up