So you'll recall that there was some trouble with an earlier design of the clock with the (absence of) loading capacitors causing accuracy problems. In investigating and checking the new design, one of the things I needed was a way to actually check a given board's frequency. This is a challenge, because the frequency is quite slow, but must be very accurate.
The first challenge is actually getting at the frequency to test. Attempting to probe the crystal while it's in circuit is a bad idea, as the loading will alter the conditions enough to mess with the crystal. So you need to proxy the crystal frequency on one of the output pins of the controller itself, or use the controller to actually perform the calibration.
My first pass at this was a board that simply provided the GPS PPS as an input to the controller. It would run firmware that would watch the PPS input and count the oscillations of the system clock using one of the timers. The problem is that the clock is also the CPU execution clock. Unless you prescale the timer, you can't read it quickly enough to catch it before it changes its value. And if you do prescale it, then the test just takes far longer to complete. I did get it working, but each run would take 45 minutes to complete. There had to be a better way.
That better way was centered around separating the execution clock from the crystal clock being measured. Unfortunately, there's no way to do that on the ATTiny45, so the only option was to move the measurement to an external processor. To do that, we still need to load firmware into the ATTiny, but that firmware's job would be to simply mirror the system clock on an I/O pin. To do that, you simply configure one of the timers to toggle one of the pins when it overflows, and set it to "count to zero." The net result is a 16.384 kHz (nominal) square wave. That can be fed into the ICP1 pin of an ATMega328p. The magic there is that you can configure the timer so that rising edges on that pin will "capture" the timer value at that moment. That means that the timer can run at the system clock rate for maximum resolution. And by clocking it at 20 MHz (the maximum for an ATMega328p), one second's worth of capture data would have a resolution of 50 ppb.
Initial tests with that system on a breadboard with just an ordinary 20 MHz crystal have shown it to be a workable solution. In fact, checking the crystal against GPS shows that it's only ~2.5 ppm off (though it is quite sensitive to changes in temperature). The next step will be to build the circuit for real with a TCXO. Hopefully the TCXO (the one I've selected is rated for 50 ppb) will line right up with GPS and be a good standard.
However, the other particularly good news is that with the correct loading capacitance, the prototypes of the new(er) controllers show that they're landing pretty close to 0 drift (modulo their 10 ppm tolerance).
Discussions
Become a Hackaday.io Member
Create an account to leave a comment. Already have an account? Log In.