I am learning with microcontrollers (mostly PIC16/18 and AVR) for some time, making various experimental projects. One of things that I found surprisingly challenging is maintaining decent clock accuracy.
Most of my projects have internal clocks at least to display uptime, but many of them (those that have display interface) also have an adjustable clock. I even created my own alarm clock for my bed table using a PIC16, but all of them are surprisingly inaccurate, despite using crystal oscillators (using internal RC clock is absolutely terrible.)
I implemented various interactive settings to configure drift to make the clock as accurate as possible, but I am still facing drift of about 10 seconds after two months compared to an NTP calibrated clock (in my phone.)
Basically this is my observation:
- Internal RC clock - drifts by ~10 seconds within 24 hours
- Crystal oscillator 8 MHz - using default interrupt delays calculated by MPLAB MCC drifts by ~10 seconds within few days
- Crystal oscillator 8 MHz - using calibrated delays per each crystal individually drifts by ~10 seconds within a month
- Crystal oscillator 16 MHz - using calibrated delays per each crystal individually drifts by ~10 seconds within two months
What also surprised me is that each crystal, even if the same frequency and from the same manufacturer is giving slightly different frequency, because each needs different calibration to give accurate time. Is that something common?
I am using cheap crystals you can buy at Farnell, such as this one.
I was reading about this and found that there are some "oven-controlled crystal oscillators" that are necessary for accurate time that maintain temperature of the crystal, but I find it hard to believe that these small ovens are installed in electronics like wristwatches.
My calibration mechanism allows me to adjust the "second interval" to the resolution of single clock cycle of the microcontroller, yet it still isn't accurate even with a 16 MHz crystal after several months.
How do wristwatch manufacturers solve this problem?
Are they using oven controlled crystals?
Are they calibrating each single wristwatch individually as each crystal has a slightly different PPM offset / frequency than other one?
Lots of electronics come with classic 24-hour clocks, yet they don't use NTP for syncing. How is this generally done?