cancel
Showing results for 
Search instead for 
Did you mean: 

I need to know what are the limits for setting the sub-second RTC resolution?

Steven Keeter
Associate III

I am planning to use a STM32F746xx device with PTPV2 time synchronization methods and am wondering if I can maintain the on-board RTC sync to at least 1 millisecond resolution or smaller. I see there are various setup registers to scale the clocks and I do not full understand all of the details yet. I just want to know if I'm moving in a feasible direction. BTW, does the related HAL drivers support this kind of sub-second setup control and use for alarms, etc...?

4 REPLIES 4

RTC simply divides down the LSE clock in two prescalers - an asynchronous (low-consumption) and synchronous, to nominally one second; and the uses the usual /60 /60 /24 /7 /28-31 /365 dividers to get time and date.

Default LSE crystal is 32.768kHz, default async divider is 128 and default sync divider is 256 (the values programmed to registers are one less, but that's just an implementation detail). The "subsecond" feature of the STM32 RTC is simply the sync divider exposed to the programmer, so it's default resolution is 1/256s (or 3.90625ms)

Now this is just some stupid sequential logic and none of those numbers are carved in stone, so if you for example desire exactly 1ms resolution, you have to go for some exotic LSE crystal which is integer multiple of 1kHz (e.g. 32.000kHz), and use such async prediv value (here: 32) which yields 1kHz sync count. Note, that this will have some consequences as far as consumption goes when running in VBAT mode.

This, and more, is described in the RTC chapter of the RM. Highly recommendable reading.

I don't use Cube/HAL.

JW

Steven Keeter
Associate III

I see in the user's guide that the resolution is quite small and that a scheduled alarm can be configured as quick as every 122 micro-seconds, and that the RTC can be fine tuned for better sync with master PTP server. I'm trying to figure out if you can sync the RTC using the STM32's 1588 PTP functionality. I see where you could add an external PHY chip that has a 1 PPS output clock to send into the REFIN for the RTC; however, I would think that the 1588 PTP functionality would allow a similar syncing method through firmware controls. Any ideas or know of sample IAR projects for this?

Is this a low power application, or could you just clock the HSE with a far more precise source?

I'd use internal TIM, and do time transfer from the RTC at top-of-second, and work with registers yielding nano-second resolutions.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Steven Keeter
Associate III

This is not a low power application. Why can't you just route the TIM2 output from the 1588 PTP function into the REFIN input of the RTC and allow the system to adjust the RTC clock to match? If I use LSI oscillator setting and set PREDIV_S to 0x7FFF and PREDEV_A to 0 then the RTC_SS regiter should have a precision to 30uS and an absolute sync to the PTP master to appr0x < 10nS. BTW, do you know of any HAL drivers or sample code to setup and use the PTP function of the on-board IEEE 1588 hardware on the ST32F7 device I'm using? Thanks Clive