Posts

Showing posts with the label STM32G4

As simple as the timer TIM1 (not really)

Image
 L ets start with something "simple" yet still widely misundersood:  standard timers in STM32. STM32 microcontrollers have a unified timer periphery called "TIMx". This means that all timers with the same name, such as TIM2, will have the same functionality and registers, regardless of the MCU series. For example, TIM2 in STM32G474 will be functionally equivalent to TIM2 in STM32L052. That's cool, isn't it? The most important timer parameters are the clock divider and the number it counts up to before it resets to zero. The clock divider is called the "Prescaler", and the number it counts up to is called the "Counter Period" or "Auto-reload Register". There is also a "Repetition Counter", but we will ignore it for now. The value you enter in STM32CubeIDE is not quite what it sounds. Let's look at the formula from [1], page 11:   Update_event = TIM_CLK/((Prescaller + 1)*(Autoreload + 1)*(Repetition + 1)) As you can ...