STM32 external counter ETR calculates frequency, measures 100K frequency, uses timer 2 for 250ms, and timer 3PD2 (TIM3_ETR) counts, and the calculation formula is f=n*t;
void Tim3_Configuration(void)
{
TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;
TIM_TimeBaseStructure.TIM_Prescaler = 0x00;
TIM_TimeBaseStructure.TIM_Period = 0xFFFF;
TIM_TimeBaseStructure.TIM_ClockDivision = TIM_CKD_DIV1;
TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;
TIM_TimeBaseInit(TIM3, &TIM_TimeBaseStructure); // Time base configuration
TIM_ETRClockMode2Config(TIM3, TIM_ExtTRGPSC_OFF, TIM_ExtTRGPolarity_NonInverted, 0);
TIM_ITConfig(TIM3, TIM_IT_Update, ENABLE);
TIM_SetCounter(TIM3, 0);
TIM_Cmd(TIM3, ENABLE);
}
void Tim2_Config(void)
{
TIM_TimeBaseInitTypeDef TIM2_TimeBaseStructure;
NVIC_InitTypeDef NVIC_InitStructure;
TIM_DeInit(TIM2);
TIM2_TimeBaseStructure.TIM_Period =(2500-1);
TIM2_TimeBaseStructure.TIM_Prescaler = (7200-1);
TIM2_TimeBaseStructure.TIM_ClockDivision = TIM_CKD_DIV1;
TIM2_TimeBaseStructure.TIM_CounterMode =TIM_CounterMode_Up;
TIM_TimeBaseInit(TIM2, &TIM2_TimeBaseStructure); // Time base configuration
TIM_ClearFlag(TIM2,TIM_FLAG_Update);
TIM_ITConfig(TIM2,TIM_IT_Update,ENABLE );
TIM_Cmd(TIM2, ENABLE);
NVIC_InitStructure.NVIC_IRQChannel = TIM2_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
}
void TIM2_IRQHandler(void)
{
if (TIM_GetITStatus(TIM2, TIM_IT_Update) != RESET)
{
TIM_ClearITPendingBit(TIM2, TIM_IT_Update);
CAPTURE=(u32)TIM_GetCounter(TIM3);
}
sum+=CAPTURE;
count++;
if(count==4)
{
Frequency=sum*4; //Calculate the frequency formula F=n*t; Here we calculate the count value 4 times, which is the frequency of 1S.
sum=0;
count=0;
}
TIM_SetCounter(TIM3,0);
}
Previous article:STM32 timer encoder mode calculates the number of AB phase pulses of the reduction motor
Next article:Understanding of STM32 address mapping
Recommended ReadingLatest update time:2024-11-16 12:43
- Popular Resources
- Popular amplifiers
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- Innolux's intelligent steer-by-wire solution makes cars smarter and safer
- 8051 MCU - Parity Check
- How to efficiently balance the sensitivity of tactile sensing interfaces
- What should I do if the servo motor shakes? What causes the servo motor to shake quickly?
- 【Brushless Motor】Analysis of three-phase BLDC motor and sharing of two popular development boards
- Midea Industrial Technology's subsidiaries Clou Electronics and Hekang New Energy jointly appeared at the Munich Battery Energy Storage Exhibition and Solar Energy Exhibition
- Guoxin Sichen | Application of ferroelectric memory PB85RS2MC in power battery management, with a capacity of 2M
- Analysis of common faults of frequency converter
- In a head-on competition with Qualcomm, what kind of cockpit products has Intel come up with?
- Dalian Rongke's all-vanadium liquid flow battery energy storage equipment industrialization project has entered the sprint stage before production
- Allegro MicroSystems Introduces Advanced Magnetic and Inductive Position Sensing Solutions at Electronica 2024
- Car key in the left hand, liveness detection radar in the right hand, UWB is imperative for cars!
- After a decade of rapid development, domestic CIS has entered the market
- Aegis Dagger Battery + Thor EM-i Super Hybrid, Geely New Energy has thrown out two "king bombs"
- A brief discussion on functional safety - fault, error, and failure
- In the smart car 2.0 cycle, these core industry chains are facing major opportunities!
- The United States and Japan are developing new batteries. CATL faces challenges? How should China's new energy battery industry respond?
- Murata launches high-precision 6-axis inertial sensor for automobiles
- Ford patents pre-charge alarm to help save costs and respond to emergencies
- New real-time microcontroller system from Texas Instruments enables smarter processing in automotive and industrial applications
- Where can I find older ICs?
- Make ADAS technology more popular in vehicles
- What is a hysteresis comparator?
- VICOR DCM2322 isolated regulated DC-DC converter is now available for free!
- Zigbee learning notes---protocol stack NV operation
- Required selection: 1.5V lithium rechargeable button battery Rated voltage (V) 1.5V
- GD32E231 analog IIC driver LSM6DSO
- Single Voltage Reference vs. Dual Voltage Reference - I
- Basic C language programming specifications for microcontroller development
- [N32L43X Review] 2. Simulating I2C to drive OLED