This is a schematic diagram of a PWM. PWM is actually a timer that counts itself and compares it with the value we set, and finally gets the high and low levels, thus generating a regular waveform.
ARR is the maximum value of the count, and CCRX is the comparison value we set ourselves.
The timer pwm has up and down counting, pwm1 and pwm2 modes, and output polarity high and low selection
1. Configure rcc
2. Configure gpio multiplexing as timer
3. Set the timer pwm mode and enable
(1) PWM mode 1 - When counting up, channel 1 is at a valid level once TIMx_CNT < TIMx_CCR1, otherwise it is at an invalid level;
When counting down, once TIMx_CNT>TIMx_CCR1, channel 1 is at an invalid level, otherwise it is at a valid level.
PWM mode 2 - When counting up, channel 1 is at an invalid level once TIMx_CNT < TIMx_CCR1, otherwise it is at a valid level;
When counting down, once TIMx_CNT>TIMx_CCR1, channel 1 is at a valid level, otherwise it is at an invalid level.
(2) The effective level is set by TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_x, where x can be high or low
My own doubt is that I set TIM_SetCompare1(TIM14,3000); very high, but the motor rotates very slowly. When I try to set TIM_SetCompare1(TIM14,200);
My motor becomes faster, this is because there is something wrong with the setting of the pwm mode
void TIM14_PWM_Init(u32 arr,u32 psc)
{
GPIO_InitTypeDef GPIO_InitStructure;
TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;
TIM_OCInitTypeDef TIM_OCInitStructure;
RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM14,ENABLE);
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA, ENABLE);
GPIO_PinAFConfig(GPIOA,GPIO_PinSource7,GPIO_AF_TIM14);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_7;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
GPIO_Init(GPIOA,&GPIO_InitStructure);
TIM_TimeBaseStructure.TIM_Prescaler=psc;
TIM_TimeBaseStructure.TIM_CounterMode=TIM_CounterMode_Up; //我选择了向上计数
TIM_TimeBaseStructure.TIM_Period=arr;
TIM_TimeBaseStructure.TIM_ClockDivision=TIM_CKD_DIV1;
TIM_TimeBaseInit(TIM14,&TIM_TimeBaseStructure);
TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_PWM1; //选择了pwm1模式
TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable;
TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_Low; //输出极性是低电平
TIM_OC1Init(TIM14, &TIM_OCInitStructure);
TIM_OC1PreloadConfig(TIM14, TIM_OCPreload_Enable);
TIM_ARRPreloadConfig(TIM14,ENABLE);
TIM_Cmd(TIM14, ENABLE);
}
// I chose to count up
// Select pwm1 mode
//Output polarity is low level
When I output a larger set value ccrx, it is considered pwm1 and counts up, so when cnt So, when cnt The proportion of low level will be large, so the motor will rotate slowly.
Previous article:STM32 one timer outputs 4 PWMs with different frequencies and adjustable duty cycles
Next article:stm32f407 PWM (operation register)
- 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 application of several common contact parts in high-voltage connectors of new energy vehicles
- Wiring harness durability test and contact voltage drop test method
- From probes to power supplies, Tektronix is leading the way in comprehensive innovation in power electronics testing
- From probes to power supplies, Tektronix is leading the way in comprehensive innovation in power electronics testing
- Sn-doped CuO nanostructure-based ethanol gas sensor for real-time drunk driving detection in vehicles
- Design considerations for automotive battery wiring harness
- Do you know all the various motors commonly used in automotive electronics?
- What are the functions of the Internet of Vehicles? What are the uses and benefits of the Internet of Vehicles?
- Power Inverter - A critical safety system for electric vehicles
- Analysis of the information security mechanism of AUTOSAR, the automotive embedded software framework
- LM3644 Application Guide for Industrial Scanning
- [GD32E503 Review]——06. Detecting PT100 sensor temperature value through differential ADC
- A creative design of an electronic paper display clock by a foreign netizen
- LLC circuit to achieve ZVS
- TI's DSP OS running problem
- RA2L1 MCU download program JLink Info: T-bit of XPSR is 0 but should be 1.
- Silicon carbide industry chain science video: substrate and epitaxy
- Share an open source software download URL
- "Practice Together in 2021" + Looking Forward
- After zigbee sends data to nb-iot, nb-iot sends data to the cloud, but the data displayed on the cloud is completely wrong. How to solve it?