2024-01-16 11:59 AM - edited 2024-01-16 12:36 PM
My STM32F303RE is running with an 8MHz crystal feeding into HSE:
Using TIM4 I want to generate 700 interrupts per second, but I only get 318.
As can be seen TIM4 runs at 64MHz and the following configuration should trigger about 318 interrupts:
Using the following formula:
(edit note - had a typo in the formula)
interrupts_per_second := clock_frequency / (prescaler + 1) / (counter_period + 1)
64 MHz / 3 / 30476 = 700
The 318 interrupts are way off the expected 700 and I just can't figure why. Any ideas are highly appreciated.
Thx in advance !
Woyzeck
Solved! Go to Solution.
2024-01-19 01:41 PM
My SYSCLK is fed from PLLCLK and both are at the correct frequency, measured using MCO and an oscilloscope an a counter.
Still, the interrupt frequency stays at about 0.45 of what it should be, independent of the counter settings. And the problem is not caused by any kind of race condition or CPU bottleneck, as the 0.45 can be observed even at low frequencies.
2024-01-19 02:49 PM
Now it's getting really weird.
The ISR only gets triggered if I use the PLLCLK as the clock source for SYSCLK. Once I switch to HSE or HSI nothing happens.
2024-01-19 03:29 PM
Let's stay objective here. Interrupts still work with HSI or HSE input. Perhaps they don't work in your program, but this isn't a hardware limitation and must be explained by something in your code.
Perhaps post enough of your code to show the problem.
> One thing that I observed is that the interrupt pulses are somehow irregular
Would suggest the clock is not stable, or there are competing resources for the cpu, or your measurements are wrong. Perhaps the interrupt blocks too long.
2024-01-19 04:18 PM
*** me - it was a bug. Deep in my code I disabled the interrupt and restarted the timer.
Thx for your support, guys - I learned a lot !