Skip to main content
CTR.1
Associate
Apr 3, 2020 2:23 PM UTC
Solved

Problem about APB1 Clock Configuration for Timer

Hi Everyone !

I have a problem for calculating timer for 1ms. I attached configuration for clock and timer.

As I understand Timer2 uses APB1 Clock Bus but for timer it will be APB1x2 if APB1 prescaler is not " 1 "

So when I use Prescaler 59999 for 60Mhz APB1 Timer clock difference between my timer interrupts are 2 ms.

When I use Prescaler 29999 for 60Mhz APB1 Timer clock(which I attached) difference between my timer interrupts are 1 ms.

Is there any timer configuration calculation problem ? I have never meet this problem before other STM mcus.

My Firmware is STM32Cube_FW_L4V1.13.0

Thanks in advanced

This topic has been closed for replies.
berendi
berendiBest answer
Principal
Apr 3, 2020 3:27 PM UTC

Check the details in the reference manual instead of trusting a barely documented tool and library that it does what you think it should do.

Timers count from 0 to the value in the ARR register (the timer is disabled when ARR=0).

So a timer will generate an update interrupt at every other prescaled clock cycle when ARR=1, and can't generate update interrupts at every single input clock cycle.

6 replies

berendi
berendiBest answer
Principal
Apr 3, 2020 3:27 PM UTC

Check the details in the reference manual instead of trusting a barely documented tool and library that it does what you think it should do.

Timers count from 0 to the value in the ARR register (the timer is disabled when ARR=0).

So a timer will generate an update interrupt at every other prescaled clock cycle when ARR=1, and can't generate update interrupts at every single input clock cycle.

CTR.1
CTR.1Author
Associate
Apr 3, 2020 8:50 PM UTC

Thank you

TDK
Apr 3, 2020 3:31 PM UTC

You want PSC=0 and ARR=59999.

Timer update frequency is TIMER_CLOCK / (PSC + 1) / (ARR + 1).

"If you feel a post has answered your question, please click ""Accept as Solution""."
CTR.1
CTR.1Author
Associate
Apr 3, 2020 8:50 PM UTC

Thank you.

waclawek.jan
Super User
Apr 3, 2020 5:09 PM UTC

What is

>difference between my timer interrupts

and how exactly do you determine it?

JW

CTR.1
CTR.1Author
Associate
Apr 3, 2020 8:01 PM UTC

I have volatile boolen variable and I used keil logic analyzer. As you can see bottom time between high and low 0693W000000VJb3QAG.png