In some applications of STM32, users have the requirement to execute certain programs periodically. The timer can be used to generate a fixed time period to meet such requirements.
STM32 related features:
STM32 advanced timers TIM1, TIM8, general timers TIM2, TIM3, TIM4, TIM5;
the maximum clock of the timer is 72MHz, and with pre-scaling, it provides flexible clock cycles;
each TIM has 4 independent capture/compare channels, DMA/interrupt functions;
the channel works in output comparison timing mode, and one TIM can provide up to 4 different timing cycles.
Principle:
A certain output/capture channel of TIM works in output comparison timing mode.
When the counter counts to the comparison value, an interrupt is generated, and the capture comparison register is refreshed in the interrupt, so that the next interrupt can be generated after the same time interval.
The TIM2 clock is set to 36MHz, the prescaler is set to 2, and the Output Compare Toggle Mode is used.
The TIM2 counter clock can be expressed as: TIM2 counter clock = TIMxCLK / (Prescaler +1) = 12 MHz
Set the TIM2_CCR1 register value to 32768, then the CC1 update frequency is the TIM2 counter clock frequency divided by the CCR1 register value, which is 366.2 Hz. Therefore, TIM2 channel 1 can generate a periodic signal with a frequency of 183.1 Hz.
Similarly, according to the values of registers TIM2_CCR2, TIM2_CCR3 and TIM2_CCR4, TIM2 channel 2 can generate a periodic signal with a frequency of 366.3 Hz; TIM2 channel 3 can generate a periodic signal with a frequency of 732.4 Hz; and TIM2 channel 4 can generate a periodic signal with a frequency of 1464.8 Hz.
Each output can be observed through an oscilloscope.
#include "stm32f10x_lib.h"
TIM_TimeBaseInitTypeDef
TIM_OCInitTypeDef
vu16 CCR1_Val = 32768;
vu16 CCR2_Val = 16384;
vu16 CCR3_Val = 8192;
vu16 CCR4_Val = 4096;
ErrorStatus HSEStartUpStatus;
void RCC_Configuration(void);
void GPIO_Configuration(void);
void NVIC_Configuration(void);
int main(void)
{
#ifdef DEBUG
#endif
}
[page]
void RCC_Configuration(void)
{
}
void GPIO_Configuration(void)
{
}
void NVIC_Configuration(void)
{
#ifdef
#else
#endif
}
#ifdef
void assert_failed(u8* file, u32 line)
{
}
#endif
Interrupt service:
void TIM2_IRQHandler(void)
{
}
Previous article:What are the technical features and differences between ARM, DSP, and FPGA?
Next article:Complete configuration of AD and DA
Recommended ReadingLatest update time:2024-11-25 05:07
- Popular Resources
- Popular amplifiers
- Naxin Micro and Xinxian jointly launched the NS800RT series of real-time control MCUs
- How to learn embedded systems based on ARM platform
- Summary of jffs2_scan_eraseblock issues
- Application of SPCOMM Control in Serial Communication of Delphi7.0
- Using TComm component to realize serial communication in Delphi environment
- Bar chart code for embedded development practices
- Embedded Development Learning (10)
- Embedded Development Learning (8)
- Embedded Development Learning (6)
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- Intel promotes AI with multi-dimensional efforts in technology, application, and ecology
- ChinaJoy Qualcomm Snapdragon Theme Pavilion takes you to experience the new changes in digital entertainment in the 5G era
- Infineon's latest generation IGBT technology platform enables precise control of speed and position
- Two test methods for LED lighting life
- Don't Let Lightning Induced Surges Scare You
- Application of brushless motor controller ML4425/4426
- Easy identification of LED power supply quality
- World's first integrated photovoltaic solar system completed in Israel
- Sliding window mean filter for avr microcontroller AD conversion
- What does call mean in the detailed explanation of ABB robot programming instructions?
- CATL releases October battle report
- Battery industry in October 2024: growth momentum remains unabated!
- Mercedes-Benz will launch the eCitaro equipped with NMC4 batteries to provide high energy density and long life
- Many companies have announced progress on solid-state batteries. When will solid-state batteries go into mass production?
- Xsens Sirius Series Inertial Sensors Enable 3D Inertial Navigation in Harsh Environments
- Infineon's Automotive Landscape: From Hardware to Systems
- STMicroelectronics discloses its 2027-2028 financial model and path to achieve its 2030 goals
- 2024 China Automotive Charging and Battery Swapping Ecosystem Conference held in Taiyuan
- State-owned enterprises team up to invest in solid-state battery giant
- The evolution of electronic and electrical architecture is accelerating
- Last day! Microchip Live Broadcast | How to solve precision timing challenges in ADAS systems
- [Fudan Micro FM33LG0 Series Development Board Review] Basic Introduction
- dspf28335 (or 2812) SPI interface to EEPROM operation read and write data program
- MaxplusII advanced use and improvement.rar
- ADC12 module
- EEWORLD forum members are having a get-together in Xi'an. Friends in Xi'an, please go to this post and sign up.
- DCDC input end inrush current problem
- Non-blocking assignment order problem
- [Raspberry Pi 4B Review] + Real-time status monitoring website server construction
- Smart Home Series Articles | Battle for Control: Who is the control center of the smart home system?