Precise counter preload calculation

Hi,

I'm trying to get a 100ms interrupt with a 32 bits counter on Arduino M0.

"MartinL" help me about 32 bits counter, it's working fine now : Arduino Zero TCC Capture - Arduino Zero - Arduino Forum

He pointed out that the exact frequency of SAMD21 is 1464*32768=47972352Hz (crystals/crystals.txt at master · manitou48/crystals · GitHub)

If I preload with 4797235 (1464*32768/10) I got a drift compared to the real time like ~100ms in 10 minutes.

I found a pretty good value (4798375) after some tries, but is there a smarter method to find the perfect value ?

Something like 10ms drift for 1 hour is perfectly fine for me.

The Arduino Zero's crystal (MS1V-T1K 32.768KHZ) is accurate to ±20ppm or parts per million.

Irrespective over what time period you're measuring, this means you timings can drift up to:

20 / 1000000 * 100 = ±0.002%

So, for example if you're measuring over a 10 minute period then your readings could drift out by as much as:

10minutes * 60seconds * 20 / 1000000 = ±12ms

Unfortunately, this means the Zero's crystal won't meet your 10ms drift for 1 hour requirement.

Well, it will be fine with 100ms in a hour (i don't have choice :grin:)
Thanks again for explanations !