产生一个2K 占空比50%的pwm波形 // PWM输出 PB1 void PwmPhyConfig() { //此部分需手动修改 IO 口设置 RCC->APB1ENR |= 1<<1; //TIM3 时钟使能 RCC->AHB1ENR |= 1<<1; //使能 PORTB 时钟 GPIOB->MODER |= (2<<1*2); //复用模式 GPIOB->OTYPER &= ~(1<<1); //推挽 GPIOB->PUPDR |= (1<<1*2); //上拉 GPIOB->OSPEEDR |= (1<<1*2); //高速 GPIOB->AFR[0] |= (2<<1*4); //GPIO_AF2_TIM3 TIM3->ARR = pwm_arr; //设定计数器自动重装值 TIM3->PSC = pwm_psc; //预分频器不分频 TIM3->CCMR2 |= 6<<12; //CH4 PWM1 模式 TIM3->CCMR2 |= 1<<11; //CH4 预装载使能 TIM3->CCER |= 1<<12; //OC4 输出使能 TIM3->CCER |= 1<<13; //OC4 低电平有效 TIM3->CR1 |= 1<<7; //ARPE 使能 TIM3->CR1 |= 1<<0; //使能定时器 3 TIM3->CCR4 = 250; } /******************************pwm*************************************/ #define pwm_arr (500-1) //2K #define pwm_psc (108-1) //1M void PwmPhyConfig(void); /**********************************************************************/
标签:TIM3,arr,void,1CR1,STM32F7xx,pwm,外设 From: https://www.cnblogs.com/lum0126/p/16892972.html