我同时打开3个定时器时,只有定时器3能输出PWM,定时器2,5输出的都是直流。而屏蔽掉定时器5之后,定时器2,3都能输出PWM。或者屏蔽掉定时器2,定时器3,5也能输出PWM。
屏蔽掉定时器3,定时器2,5只能输出直流。不知道是不是定时器5和定时器2有冲突还是什么原因,求各位解答一下。下面是配置的PWM代码
RCC->APB2ENR |= 1<<2; //使能A端口时钟
GPIOA->CRL &= 0X0FFFFF00; //推挽输出PA1,PA0,PA7
GPIOA->CRL |= 0XB00000BB;
GPIOA->ODR |= 0X0083; //上拉
TIM_BaseInit(TIM2,1027,6); //10k的PWM
TIM_BaseInit(TIM3,1199,1); //30k的PWM
TIM_BaseInit(TIM5,2000,2); //50k的PWM
TIM2->CCMR1 |= 0X6<<12; //PWM1模式
TIM2->CCMR1 |= 1<<11; //快速预装载使能
TIM2->CR1 = 0X0080; //使能自动重装载的值
TIM2->CCMR1 &= ~(3<<8); //CH2配置为输出
TIM2->CCR2 = CCR_Val1;
TIM2->CCER |= 1<<4; //输出比较使能
TIM2->CCER |= ~(1<<5); //输出极性高电平有效
TIM3->CCMR1 |= 0X6<<12; //PWM1模式
TIM3->CCMR1 |= 1<<11; //快速预装载使能
TIM3->CR1 = 0X0080; //使能自动重装载的值
TIM3->CCMR1 &= ~(3<<8); //CH2配置为输出
TIM3->CCR2 = CCR_Val2;
TIM3->CCER |= 1<<4; //输出比较使能
TIM3->CCER |= ~(1<<5); //输出极性高电平有效
TIM5->CCMR1 |= 0X6<<4; //PWM1模式
TIM5->CCMR1 |= 1<<3; //快速预装载使能
TIM5->CR1 = 0X0080; //使能自动重装载的值
TIM5->CCMR1 &= ~(3<<0); //CH1配置为输出
TIM5->CCR1 = CCR_Val3;
TIM5->CCER |= 1<<0; //输出比较使能
TIM5->CCER |= ~(1<<1); //输出极性高电平有效
TIMx_Enable(TIM5);
TIMx_Enable(TIM3);
TIMx_Enable(TIM2); |