There are many types of timers in STM32, which are divided into 2 advanced controller timers, 4 ordinary timers, 2 basic timers, 2 watchdog timers, and 1 system tick timer SysTICk according to their functions.
The key to the timer is the calculation of the timing time. For example, when using a timer to control the switch of a relay, it needs to be delayed for a period of time before closing or opening, and the timer timing is indispensable at this time.
General timer timing calculation. Basic implementation of 1 second interrupt:
The input clock of the general timer module is divided to obtain the clock of the counter, which is represented by CK_CNT. The coefficient of the pre-divider is: TIMx_PSC. When TIMx_PSC=0, it means no division, when =1, it means 2 division. And so on.
The formula is: CK_CNT=fclk_PSC/(PSC[15:0]+1), where the maximum value of PSC is 65535.
The second step is to set the count value of the TIM5 counter. The TIM5 counter uses CK_CNT as the clock to count. When the count reaches the set value, an interrupt is generated.
(1/counting clock after frequency division)*counting value=set time. Take 1 second as an example
(1/(72MHz/7200))*10000=1s
Initialize an important structure of the general timer TIM_TimeBaseInitTypeDef
typedef struct
{
u16 TIM_Period; //Count value automatically loaded,
u16 TIM_Prescaler; //Division value, when it is 0, it means no frequency division, so it needs to be subtracted by 1.
u8 TIM_CLOCkDivision; //Set clock division,
u16 TIM_CounterMode; //Up, down, etc. counting modes
} TIM_TimeBaseInitTypeDef;
Calling a function after initializing the structure
void TIM_TimeBaseInit(TIM_TypeDef* TIMx, TIM_TimeBaseInitTypeDef * TIM_TimeBaseInitStruct) Initializes the time base unit of the TIMx timer.
Secondly, the interrupt pending bit must be cleared, and the function void TIM_ClearITPendingBit(TIM_TypeDef* TIMx, u16 TIM_IT) does this work. TIM_IT: TIM interrupt pending bit to be checked.
Previous article:What is the RTC calibration function of the STM32F microcontroller?
Next article:Application of USB interface in smartphone base speaker based on Cortex-M0 processor
Recommended ReadingLatest update time:2024-11-15 11:12
- Popular Resources
- Popular amplifiers
- Learn ARM development(16)
- Learn ARM development(17)
- Learn ARM development(18)
- Embedded system debugging simulation tool
- A small question that has been bothering me recently has finally been solved~~
- Learn ARM development (1)
- Learn ARM development (2)
- Learn ARM development (4)
- Learn ARM development (6)
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- LED chemical incompatibility test to see which chemicals LEDs can be used with
- Application of ARM9 hardware coprocessor on WinCE embedded motherboard
- What are the key points for selecting rotor flowmeter?
- LM317 high power charger circuit
- A brief analysis of Embest's application and development of embedded medical devices
- Single-phase RC protection circuit
- stm32 PVD programmable voltage monitor
- Introduction and measurement of edge trigger and level trigger of 51 single chip microcomputer
- Improved design of Linux system software shell protection technology
- What to do if the ABB robot protection device stops
- Apple faces class action lawsuit from 40 million UK iCloud users, faces $27.6 billion in claims
- Apple faces class action lawsuit from 40 million UK iCloud users, faces $27.6 billion in claims
- The US asked TSMC to restrict the export of high-end chips, and the Ministry of Commerce responded
- The US asked TSMC to restrict the export of high-end chips, and the Ministry of Commerce responded
- ASML predicts that its revenue in 2030 will exceed 457 billion yuan! Gross profit margin 56-60%
- Detailed explanation of intelligent car body perception system
- How to solve the problem that the servo drive is not enabled
- Why does the servo drive not power on?
- What point should I connect to when the servo is turned on?
- How to turn on the internal enable of Panasonic servo drive?
- Discuss the voltage problem at a certain point in an op amp circuit
- MSP430F5438A clock settings
- Ideal Auto says it will open source its self-developed AEB system code
- Three-phase PFC, current loop does not converge using VIENNA topology
- 【GD32450I-EVAL】USB touch screen driver
- CCS3.3
- Request the schematic diagram of this system board
- How many Gs is the AT in the PULLin VALUE of the reed switch?
- July 9 live broadcast review: Enjoy the purity - AMS active noise reduction and proximity sensing bring a new level of headphone design (including video, ppt)
- ADI chips have increased by NNN times?