Skip to main content
Nimit Vachhani
Associate III
September 30, 2019
Solved

STM32F030R8T6 Timer 3 Initialization Problem

  • September 30, 2019
  • 2 replies
  • 1352 views

Greetings Everybody,

I am initializing STM32F030R8 Timer 3 with 48MHz clock and pre scaller 480 - 1 -> 479 and counter period 1. Technically this timer 3 interrupt should be generated at 48MHz / 480 -> 100KHz. On every interrupt i am toggling PA4 GPIO which i am viewing in Oscilloscope and it shows the frequency of 25KHz .. Shouldn't i be getting 100KHz output ? I cant figure out where i am going wrong ?

Any help would be of great help.

I am using STMCube and HAL libraries..

Below is snapshot of timer 3 init

0690X000009joQ5QAI.jpg

This topic has been closed for replies.
Best answer by waclawek.jan

The frequency of Update events (to which you probably interrupt - I don't use Cube) is ftimer/(TIMx_PSC+1)/(TIMx_ARR+1), i.e. if you set ARR ("Period") to 1, the frequency is half of the output of prescaler. You can't set ARR to 0 as that stops the timer; if you want higher frequency, lower the prescaler.

Now if you toggle output at every timer period, your output frequency is half of the toggle frequency - a full period of output waveform is two periods of timer, as in one period you set 0 and in second you set 1.

These two things make your output frequency quarter of what you expect.

JW

2 replies

waclawek.jan
waclawek.janBest answer
Super User
September 30, 2019

The frequency of Update events (to which you probably interrupt - I don't use Cube) is ftimer/(TIMx_PSC+1)/(TIMx_ARR+1), i.e. if you set ARR ("Period") to 1, the frequency is half of the output of prescaler. You can't set ARR to 0 as that stops the timer; if you want higher frequency, lower the prescaler.

Now if you toggle output at every timer period, your output frequency is half of the toggle frequency - a full period of output waveform is two periods of timer, as in one period you set 0 and in second you set 1.

These two things make your output frequency quarter of what you expect.

JW

Nimit Vachhani
Associate III
September 30, 2019

@JW - Thanks for your guidance.... It works.