Skip to main content
CTR.1
Associate
April 3, 2020
Solved

Problem about APB1 Clock Configuration for Timer

  • April 3, 2020
  • 6 replies
  • 2736 views

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.
Best answer by berendi

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
April 3, 2020

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
April 3, 2020

Thank you

TDK
April 3, 2020

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
April 3, 2020

Thank you.

waclawek.jan
Super User
April 3, 2020

What is

>difference between my timer interrupts

and how exactly do you determine it?

JW

CTR.1
CTR.1Author
Associate
April 3, 2020

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