2021-01-04 08:02 AM
Hi,
I'm testing various PWM scenarios and found that output frequency does not match with expected.
I'm using formula Period = (PSC+1)*(ARR+1) / TmerClockFreq in seconds Period = 1000 * (PSC+1)*(ARR+1) / TmerClockFreq in milliseconds. The board is Nucleo-144, MCU STM32H745Z.
My calculus :
PSC=0
ARR=1
TimerClockFreq (MHz)=80
TimerClockFreq (s) =0,00008
Period (ms) =25000
Frequency MHz= 40
So I expect close to 40 Mhz on output pin. GPIO setting on pin for speed is Very High.
But my measures shows me, that real frequency is 32,15 Mhz on scope, and 33.33 on 100 Mhz longing device. Documentation explains, that timers are free-running hardware parts, so any interrupts may not have impact, and all depends only on system clock. Attached system clock screen.
Where I'm wrong? Thanks in advance !
Regards,
Steponas
2021-01-04 09:20 AM
You're probably just missing some edges due to the bandwidth limitations of the scope. What is a "100MHz longing device" ? Logging?
Slow things down by an order of magnitude and see if it matches expectations.
Can you show the scope plots?
> TimerClockFreq (s) =0,00008
What is this?
> Period (ms) =25000
This is incorrect, but probably just a typo.
2021-01-04 10:15 AM
Sorry, for some mistakes. English isn't native.
Scope Siglent 2102X 100 Mhz bandwidth, Logging device Kingst LA1010 100 Mhz. I added screens.
I'm using Excel for counting and my logic is (some variables is for formula and self check) as above. Because TimerClockFreq mus be in seconds it is =0,00008 s, and Period I've got is in micoseconds (yes, it's typo error). 25000 us convert to frequency = 1/25000*10^6 = 40 Mhz.
2021-01-04 10:16 AM
2021-01-04 11:05 AM
Well that's definitely not close to 40MHz.
The CSI RC should be considerably more accurate than that.
What could be happening is that HAL is messing up the value in CSITRIM within the RCC->CSICFGR register which is causing the clock to be off by quite a bit. Check the value immediately after reset and ensure HAL doesn't change it. Just a guess.
You should average many readings together to get a more accurate reading in your logic analyzer, but that's not the issue here.
2021-01-04 11:35 AM
It is measured in debug mode, right after command HAL_TIM_PWM_Start(); Well, maybe debug is problem I'll try flashed MCU. Thanks.
2021-01-04 12:12 PM
More probably you're running from the 64 MHz HSI clock.
Get your RCC/PLL settings right first.
2021-01-05 01:45 AM
2021-01-05 06:11 AM
You could use the MCO output and its various configurations to help with your debugging - I often find it handy.
2021-01-06 05:54 AM
I received Blue Pill from Aliexpress today, I’m not sure even the original chip. But it works as expected.