I created a simple sketch: signal sampling (DAQ) with 1 kHz SR on one AI channel. I'm using the FlexiTimer2 lib for accurate timing, but when I tested this sketch I noticed that incoming data (i.e. timer cycle) drifts 400 ms/min.. (cca 6.6 ms/s delay)
I have an Arduino Mega2560 clone (Chinese) board. Is it possible that the clock on this board is so inaccurate or the problem comes from the flexitimer function?
I think 400 ms/min error is a bit much..
There may be something of a misunderstanding here.
Despite the reference in the Mega description to a "16 MHz crystal oscillator", reference to the schematic indicates it - "Y1" - actually has a ceramic resonator, a MuRata CSTCE16M0V53 with a ±0.5% Initial Tolerance specification.
It is not a timebase.
Actually, the ATMEGA16U2 USB interface has a real 16 MHz crystal. It has often been asked why this was not simply "chained" to the MCU to provide accuracy.
So the sampling rate (timer) accuracy depends on this cheap ceramic resonator..
Though, in my case this clock source is out of spec, since the error is greater than 0.5%..
George_Cs:
So the sampling rate (timer) accuracy depends on this cheap ceramic resonator..
Though, in my case this clock source is out of spec, since the error is greater than 0.5%..
How are you determining the error? Are you using a calibrated timer/counter? If so when was it last calibrated? If not, what are you using as your time/frequency reference?
I'm using a very accurate NI USB-6221 device as signal source. It has a 10 Mhz base clock with 50 ppm (factory calibrated). Moreover I tried with a USB-6211 device too, but result (drift) is the same.
Maybe this chinese Arduino clone contains a more cheaper resonator than the genuine Arduino?? Unfortunately I can't see any lettering on this microscopic resonator chip..
The signal source sounds adequate so the drift experienced is probably real. I have a genuine Mega2560 and a Chinese Mega2560 and neither has a clock error anything like you are experiencing. Some while ago I checked both against a GPS 1 second tick by counting clock pulses between transitions of INT0 using timer1, Both were within about 110 parts per million (about 6.6ms per minute). Of course my sample of 2 devices is far too small to make any generalizations.
One thing I noticed was that the error I experienced was very temperature dependent. Originally I was going to use the Mega2560 to measure frequency but the poor temperature stability caused me to change tack. I now use a 10MHz OCXO as the clock to an ATMEGA328P and calibrate that about once a month.
Just for comparison, both of my official Uno R3 boards as well as a 16MHz resonator with 0.5% tolerance that I purchased and connected to an Atmega328p are all roughly 1000ppm slow. They vary with indoor temperature swings by 100ppm or more.
Paul__B:
reference to the schematic indicates it - "Y1" - actually has a ceramic resonator
just one of the reasons i avoid using the real arduino board. some clones use quartz but also on my shun list due to the uncertainty. specially odd considering quartz crystals are significantly cheaper than ceramic on the world market. breakout boards with a few components suffice at about 1/5th the cost.
I replaced a resonator with a crystal (and capacitors) and measured about 15ppm accuracy at room temperature. And if I'm reading the datasheet correctly it promises stability of ±10ppm over a -10 to 60°C temperature range. Does that sound right? I never tested that.
You can hack your board and add a crystal and caps, it's not that hard. But it would be kind of nice if those boards came that way in the first place.
Just one more question about this ceramic resonator.. is it possible that tolerance (0.5%) and temp. stability (0.3%) are added together so the full error (in the worst-case scenario) is 0.8% in room temperature ?
I created a simple sketch: signal sampling (DAQ) with 1 kHz SR on one AI channel. I'm using the FlexiTimer2 lib for accurate timing, but when I tested this sketch I noticed that incoming data (i.e. timer cycle) drifts 400 ms/min.. (cca 6.6 ms/s delay)
I have an Arduino Mega2560 clone (Chinese) board. Is it possible that the clock on this board is so inaccurate or the problem comes from the flexitimer function?
I think 400 ms/min error is a bit much..
George Cs. -
The Arduino boards use a ceramic resonator for a clock source. These are not very temperature stable.
Your choices are:
Remove the stock ceramic resonator and replace it with a crystal
George_Cs:
So the sampling rate (timer) accuracy depends on this cheap ceramic resonator..
Though, in my case this clock source is out of spec, since the error is greater than 0.5%..
It seems as though the Arduino designers didn't think anyone would want to do anything more complex that blink an LED...
George_Cs:
Just one more question about this ceramic resonator.. is it possible that tolerance (0.5%) and temp. stability (0.3%) are added together so the full error (in the worst-case scenario) is 0.8% in room temperature ?
Maybe. Are you operating at a temperature extreme? Another possibility is that your unidentified resonator has an initial tolerance greater than 0.5%.
It's a moot point anyway.
Could it be time for a better iron and one of those headband jewelry visor magnifiers?