This is interesting... - Page 1
Forum section: electronics / general

author: technix
author_rank: Super Contributor
timestamp: September 12, 2016, 03:16:05 pm
content: I got an ATmega32 which have two sets of oscillator inputs, one set for the system clock and the other for a 32768Hz watch crystal when one of the onboard timers is operating in asynchronous mode. And I got an interesting measurement:Code:Ready.tock: 998tock: 1998...tock: 10998tock: 11998tock: 12999tock: 13999...tock: 31999tock: 32999tock: 34000tock: 35000...tock: 53000tock: 54000tock: 55001tock: 56001...tock: 74001tock: 75001tock: 76002tock: 77002...tock: 95002tock: 96002tock: 97003tock: 98003...tock: 116003tock: 117003tock: 118004tock: 119004...tock: 137004tock: 138004tock: 139005tock: 140005...tock: 158005tock: 159005tock: 160006tock: 161006...tock: 179006tock: 180006tock: 181007tock: 182007...tock: 199007tock: 200007tock: 201008tock: 202008...Those "tock" messages are outputed when Timer 2 overflows, which is once per second. The number is milliseconds since initialization of an Arduino-style timer based on Timer 0 which is running at system core clock speed.What is causing those oscillators to drift apart like that, one millisecond every 20 seconds or so? I am using two crystals, one 2-pin 32768Hz watch crystal, and a 16MHz 4-pin crystal oscillator can.

author: PA0PBZ
author_rank: Super Contributor
timestamp: September 12, 2016, 03:29:09 pm
content: Quote from: technix on September 12, 2016, 03:16:05 pmWhy do you think they would be synchronized?

author: technix
author_rank: Super Contributor
timestamp: September 12, 2016, 03:33:50 pm
content: Quote from: PA0PBZ on September 12, 2016, 03:29:09 pmI am not expecting synchronization, but I do want to know if this drift is significant.

author: Kilrah
author_rank: Unknown
timestamp: September 12, 2016, 03:41:13 pm
content: Seems within the tolerances of 2 randomly picked crystals working completely independently...

author: technix
author_rank: Super Contributor
timestamp: September 12, 2016, 03:45:23 pm
content: Quote from: blueskull on September 12, 2016, 03:40:07 pmI used timer overflow interrupts in Fast PWM mode (effectively simple timer mode with PWM instead of comparator output) so there is no timer resetting involved.

author: Chris Mr
author_rank: Regular Contributor
timestamp: September 12, 2016, 04:17:01 pm
content: QuoteLemme see..20 seconds and 0.001 seconds out, is like 20,000:1 or to put it another way, 50ppm ((1/20000) * 1,000,000).Your two crystals might be +/- 100ppm (for example) so what you have noticed is entirely reasonable.A better explanation would be that whilst you have worked outpreciselywhat the times should be using the crystal frequencies, the +/-100ppm variability of the crystals means those calculations are not as the hardware actually is. Crystals are temperature sensitive so you could heat one up and watch the discrepancy get either larger or smaller.If you have a scope, even better is to output two square waves and watch them drift. Say 512Hz so you get plenty of updates.

author: tatus1969
author_rank: Super Contributor
timestamp: September 12, 2016, 04:21:09 pm
content: those watch crystal can be very nasty and temperature dependent. Take a chance and put your finger on it, I bet that you can see it at your output.

author: technix
author_rank: Super Contributor
timestamp: September 12, 2016, 04:25:51 pm
content: Quote from: tatus1969 on September 12, 2016, 04:21:09 pmSo my general design policy of only using DS3231 TCXO for RTC is a good idea?