Calculating the prescaler and counter period for an external timer on STM32

Thread Starter


Joined Feb 28, 2023
I am trying to get an external timer (TIM5) to toggle an LED at a certain time period. I am designing it to interrupt every 2 micro seconds. I use an oscilloscope to check whether it works as intended, but unfortunately it does not. The clock speed is 45Mhz

And I calculate the period
APBtimer = 45
prescaler = 10-1
ARR = 11-1
triggerfrequency = APBtimer/((prescaler + 1) * (ARR + 1))
period = 1/ triggerfrequency

which gives me a period of 2.4 micro seconds. When I check on the oscilloscope, I get a period of 2.4, which is according to calculations1682589894893.png

But if I change the prescaler to 12-1 and the ARR to 4-1 I get a period of 2.15 instead of the calculated 1.06

Is there something I am doing completely wrong?