The CHN1 and CHN4 of TIM1 are set to output PWM. The code is as follows, but the simulated waveform is incorrect and the upper device is also incorrect:
RCC->APB2ENR|=1<<11; //TIM1 clock enable
RCC->APB2ENR|=1<<2; //Enable PORTA clock
GPIOA->CRH&=0XFFFFFFF0; //PA8 output
GPIOA->CRH|=0X0000000B; //General push-pull output
GPIOA->ODR|=1<<8; //PA8 pull-up
GPIOA->CRH&=0XFFFF0FFF; //PA11 output
GPIOA->CRH|=0X0000B000; //General push-pull output
GPIOA->ODR|=1<<11; //PA11 pull-up
TIM1->ARR=arr; //Set the counter to automatically reload value
TIM1->PSC=psc; //Prescaler does not divide
TIM4->ARR=arr; //Set the counter to automatically reload value
TIM4->PSC=psc; //Prescaler does not divide
TIM1->CCMR1|=6<<4; //CH1 PWM2 mode
TIM1->CCMR1|=1<<3; //CH1 preload enable
TIM1->CCMR2|=7<<12; //CH4 PWM2 mode
TIM1->CCMR2|=1<<11; //CH4 preload enable
TIM1->CCER|= pwdState << 0; //OC1 output enable
TIM1->CCER|= pwdState << 12; //OC1 output enable
TIM1->CR1=0x8000; //ARPE enable
TIM1->CR1|=0x01; //Enable timer 1
Checking the register manual, I found that TIM1 has a MOE bit that controls the output of TIM1: MOE: Main output enable Bit 15 Once the brake input is valid, this bit is cleared to '0' asynchronously by hardware. Depending on the setting value of the AOE bit, this bit can be cleared to '0' by software or automatically set to 1. It is only valid for channels configured as outputs. 0: Disable OC and OCN outputs or force them to idle state; 1: If the corresponding enable bit (CCxE, CCxNE bits of the TIMx_CCER register) is set, OC and OCN outputs are turned on. For details on OC/OCN enable, see 13.4.9 TIM1 and TIM8 capture/compare enable register (TIMx_CCER).
Add the following code and the output will be normal:
TIM1->BDTR |= 1<<15;
Previous article:STM32 TIM1 PWM output problem
Next article:STM32F103_Frequency meter
- 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
- EEWORLD University Hall----Live Replay: TI's new generation Sitara? AM62 processor revolutionizes human-computer interaction-accelerates the development of edge AI
- Zigbee low power consumption steps
- When using the ADC of Jinxin Electronics AVP32F335, the sampling value deviation
- mPower1203 programmable power supply also supports third-party applications to obtain the current of the device under test in real time
- MSP430F149 Learning Road - Capture/Compare Mode
- DIY a USB hub shell
- STM8S001J3 uses HalfDuplex mode and uses IO mapping and cannot receive data.
- Analysis of the Causes of Operational Amplifier Oscillation and Self-excitation
- (Bonus 14) GD32L233 Review - Driving Segment Code LCD
- China's chip self-sufficiency rate was 30% last year, and the goal is to reach 70% by 2025 (attached with representative companies in 70 sub-sectors of domestic chips)