Go Down

Topic: measuring time (Read 64615 times) previous topic - next topic


Aug 19, 2016, 09:22 am Last Edit: Aug 19, 2016, 09:23 am by allanhurst
Some arduinos use a ceramic resonator, which could be +/-  3%%

some use crystals, which could be as bad as +/- 100ppm - ie  0.01%

if this isn't good enough, buy a 30ppm crystal  - 0.003%

if you want better than this is it gets more expensive




Call millis(), remember the result on each press, then you can subtract one from the other.
[ I will NOT respond to personal messages, I WILL delete them, use the forum please ]


When I needed accurate time, I use a DS3231 board
that I got from ebay. I set it to do a one second interrupt.
In the interrupt, I take a micros() reading.
When the code is running, I watch for an update from the one
second interrupt, while doing other things that take less than a second.
I take the result of the interrupts time reading from the
uPs clock and calculate the error. I apply it to the current
one second time span.
Even though the uP is running on a resonator, it is relatively
constant over a one second time span.
The drift rate is mostly related to temperature changes.
The change in rate is a little higher for the first 15 minutes
after power up and then slows down a lot.


Hi everybody!

I'm almost new in Arduino and I'm trying to send a sample of an Ultrasonic (HC-SR04) sensor to PC over Bluetooth. The main problem is that time the pulseIn function I am using to work out the distance depends on the distance. I mean, the more distance, the more time it takes.

Any idea of how I can set the sampling time? I don't mind if it's not too quick because I will interpolate the signal in matlab.

I have tried using millis() but it doesn't work.



I have tried using millis() but it doesn't work
I can absolutely assure you that the millis function does work.

If the delay caused by increased range is a problem, you have at least two solutions:
A) reduce the range
B) increase the speed of sound - try an atmosphere of helium.
"Pete, it's a fool (who) looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.
I speak for myself, not Arduino.

Go Up