cancel
Showing results for 
Search instead for 
Did you mean: 

Set timer update event at a desired T seconds frequency

migmel
Senior

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.

1 ACCEPTED SOLUTION

Accepted Solutions
MM..1
Chief II

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

View solution in original post

4 REPLIES 4
MM..1
Chief II

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
Senior

Thank you MM

Regards

Thank you Nikita91