2017-01-24 07:26 PM
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-timerSolved! Go to Solution.
2017-01-26 03:09 AM
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
package: STM32Cube_FW_L0_V1.8.0\Projects\STM32L053R8-Nucleo\Examples\TIM\TIM_TimeBaseKhouloud.
2017-01-26 12:36 AM
Hello
Tanomsup.Nathapol
I have moved your question to the
where someone should be able to assist you.Thanks
Oli
2017-01-26 03:09 AM
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
package: STM32Cube_FW_L0_V1.8.0\Projects\STM32L053R8-Nucleo\Examples\TIM\TIM_TimeBaseKhouloud.
2017-01-26 08:33 PM
Thanks,
Khouloud. It works like a charm.