filmov
tv
Getting Started with STM32 and Nucleo Part 6: Timers and Timer Interrupts | Digi-Key Electronics
Показать описание
In this tutorial, Shawn shows you how to set up timers in STM32 and use those timers to measure execution time, create non-blocking code, and trigger interrupts.
We first cover the basics of timers in STM32. A timer is a piece of hardware in the microcontroller that continually increments a stored value each clock pulse it receives. Most general purpose timers in microcontrollers are connected to the main CPU clock through one or more prescalers. A prescaler acts to divide the cock. For example, an 80 MHz clock that goes through a prescaler of 80 would cause a timer to increment (tick) at a rate of 1 MHz.
These timers can be used to trigger interrupts to run arbitrary code at given intervals, measure the time between events, or automatically control hardware, as in the case of output compare and pulse width modulation (PWM).
We show you how to configure a timer using STM32CubeIDE by setting a prescaler and a maximum counter value. When a timer reaches this maximum value, it will reset back to 0 (for our chosen general purpose timer).
From there, we create a demo using the STM32 HAL framework to first read timer values to measure execution time of another piece of code. Then, we show how to use timer values to create a non-blocking blink example. Finally, we set up a timer interrupt that triggers once per second. In the interrupt handler, we simply toggle the LED.
Product Links:
Related Videos:
Getting Started with STM32 and Nucleo Part 1: Introduction to STM32CubeIDE and Blinky
Getting Started With STM32 and Nucleo Part 2: How to Use I2C to Read Temperature Sensor TMP102
Getting Started With STM32 & Nucleo Part 4: Working with ADC and DMA
Getting Started With STM32 and Nucleo Part 5: How to Use SPI
Programming the Adafruit Feather STM32F405 Express with STM32CubeIDE
TinyML: Getting Started with STM32 X-CUBE-AI
Getting Started With STM32 and Nucleo Part 3: FreeRTOS - How To Run Multiple Threads w/ CMSIS-RTOS
Related Project Links:
Related Articles:
We first cover the basics of timers in STM32. A timer is a piece of hardware in the microcontroller that continually increments a stored value each clock pulse it receives. Most general purpose timers in microcontrollers are connected to the main CPU clock through one or more prescalers. A prescaler acts to divide the cock. For example, an 80 MHz clock that goes through a prescaler of 80 would cause a timer to increment (tick) at a rate of 1 MHz.
These timers can be used to trigger interrupts to run arbitrary code at given intervals, measure the time between events, or automatically control hardware, as in the case of output compare and pulse width modulation (PWM).
We show you how to configure a timer using STM32CubeIDE by setting a prescaler and a maximum counter value. When a timer reaches this maximum value, it will reset back to 0 (for our chosen general purpose timer).
From there, we create a demo using the STM32 HAL framework to first read timer values to measure execution time of another piece of code. Then, we show how to use timer values to create a non-blocking blink example. Finally, we set up a timer interrupt that triggers once per second. In the interrupt handler, we simply toggle the LED.
Product Links:
Related Videos:
Getting Started with STM32 and Nucleo Part 1: Introduction to STM32CubeIDE and Blinky
Getting Started With STM32 and Nucleo Part 2: How to Use I2C to Read Temperature Sensor TMP102
Getting Started With STM32 & Nucleo Part 4: Working with ADC and DMA
Getting Started With STM32 and Nucleo Part 5: How to Use SPI
Programming the Adafruit Feather STM32F405 Express with STM32CubeIDE
TinyML: Getting Started with STM32 X-CUBE-AI
Getting Started With STM32 and Nucleo Part 3: FreeRTOS - How To Run Multiple Threads w/ CMSIS-RTOS
Related Project Links:
Related Articles:
Комментарии