Benefits of Universal Timer
Tout= ((arr+1)*(psc+1))/Tclk;
TIM3 clock enable
TIM3 is mounted under APB1, so we enable TIM3 through the clock enable function under the APB1 bus. The function called is:
RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM3, ENABLE); //Clock enable
Initialize timer parameters, set auto-reload value, frequency division factor, and counting mode.
In the library function, the timer initialization parameters are implemented through the initialization function TIM_TimeBaseInit:
voidTIM_TimeBaseInit(TIM_TypeDef*TIMx,TIM_TimeBaseInitTypeDef* TIM_TimeBaseInitStruct);
The first parameter is to determine which timer it is, which is relatively easy to understand. The second parameter is the timer initialization parameter structure pointer, the structure type is TIM_TimeBaseInitTypeDef
TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;
TIM_TimeBaseStructure.TIM_Period = 5000; //Set the automatic reload count period value
TIM_TimeBaseStructure.TIM_Prescaler =7199; //Parameter TIM_Prescaler is used to set the frequency division coefficient
TIM_TimeBaseStructure.TIM_ClockDivision = TIM_CKD_DIV1; //Set the clock division factor
TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up; //Parameter TIM_CounterMode is used to set the counting mode
TIM_TimeBaseInit(TIM3, &TIM_TimeBaseStructure);
Setting TIM3_DIER enables update interrupts.
Because we want to use the update interrupt of TIM3, the corresponding bit of the register can enable the update interrupt. In the library function, the timer interrupt enable is implemented through the TIM_ITConfig function:
void TIM_ITConfig(TIM_TypeDef* TIMx, uint16_t TIM_IT, FunctionalState NewState);
The first parameter is to select the timer number, which is easy to understand. The value is TIM1~TIM17.
The second parameter is very critical. It is used to indicate the type of timer interrupt we enable. There are many types of timer interrupts, including update interrupt TIM_IT_Update, trigger interrupt TIM_IT_Trigger, and input capture interrupt, etc.
The third parameter is very simple, which is whether to disable or enable.
TIM3 interrupt priority setting.
After the timer interrupt is enabled, in order to generate an interrupt, it is necessary to set the NVIC related registers.
Interrupt priority.
Enable TIM3.
It is not enough to just configure the timer. If the timer is not enabled, it will not work. We need to enable the timer after configuration by setting the CEN bit of TIM3_CR1. In the firmware library, the function to enable the timer is implemented by the TIM_Cmd function:
void TIM_Cmd(TIM_TypeDef* TIMx, FunctionalState NewState)
Write an interrupt service function.
Function to read the value of the interrupt status register to determine the interrupt type
ITStatus TIM_GetITStatus(TIM_TypeDef* TIMx, uint16_t)
The function is to determine whether the interrupt type TIM_IT of the timer TIMx has an interrupt if (TIM_GetITStatus(TIM3, TIM_IT_Update) != RESET){}
Function to clear interrupt flag in firmware library
void TIM_ClearITPendingBit(TIM_TypeDef* TIMx, uint16_t TIM_IT)
The function is to clear the interrupt TIM_IT flag of timer TIMx. TIM_ClearITPendingBit(TIM3, TIM_IT_Update);
Previous article:Introduction to the enumeration process of STM32USB
Next article:stm32 system tick timer use
Recommended ReadingLatest update time:2024-11-15 13:55
- 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
- Analysis of the information security mechanism of AUTOSAR, the automotive embedded software framework
- Brief Analysis of Automotive Ethernet Test Content and Test Methods
- How haptic technology can enhance driving safety
- Let’s talk about the “Three Musketeers” of radar in autonomous driving
- Why software-defined vehicles transform cars from tools into living spaces
- How Lucid is overtaking Tesla with smaller motors
- Wi-Fi 8 specification is on the way: 2.4/5/6GHz triple-band operation
- Wi-Fi 8 specification is on the way: 2.4/5/6GHz triple-band operation
- Vietnam's chip packaging and testing business is growing, and supply-side fragmentation is splitting the market
- Vietnam's chip packaging and testing business is growing, and supply-side fragmentation is splitting the market
- Overview of MCU bus, three-bus structure of MCU
- Comparison summary of MSP430 FR2xx series MCU BSL and MSP432 P series MCU BSL
- Most Popular Blogs of 2021: Connect, Power, and Protect
- Recruiting circuit engineers with high salary (Nantong Intelligent Perception Research Institute, Shanghai Institute of Technical Physics, Chinese Academy of Sciences)
- Does anyone have the schematic diagram of jmb366?
- If the clamp meter (multimeter) does not measure but there are still numbers, is it a malfunction?
- EEWORLD University Hall - Digital Oscilloscope Operation Digital Oscilloscope Operation_National Taiwan Normal University_Teacher Zhang Guowei
- [ESP32-Audio-Kit Audio Development Board Review] Part 1: Building esp-idf and esp-adf development environments based on vs code
- [Raspberry Pi Pico Review] Pico power supply part
- Live broadcast has ended | Microchip's latest SAM and PIC32 microcontroller software development platform - MPLAB Harmony V3