STM32H5 PLL Nfract issue
Hello,
I am using STM32H503 for precise time measurement hence I need to tune the PLL that output frequency compensates the voltage or temperature drift of the HSE crystal.
My setup is:
- Clock configured as HSE=16, M=, N=337, Nfrac=4096, P=2 which should give HCLK=180MHz
- External, high class reference GPS clock (1PPS) connected to TIM1 as ETR.
- TIM2 CH1 in IC/TRC mode with DMA readout to measure the HCLK.
The procedure is as follows:
- DMA reads TIM2_CH1 CC values into buffer in circular manner (size of buffer is 30 dwords)
- on every HT/TC interrupt I am averaging measurements, taking into account only those within 2% of target frequency
- I am calculating the HCLK error, and correction to be applied to PLL1 Nfrac register.
Update of the Nfrac is done according to to RM492, i.e. to enforce 0->1 transition of the RCC_PLL1CFGR_PLL1FRACEN and later wait for RCC_CR_PLL1RDY to become 1.
This is done in incremental way, one can say algorithm tries to find sweet spot, i.e Nrac values that gives smallest HCL error. Typically, with this setup I am achieving 0.01-0.03ppm of precision using typical HSE crystal with 20 or 30ppm frequency tolerance.
Yet, I frequently see the update of the Nfrac does not change HCLK.
Not always, sometimes, but this behavior fools my algorithm.
As en example, here is a log showing timestamp of USART reception, HCLK from previous 15 measurements and calculated current NFrac.
[10:44:00.007] RX: 179994460,4061
[10:44:15.006] RX: 179995763,4081
[10:44:30.006] RX: 179997716,4101
[10:44:45.006] RX: 179997717,4121
[10:45:00.007] RX: 179997717,4141
[10:45:15.006] RX: 180000972,4141
[10:45:30.006] RX: 180000321,4126
[10:45:45.006] RX: 180000321,4121
[10:46:00.007] RX: 180000321,4111
[10:46:15.006] RX: 180000321,4101
[10:46:30.006] RX: 180000321,4091
[10:46:45.006] RX: 180000322,4081
[10:47:00.007] RX: 180000322,4071
[10:47:15.006] RX: 180000323,4061
[10:47:30.006] RX: 179997881,4066
[10:47:45.006] RX: 179995440,4076
According to RM: "The PLLxRDY flag is set when the PLL lock is detected. The lock detect circuit uses a window comparator that asserts the flag when the output frequency is within a ±2% window of its target value."
For HCLK=180MHz, 2% is 3.6Mhz.
With my PLL setup, change of FracN by 1 should result in HCLK change of 65Hz.
From the observation I can notice that:
Changing NFRAC does not always result in an immediate PLL response, despite the correct FRACEN sequence.
Is it possible that the PLL has an internal averaging mechanism or sigma-delta filter that ignores small changes in FRACN if the new value differs from the previous one only by ±1-2 (because the effect of ~±65 Hz is "below the line of sight")? Or change in FRACN does not change HCLK as the PLL window comparator sees that VCO-out is OK-ish?
If this is a case, how one can effectively use FracN?
Regards,
Arkadiusz
