Skip to main content
MNapi
Senior II
January 18, 2019
Question

how do you tune up timers, do you have problems to get the right frequency

  • January 18, 2019
  • 1 reply
  • 589 views

I have STM32F446RE which is 180 Mhz, APB1 is running at 90 Mhz which is the timer clock

for prescaler 7 it is 1.04 Mhz

6 is 1.19 Mhz

8 is 922 Khz

I would assume that I could divide 90 Mhz by 90 to get nice 1 Mhz but it does not seem to be the case. I wonder why

I use CubeMx to setup timers.

This topic has been closed for replies.

1 reply

Tesla DeLorean
Guru
January 18, 2019

The values are programmed as N-1 values, the silicon does a compare, the logic's easy to implement.

For 1MHz output

Prescaler = 0; // DIV 1

Period = 90 - 1; // DIV 90

Tips, Buy me a coffee, or three.. PayPal VenmoUp vote any posts that you find helpful, it shows what's working..
Tesla DeLorean
Guru
January 18, 2019

Interrupting a 1 MHz will be problematic, use the TIM to output to a pin, or toggle it.

If the clocks are still wrong, printf("%d\n", SystemCoreClock); and see what the processor thinks it is running at. For example off 8 MHz HSE , or 16 MHz HSI

Tips, Buy me a coffee, or three.. PayPal VenmoUp vote any posts that you find helpful, it shows what's working..