I need to measure incoming pulse width, but I don't need to wait until arduino measure it,
In other words , if incoming pulse is 1 seconds , arduino should start measuring the width but other works should done in that 1 seconds, just after measuring finishes it return value.
something like arduino timer, that run parallel with program.
Is inbuilt pulseIn() function use internal timer and run parallel? if not any other method to do so?
unsigned long prevMillis=millis(); // Edit: Put this in setup
unsigned long period=5000;
void loop()
{
if(millis()-prevMillis>=period) // no overflow problem
{
// Do whatever's needed when time elapses.
}
}
frechi91:
I have one problem with using millis or micros , when it overflows, answer for time difference is wrong.
Time differences can always be correct while there is no or one overflow between two time stamps. Depends just on the correctness of your code.
Time differences will always be wrong while there are two or more overflows between two time stamps.
So with "micros()" you can create correct time differences of times up to ca. 70 minutes.
And with "millis()" you can create correct time differences of times up to ca. 49 days.