

When the counter underflows, an update event can also be set. When the counter reaches 0, the counter underflow occurs and the counter restarts again from the auto-reload value. In this mode the counter starts from the auto-load value and counts down to 0.

When the counter overflows, an update event can also be set. When the counter counts till the auto-reload value, the counter overflows and it is restarted again from 0. In this mode the counter starts from 0 to the auto-reload value that is set by the user. Another thing of importance while working in counter mode is that it allows the user to monitor the frequency of the counter through the number of pulses that occurred at each interval through the counter difference. The counter mode is useful when creating a digital counter that does not require polling input pins or reading a GPIO pin periodically or regularly triggering interrupts. The timer can count up/down on every rising/falling edge of the timer input pin. When configuring the STM32 Blue Pill timer module in counter mode, an external source such as the timer input pin clocks the timer module. This guide focuses on configuring the timer module in counter mode. The timer module can work in different configurations such as timer mode, counter mode, PWM mode, output compare mode, etc. They act as a clock and are used to keep track of time based events.

The Blue Pill STM32F103C8 comes with four timers known as TIM1, TIM2, TIM3, and TIM4. In input edge capture counter mode, timers of stm32 start to count whenever an external event occurs on the input-edge capture GPIO pin. We will program STM32 Blue Pill in STM32CubeIDE using HAL libraries.

To use the timer as a counter, we will configure it in input-edge counter mode. In this user guide, we will discuss how to configure STM32 Blue Pill timer module in counter mode.
