Skip to main content
migmel
Associate III
March 6, 2022
Solved

Set timer update event at a desired T seconds frequency

Hello, I want to generate an interrupt using the timer update event every T seconds at a given MCU frequency F using LL library and a basic timer with STM32L071CB.

Lets say for example that:

T = 5 s

System clock frequency F = 32 MHz

Timer TIM6

It looks like a simple task but it's difficult for me to understand the math behind these operations.

This topic has been closed for replies.
MM..1
MM..1Best answer
Super User
March 6, 2022

Basic timer features include:

  • 16-bit auto-reload up-counter ARR
  • 16-bit programmable Prescaler used to divide (also “on the fly�?) the counter clock frequency by any factor between 1 and 65536

Time to int = TIMperipheral CLK (APB) / (PRESC + 1) / (ARR + 1)

calculate for ARR=999 for example 1 sec and changing ARR 1999 is 2 sec ...For your T and F PRSC=31999 ARR=4999

Or more info

The update event period is calculated as follows:

Update_event = TIM_CLK/((PSC + 1)*(ARR + 1)*(RCR + 1))

Where: TIM_CLK = timer clock input

 PSC = 16-bit prescaler register

 ARR = 16/32-bit Autoreload register

 RCR = 16-bit repetition counter (where present)

 URL:

http://www.st.com/web/en/resource/technical/document/application_note/DM00042534.pdf

4 replies

MM..1
MM..1Best answer
Super User
March 6, 2022

Basic timer features include:

  • 16-bit auto-reload up-counter ARR
  • 16-bit programmable Prescaler used to divide (also “on the fly�?) the counter clock frequency by any factor between 1 and 65536

Time to int = TIMperipheral CLK (APB) / (PRESC + 1) / (ARR + 1)

calculate for ARR=999 for example 1 sec and changing ARR 1999 is 2 sec ...For your T and F PRSC=31999 ARR=4999

Or more info

The update event period is calculated as follows:

Update_event = TIM_CLK/((PSC + 1)*(ARR + 1)*(RCR + 1))

Where: TIM_CLK = timer clock input

 PSC = 16-bit prescaler register

 ARR = 16/32-bit Autoreload register

 RCR = 16-bit repetition counter (where present)

 URL:

http://www.st.com/web/en/resource/technical/document/application_note/DM00042534.pdf

migmel
migmelAuthor
Associate III
March 6, 2022

Thank you MM

Regards

migmel
migmelAuthor
Associate III
March 7, 2022

Thank you Nikita91