RTC wakeup depends on calibration value ???

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.
Post Reply
Hanilein
Posts: 26
Joined: Thu Jul 12, 2018 11:40 am
Location: Christchurch, New Zealand

RTC wakeup depends on calibration value ???

Post by Hanilein » Tue Jan 22, 2019 10:26 am

There is a problem with the RTC wakeup, the timing depends on the calibration value and is therefore incorrect... Sorry for the long text, but I am kinda stuck...

I am working on a code to self-adjust the RTC on the PyBoard.

The code uses a PPS signal from a GPS to calculate the calibration value of the RTC, which is set with rtc.calibration(value).
This value has a range from -511 to +512, and effectively adds or subtracts this number of pulses over a period of 32 seconds from the quarz oscillation, running at 32768Hz.

That works really well, and my development Pyboard currently uses a correction value of -293, and keeps it's time pretty stable (~1-5 seconds/day deviation).

I want the RTC to generate an interrupt precisely every second using rtc.wakeup(milliSeconds, IRQhandler) with a millisecond value of 1000.
The IRQhandler fetches the current time from the RTC and prints it (using the scheduler), and that's how it looks:

22.01.2019 22:51:57:99 0

The 99 represent 1/100 seconds, and the 0 is the subsecond value. Regardless the correction value, this timestamp should never change!
Now look at these values:

22.01.2019 22:52:57:98 4 This is the timestamp after 1 minute - a deviation of 1/64 second.
22.01.2019 23:00:57:85 38 And this is the timestamp after 9 minutes - we are 148 milliseconds off, compared to the start time.

Remember, the RTC is adjusted.

I then tested with another pyboard and also played with the correction value for the RTC - there is no deviation over hours, when the correction value is 0!

In other words, I never get a precise, repeated interrupt with the RTC. :o

Sidenote:
For another part of the project the RTC should wake up the µC at a given date/time, but this functionality is not implemented. According to the datasheet this is possible, but the Python implementation currently does not support this :(.
Ivo Gorny

chuckbook
Posts: 93
Joined: Fri Oct 30, 2015 11:55 pm

Re: RTC wakeup depends on calibration value ???

Post by chuckbook » Tue Jan 22, 2019 12:33 pm

If rtc.wakeup(ms, wup) is used, STM32 will always use non-calibrated RTC timer for intervals < 16s.
For intervals >= 16s the calibrated 1s timer will be used.
To force rtc.wakeup using 1s clock, use:

Code: Select all

rtc.wakeup(4, 0, wup) # 1s interval
rtc.wakeup(4, 1, wup) # 2s interval

Hanilein
Posts: 26
Joined: Thu Jul 12, 2018 11:40 am
Location: Christchurch, New Zealand

Re: RTC wakeup depends on calibration value ???

Post by Hanilein » Wed Jan 23, 2019 9:34 am

Excellent, thank you!

Works like a charm.
Ivo Gorny

Post Reply