| 
 
新手入门 
 
	积分11金钱11 注册时间2021-1-29在线时间3 小时 | 
 
1金钱 
| 模仿例程调用tim4的ch1 ch2 ch3生成3路pwm,rgb的led常亮,没有脉冲生成。采用例程PA6输出pwm 板子led实现呼吸但是引脚外接led常亮,不知道什么原因? 代码如下:
 int main(void)
 {
 u16 led0pwmval=0;
 u8 dir=1;
 NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);//éèÖÃÏμí3ÖD¶ÏóÅÏè¼¶·Ö×é2
 delay_init(168);
 uart_init(115200);
 TIM3_PWM_Init(500-1,84-1);
 while(1)
 {
 delay_ms(10);
 if(dir)led0pwmval++;
 else led0pwmval--;
 if(led0pwmval>300)dir=0;
 if(led0pwmval==0)dir=1;
 
 TIM_SetCompare1(TIM3,led0pwmval);        /
 }
 }
 
 
 void TIM3_PWM_Init(u32 arr,u32 psc)
 {
 //′Ë2¿·ÖDèêÖ¶ˉDT¸ÄIO¿úéèÖÃ
 
 GPIO_InitTypeDef GPIO_InitStructure;
 TIM_TimeBaseInitTypeDef  TIM_TimeBaseStructure;
 TIM_OCInitTypeDef  TIM_OCInitStructure;
 
 RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM3,ENABLE);
 RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA, ENABLE);
 
 GPIO_PinAFConfig(GPIOA,GPIO_PinSource6,GPIO_AF_TIM3);
 
 GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6;           //GPIOFA
 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(TIM3,&TIM_TimeBaseStructure);
 
 //3õê¼»ˉTIM14 Channel1 PWMÄ£ê½
 TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_PWM1;
 TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable;
 TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_Low;
 TIM_OC1Init(TIM3, &TIM_OCInitStructure);
 
 TIM_OC1PreloadConfig(TIM3, TIM_OCPreload_Enable);
 
 TIM_ARRPreloadConfig(TIM3,ENABLE);
 
 TIM_Cmd(TIM3, ENABLE);
 
 
 }
 
 
 | 
 |