Page 2 of 2

Re: measuring crystal ppm with GPS

Posted: Sat Mar 21, 2015 2:19 am
by blmorris
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

Re: measuring crystal ppm with GPS

Posted: Sat Mar 21, 2015 12:00 pm
by manitou
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.

Re: measuring crystal ppm with GPS

Posted: Sat Mar 21, 2015 2:18 pm
by blmorris
@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

Re: measuring crystal ppm with GPS

Posted: Sat Mar 21, 2015 3:11 pm
by manitou
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.

Re: measuring crystal ppm with GPS

Posted: Mon Mar 23, 2015 12:50 am
by Damien
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.