measuring crystal ppm with GPS

The official pyboard running MicroPython.
This is the reference design and main target board for MicroPython.
You can buy one at the store.
Target audience: Users with a pyboard.
blmorris
Posts: 348
Joined: Fri May 02, 2014 3:43 pm
Location: Massachusetts, USA

Re: measuring crystal ppm with GPS

Post by blmorris » Sat Mar 21, 2015 2:19 am

Damien, the GPS device that I used for my tests is the same as the one on the navigation board - the PPS output from the GPS is available on pin XY-3.
I haven't looked at the RTC stuff in a few months. I was trying to calibrate the RTC by using stm.mem32[] to directly manipulate the SFR's but couldn't quite get it to work - probably missing a step or two somewhere. I'm very interested to see how it is done.
-Bryan

manitou
Posts: 73
Joined: Wed Feb 25, 2015 12:15 am

Re: measuring crystal ppm with GPS

Post by manitou » Sat Mar 21, 2015 12:00 pm

To test calibration in firmware, to rtc.c after RTC_Init i added
HAL_RTCEx_SetCoarseCalib(&RTCHandle,RTC_CALIBSIGN_NEGATIVE,60);
(should slow RTC by 120ppm). Sure enough, quick drift check shows my RTC improved from 170ppm to 40ppm.
and to confirm, peek at Calibration register

>>> import stm
>>> print(hex(stm.mem32[stm.RTC + stm.RTC_CALIBR]))
0x9c

The max negative calibration is 2*63 ppm, so our 170ppm is far enough out of spec, that the calibration can't fully eliminate the drift.

blmorris
Posts: 348
Joined: Fri May 02, 2014 3:43 pm
Location: Massachusetts, USA

Re: measuring crystal ppm with GPS

Post by blmorris » Sat Mar 21, 2015 2:18 pm

@manitou - you were able to get the calibration to take affect using the HAL, which is further than I got. I didn't dig into the HAL functions, I was trying to work directly with the configuration registers.

According to the reference manual, we should have more than enough calibration range. Is there a HAL_RTCEx_SetSmoothCalib function?
26.3.11 RTC smooth digital calibration
RTC frequency can be digitally calibrated with a resolution of about 0.954 ppm with a range from -487.1 ppm to +488.5 ppm. The correction of the frequency is performed using series of small adjustments (adding and/or subtracting individual RTCCLK pulses). These adjustments are fairly well distributed so that the RTC is well calibrated even when observed over short durations of time.
-Bryan

manitou
Posts: 73
Joined: Wed Feb 25, 2015 12:15 am

Re: measuring crystal ppm with GPS

Post by manitou » Sat Mar 21, 2015 3:11 pm

there is a
HAL_RTCEx_SetSmoothCalib(RTC_HandleTypeDef* hrtc, uint32_t SmoothCalibPeriod, uint32_t SmoothCalibPlusPulses, uint32_t SmouthCalibMinusPulsesValue)

in firmware micropython/stmhal/hal/src/stm32f4xx_hal_rtc_ex.c
so larger frequency corrections are possible.

(Doing the calibration with stm should be possible, but as you noted, "messy" -- you have to disable write-protection, enable init mode, enable coarse calibration, set the calibration register, exit init mode, and enable write-protection ...whew. I guess that argues for hardware abstraction layer)

If we get the RTC frequency tamed, then there might still be an issue with VBAT and whether the RTC is running with main power off (several threads touched on this). Edit: For me VBAT appears to keep RTC running just fine with no USB power.
Last edited by manitou on Mon Mar 23, 2015 5:40 pm, edited 1 time in total.

Damien
Site Admin
Posts: 647
Joined: Mon Dec 09, 2013 5:02 pm

Re: measuring crystal ppm with GPS

Post by Damien » Mon Mar 23, 2015 12:50 am

Thanks to the GPS unit from @blmorris and the code from @manitou I was able to measure the accuracy at around 137 ppm.

I will try other boards and maybe changing the load capacitor on the crystal.

Post Reply