Skip to main content
Visitor II
May 2, 2024
Solved

STM32G474RE General purpose timer (TIM16)

  • May 2, 2024
  • 1 reply
  • 926 views

Greetings,

I am trying to set TIM16 on 1us period but the smallest period I am able to achieve is 4us here is the values of my prescaler and auto-reload register(ARR). I am working with the HAL.

SysClk = 170MHz

PSC = 16 (+1 will be added) 

ARR = 9 (+1 will be added) 

So the counter period is: SysClk/(PSC + 1)(ARR+1)  => 170Mhz/(16+1)(9+1) = 1Mhz

I am expected to be at the callback (HAL_TIM_PeriodElapsedCallback) function at this frequency but instead I am at 250Khz

I am pretty sure this timer should be able to go to 1us period and even smaller than that. What am I doing wrong????

    This topic has been closed for replies.
    Best answer by AScha.3

    Hi,

    going to INT and then to callback in less than 1 us ?  Your cpu running on Warp Speed ?

    If not, but on 170MHz , then think: INT on ARM cpu is 12 clks , then jump to callback, then HAL ...1..2us,

    then jump back, 12 clks to restore registers. So in 4us can come back...good. And maybe 100% cpu load here.

    If you want do anything else in your program, then try with 1ms INT/callback speed.

    Or 10 us just for test. :)

    1 reply

    AScha.3Answer
    Super User
    May 2, 2024

    Hi,

    going to INT and then to callback in less than 1 us ?  Your cpu running on Warp Speed ?

    If not, but on 170MHz , then think: INT on ARM cpu is 12 clks , then jump to callback, then HAL ...1..2us,

    then jump back, 12 clks to restore registers. So in 4us can come back...good. And maybe 100% cpu load here.

    If you want do anything else in your program, then try with 1ms INT/callback speed.

    Or 10 us just for test. :)