cancel
Showing results for 
Search instead for 
Did you mean: 

STM32L053-Nucleo (Timer Pre-scaler)

Nathapol Tanomsup
Associate II
Posted on January 25, 2017 at 04:26

I am newbie of STM32 board. After yesterday I had tried a little experiment about timer. I use timer4 and use PLL clock as input source clock and finally in cubeMX, it said that APB is 32 MHz. My desire is I want to toggle pin every 500 ms and in configuration page I put pre-scaler to 32000 and count period is 499 so it should be interrupted every 500 ms after I programmed that on my STM32L053., timer gave an interrupt every 250 ms. I try to divide my pre-scaler by 2 and I got 500 ms. I had read a data sheet but still got nothing. I cannot figure out why the outcome turn in to this way. So is anyone know? what happened. Appreciated guys.

#stm32l0-nucleo #stm32-timer
1 ACCEPTED SOLUTION

Accepted Solutions
Khouloud GARSI
Lead II
Posted on January 26, 2017 at 12:09

Hello

Tanomsup.Nathapol

,

There is no TIM4 in STM32L053-Nucleo. I assume you're using TIM6.

The TIMxCLK frequency is the SystemCoreClock (Hz).

SystemCoreClock is set to 32MHz for STM32L0xx Devices.

Prescaler = 32000 = (TIMxCLK / TIMx counter clock) - 1

-> TIMx counter clock = TIMxCLK/32001 = 1 kHz (I advise you to use a prescaler value=31999)

The TIMx ARR register value is equal to 499 .

-> Update rate = TIMx counter clock / (Period + 1) = 2 Hz,

So the TIMx generates an interrupt each 500 ms.

When the counter value reaches the auto-reload register value, the TIM update

interrupt is generated and, in the handler routine, The LED is toggled with

the following frequency: 1Hz (LED_ON : 500ms + LED_Off : 500 ms)

I'd recommend you to refer to the example titled 'TIM_TimeBase' under the

http://www.st.com/content/st_com/en/products/embedded-software/mcus-embedded-software/stm32-embedded-software/stm32cube-embedded-software/stm32cubel0.html

package:

STM32Cube_FW_L0_V1.8.0\Projects\STM32L053R8-Nucleo\Examples\TIM\TIM_TimeBase

Khouloud.

View solution in original post

3 REPLIES 3
Oliver Beirne
Senior
Posted on January 26, 2017 at 09:36

Hello

Tanomsup.Nathapol

I have moved your question to the

https://community.st.com/community/stm32-community/stm32-forum?sr=search&ampsearchId=8cf640a5-fa5c-4ed3-8c7f-4fc8e82d1cd5&ampsearchIndex=0

where someone should be able to assist you.

Thanks

Oli

Khouloud GARSI
Lead II
Posted on January 26, 2017 at 12:09

Hello

Tanomsup.Nathapol

,

There is no TIM4 in STM32L053-Nucleo. I assume you're using TIM6.

The TIMxCLK frequency is the SystemCoreClock (Hz).

SystemCoreClock is set to 32MHz for STM32L0xx Devices.

Prescaler = 32000 = (TIMxCLK / TIMx counter clock) - 1

-> TIMx counter clock = TIMxCLK/32001 = 1 kHz (I advise you to use a prescaler value=31999)

The TIMx ARR register value is equal to 499 .

-> Update rate = TIMx counter clock / (Period + 1) = 2 Hz,

So the TIMx generates an interrupt each 500 ms.

When the counter value reaches the auto-reload register value, the TIM update

interrupt is generated and, in the handler routine, The LED is toggled with

the following frequency: 1Hz (LED_ON : 500ms + LED_Off : 500 ms)

I'd recommend you to refer to the example titled 'TIM_TimeBase' under the

http://www.st.com/content/st_com/en/products/embedded-software/mcus-embedded-software/stm32-embedded-software/stm32cube-embedded-software/stm32cubel0.html

package:

STM32Cube_FW_L0_V1.8.0\Projects\STM32L053R8-Nucleo\Examples\TIM\TIM_TimeBase

Khouloud.

Posted on January 27, 2017 at 04:33

Thanks, 

Khouloud. It works like a charm.