Hi Daniel,
I have duplicated your simple test program, and I don't get the
same result as you. I'm using an Arduino Uno with an inbuilt 16
MHz crystal.
My result for 'elapsed' is 10000008
If I change the delay from 10000 to 1, 'elapsed' comes out as 1008.
The reason for this is that the functions delay() and micros() both take a finite processing time. Although the delay is accurate, it takes further time to process and record the value of the microseconds counter and load the number into 'finished'.
You are registering processing times of 16 - 32 microseconds. With an 8MHz clock, that's your 16 microseconds explained away.
In summary, I think your delays are due to processing time.
I can't say why you sometimes get 24 or 32. Try changing the
delay to 1 and see whether that gives similar results.
Does the Arduino software know that you are using an 8MHz clock?
All the timing depends on an interrupt when timer0 overflows,
which does something odd with the fractional number of
milliseconds per timer0 overflow. I don't fully understand what
it does, but it certainly needs to know the number of clock cycles
per microsecond.
There could be error introduced if it's assuming the clock is 16MHz. Further, the delay() function calls micros() frequently while it's timing the delay.
Good luck
Ian B.
--
You received this message because you are subscribed to the Google Groups "accelstepper" group.
To unsubscribe from this group and stop receiving emails from it, send an email to accelstepper...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/accelstepper/1127af4c-29b1-4a9c-8b29-4d2d6cf4fa0en%40googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/accelstepper/43cbad5b-0e9c-57d7-093a-1e0c63adf0aa%40gmail.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/accelstepper/43cbad5b-0e9c-57d7-093a-1e0c63adf0aa%40gmail.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/accelstepper/CAN7FtALQYd39THpnAcue7uw9AnLyfP3%3Dsm64mjdaneNCRi%3D4BQ%40mail.gmail.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/accelstepper/CAHVSG_WP6b9-3MpK%3DCfFR%3D96Ub%3DLof5d4QS1e4DhWVne-7Z9%2BA%40mail.gmail.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/accelstepper/CAN7FtALq53K%3Dhj-mBk1QoAXqN8CFHA7YW5R-bzBV0e108_hU%2BQ%40mail.gmail.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/accelstepper/CAHVSG_UCOEa4hcLT1vJcej4V9ge0FqKX-6y23SoLigOpAANzBA%40mail.gmail.com.