Skip to main content
Lucky Dog
Associate II
June 27, 2022
Question

Use RTC counter to realize the function of time keeping, but the error is very big

  • June 27, 2022
  • 2 replies
  • 2521 views

Background: The MCU chip I use is stm32L476RG. Since the MCU usually needs to work in the standby mode and will wake up within 2s, I want to count the time the MCU is in the standby mode each time.

Implementation method: The clock source of RTC is LSI, PREDIV_A[6:0] in RTC_PRER in the register is 15, PREDIV_S[14:0] is 32767, that is to say, the load value in the register RTC_SSR will subtract 1 every about 488.3us. I used systick to implement a delay function to verify the accuracy of RTC for timing, read the value of RTC_SSR before and after the delay, denoted as cnt1 and cnt2 respectively, timing time T=(cnt1- cnt2)*488.3.

Question: The picture below shows the actual situation where I use systick delay and RTC timing. I would like to know why this happens.

0693W00000NsmRAQAZ.pngRTC related configuration:

0693W00000NsmShQAJ.png

This topic has been closed for replies.

2 replies

gbm
Lead III
June 27, 2022

Check the datasheet - LSI frequency and accuracy.

My STM32 stuff on github - compact USB device stack and more: https://github.com/gbm-ii/gbmUSBdevice
Lucky Dog
Lucky DogAuthor
Associate II
June 28, 2022

0693W00000NsqvnQAB.png 

0693W00000NsqwlQAB.pngAs can be seen from the above two figures, the LSI clock frequency is in a certain range, so we cannot know the exact clock frequency??

waclawek.jan
Super User
June 28, 2022

Yes.

JW​

Lucky Dog
Lucky DogAuthor
Associate II
June 28, 2022

Thank you very much