Close

XTAL tunning

A project log for Agora clock

Table clock with e-paper display

Daniel ZilinecDaniel Zilinec 01/09/2022 at 22:576 Comments

I had some complains about the clock is not very accurate so I started to investigate it. A friend of mine borrowed me a HP 5385A frequency counter. It was first time I used one and we weren't sure if it measures correctly.

ATmega328p that is the MCU in Agora clock has no option to tune the RTC XTAL frequency in firmware. It has 32.768 Hz XTAL connected to internal counter that drives the clock. I hooked this counter's output to a GPIO. It had to divide the frequency first so I was looking for precisely 64 Hz frequency on the GPIO where I connected the counter.

Then I started to tune the load capacitors of the 32.768 Hz XTAL to get as closer as possible to 64 Hz at my GPIO.

So I realized that a made a big mistake. I used two XTALs with different load capacitance - the original had 9 pF a the second had one 12.5 pF. That happened in the time when the chip shortage started and I was not aware of the consequences.

Now with the frequency counter I measured the differences and tuned the load capacitors

XTAL capacitanceC13 [pF]C14 [pF]ppm
9 pF - original (mark TBs18)3.34.738
9 pf - tuned (mark TBs18)2.210.23
12.5 - original (mark TAV06)3.34.7-31
12.5 - tuned (mark TAV06)8.26.8-0.2

Next I wanted to know if I can trust the frequency meter. So I made a cardboard with 4 tuned Agora clock boards. I set the exact time on the clock and prepared to let them go for a month

OK, so I had now 4 clocks that a wanted to watch for.

Then I got an idea to turn them into the kitchen clock. My wife was surprisingly not against it.

So I let the clock to go for a month and then I measured the differences.

After a month it was 2678400 passed seconds. So I did a little math and the results are here:

XTALHP counter ppmreal ppm
9 pF0.232
12.5 pf0.20-2

Conclusion

Now I know how important it is to have the RTC frequency of all clocks checked. Because the ATmega328p has no firmware feature to tune the clock I have the only option to tune capacitors on every clock to have good time accuracy.

Discussions

MS-BOSS wrote 01/11/2022 at 15:43 point

You can tune the RTC. Just use some varactors (or diodes, LEDs etc) as part of the capacitive load. Use filtered PWM from the ATMega to get tuning voltage. And then, you can set the frequency using firmware.

  Are you sure? yes | no

Daniel Zilinec wrote 01/14/2022 at 22:32 point

Interesting idea. But I'm not sure if ATmega can generate PWM in low power mode.

Please can you sketch a schematic of this circuit? I can't imagine how could I connect it.

  Are you sure? yes | no

MS-BOSS wrote 01/15/2022 at 20:35 point

Or use a trimmer potentiometer if PWM is not an option. But it will require stabilised voltage in both cases.
https://imgur.com/a/Hbsg3iM

  Are you sure? yes | no

Ken Yap wrote 01/10/2022 at 01:41 point

Elegant build. 👍 An alternative to tuning would be to interface to a DS3231 TCXO, like the ones I wrote about in https://hackaday.io/page/9293-a-quick-note-on-ds3231-rtc-modules I like them and they are quite cheap.

  Are you sure? yes | no

Daniel Zilinec wrote 01/14/2022 at 22:26 point

Thanks.

I always thought that all DSxxxx chips need external crystal so I didn't want to use them. But this one looks pretty nice and has a good price. 

  Are you sure? yes | no

Ken Yap wrote 01/15/2022 at 00:27 point

It has a temperature sensor too though the error limits on that are broad, ±3°C.

  Are you sure? yes | no