Hello everyone,
I'm doing a project where I'm using an ultrasonic sensor to make measurements. I see that there was a variation in the accuracy of the data when there was a variation in the temperature.
For example at 0° the sensor measure 80cm and the manual measure is of 80cm with a good repeatability of the measure and a good accuracy close to 0.5cm.
But I make the same test at 25° and here the accuracy was completely different with a variation of 2 cm. 78 ultrasonic measurement against 80 manual measurement. at 30 cm distance the differences become of 1 cm. the repeatability is still good but the accuracy varies.
I make this test with 5 sensors and I always get the same result.
The sensor make the measurement by time domain return routine. make an impulse on a pin and attend the time when the sonic wave return to the other ultrasonic cone. so if the time count by the arduino was corrected the whole system give bad result.
Does anyone know which clock Arduino uses to measure time in the program exegution and if this is affected by temperature variations?
I'm using an arduino nano 328P.
There is only one clock. Either external or internal. A standard 328P based Arduino uses the an external 16 MHz source. I think it depends on the quality of the source what the deviation will be.
For the internal oscillator the following image applies (see datasheet)
Sorry, but I forgot to mention that we used the speed of sound as the speed of sound at 20° or 343 m/s so I would have expected to be wrong at low temperatures not 20 degrees.
But I have a question :
you say that [quote="sterretje, post:3, topic:1356467"]
Arduino uses the an external 16 MHz source
[/quote]
but in the graph i say 8 MHz the clock is of 16 o 8 MHz.
Not in your case. The clock used is determined by MCU fuse settings as well as register settings.
The default for the Arduino Nano 328P is an external resonator or crystal, typically 8 or 16 MHz, usually cheap and therefore not particularly accurate.
Perhaps you could get some estimate of clock variation with temperature. Write a simple sketch that just changes the state of an LED in loop() followed by delay(60000). Then time how long it takes the LED to change state, using a stopwatch. Try it at 0° and 25°.
The data sheet for the processor explains how to do that. You need a processor fuse programmer to change the clock source.
If you have a stock Arduino Nano 328P, then either a crystal or resonator is used, most likely 16 MHz. The clock accuracy depends almost entirely on the selection of that component (if a crystal, including the two associated capacitors) and its temperature dependence.
It is possible with the Nano 328P to measure the crystal or resonator frequency of oscillation to about 1 Hz accuracy using a GPS module as a time base. Let me know if you are interested and I can point you to some resources.