Voltron6000
Posts: 9
Joined: Wed Jan 30, 2013 4:10 am

Crystal calibration?

Wed Jul 10, 2013 5:40 am

I was wondering if there was some way to accurately measure the actual frequency of the 19.2MHz crystal oscillator on the Pi, using just the Pi and an NTP server? In order to use the Pi as a WSPR transmitter (https://github.com/threeme3/WsprryPi) we need to know the frequency to an accuracy of 5-10Hz.

Is there a counter that is directly derived from the 19.2MHz source? Conceptually, one could reset this counter and query NTP time. After N seconds as measured by the RPi, one could querry NTP time to find out how many seconds had really elapsed and then read the value of the counter. As N increases, the accuracy of the measurement increases and hopefully N would not have to be too large to get 5-10Hz accuracy.

Thanks for any pointers!
James

User avatar
joan
Posts: 14936
Joined: Thu Jul 05, 2012 5:09 pm
Location: UK

Re: Crystal calibration?

Wed Jul 10, 2013 6:36 am

Both the PWM and PCM peripherals (in Broadcom speak) can use the 19.2MHz crystal as their clock. I'm sure other peripherals could as well. The clock can be divided down so that the peripheral could generate a fixed number of bits per second. You could count those bits to derive "time".

Don't crystals drift with temperature?

Voltron6000
Posts: 9
Joined: Wed Jan 30, 2013 4:10 am

Re: Crystal calibration?

Wed Jul 10, 2013 7:38 am

joan wrote:Both the PWM and PCM peripherals (in Broadcom speak) can use the 19.2MHz crystal as their clock. I'm sure other peripherals could as well. The clock can be divided down so that the peripheral could generate a fixed number of bits per second. You could count those bits to derive "time".
The problem with the PWM output is that it's already used to generate the WSPR signal to be transmitted.

By PCM, I think you mean I can create an 'audio' signal which is actually a binary signal that toggles at a specific clock frequency. How can I count these bits? Perhaps I can feed the PCM output to an interrupt pin and if the interrupts happen with a low enough frequency, I can assume that all interrupts will be individually counted?
Don't crystals drift with temperature?
This is the reason I'd like to be able to calibrate the crystal repeatedly. Every 5/10/30 minutes, I'd perform a re-calibration to track the drift...

James

PiGraham
Posts: 3939
Joined: Fri Jun 07, 2013 12:37 pm
Location: Waterlooville

Re: Crystal calibration?

Wed Jul 10, 2013 8:51 am

It should be possible to calibrate the crystal from system clock tick by comparing system time with NTP time. Calibrate the frequency by multiplying it by the ratio of NTP time interval to system time interval. I think that's what you have in mind. It should work. You would need a long enough interval that variabilities in reading the system clock and the NTP time are not significant. At a very rough guess once a day would be safe but once a minute would have too much error.

Voltron6000
Posts: 9
Joined: Wed Jan 30, 2013 4:10 am

Re: Crystal calibration?

Thu Jul 11, 2013 2:48 am

PiGraham wrote:It should be possible to calibrate the crystal from system clock tick by comparing system time with NTP time. Calibrate the frequency by multiplying it by the ratio of NTP time interval to system time interval. I think that's what you have in mind. It should work. You would need a long enough interval that variabilities in reading the system clock and the NTP time are not significant. At a very rough guess once a day would be safe but once a minute would have too much error.
Your post started me thinking about ntpd which I have running on my Pi. It ends up that ntpd itself needs to know the frequency error of the system oscillator and this information is available from ntpdc using the 'loopinfo' command:

Code: Select all

ntpdc> loopinfo
offset:               0.007218 s
frequency:            -33.365 ppm
poll adjust:          30
watchdog timer:       3164 s
ntpdc>
I'll try this first and see if it's accurate enough for WSPR.

Thanks,
James

User avatar
joan
Posts: 14936
Joined: Thu Jul 05, 2012 5:09 pm
Location: UK

Re: Crystal calibration?

Thu Jul 11, 2013 7:00 am

Re ntpdc loopinfo.

Well you learn something new every day :)

Trouble is another 5 things you did know drop out to make room for the new thing. :(

gsh
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 1557
Joined: Sat Sep 10, 2011 11:43 am

Re: Crystal calibration?

Thu Jul 11, 2013 8:23 am

Since the PLL is locked to the 19.2MHz oscillator then you can just use the ARM clock to measure the accuracy, if you apply a little maths (i.e. calculate the ratios)...

I assume you don't care about jitter which would be unmeasureable anyway...

Gorodn
--
Gordon Hollingworth PhD
Raspberry Pi - Director of Software Engineering

Return to “General discussion”