Which in turn helps you better pick the right MCU part for your project. So, you can have a better understanding of which type fits in which kind of applications. Just to give you an overview of the different available hardware timers in STM32 microcontrollers. So, in this section, I’ll highlight those timer modules and their main features, block diagram, and things like that. STM32 microcontrollers usually have a handful of each type, however, some parts may lack one or more of these hardware timers. STMicroelectronics provides some different versions or variants for the hardware timer modules. And you can capture the information of how many times the button is pressed by simply reading the TCNT register’s value.įor more introductory information about Timers Modules & Timer Preloading Where you can see, the clock signal is now driven from the push button and gets to the timer clock input through the Prescaler. But for now, consider the following diagram. This mode can be advantageous in numerous applications as we’ll discuss hereafter. Maybe from a push button, so the counter gets incremented every rising or falling edge from the button press. Hence, any time interval can be obtained with a timer module.Ī timer module can also operate in a counter mode where the clock source is not known, it’s actually an external signal. So, you no longer have to start counting from zero. Well, for this reason, there exists a possible hardware feature called preload register that forces the timer to count from any arbitrarily chosen value up to the overflow. What if I need to set up this timer to give me an interrupt signal once per 1 second? I don’t want this 0.839Sec time interval in fact. Therefore, if you start this timer to count from 0 until it reaches overflow (at 65535), it will give you an interrupt signal once every 0.839 Second. This means if the Fsys is 80MHz & PSC is 1:1024, the TCNT gets incremented by 1 every 12.8μSec.
But it gets divided by the Prescaler, then it gets fed to the timer.īasically, in timer mode, the TCNT register is incremented by 1 each clock cycle the following frequency (Fsys/PSC).
And as you can see, the Fsys is not the frequency that is incrementing the timer module.
Every clock cycle, the value of the timer is incremented by 1. As a 16-Bit time, it can count from 0 up to 65535. Let’s consider a basic 16-Bit timer like the one shown below. It can also have circuitry for input capture, PWM signal generation, and much more as we’ll see in this tutorial. It can have a Prescaler to divide the input clock frequency by a selectable value. More functionalities are implemented in hardware to support the timer module so it can count up or down. A Timer Module in its most basic form is a digital logic circuit that counts up every clock cycle.