新手,为什么
STM32f429就是不能输出pwm波形 ,检查了好多遍就是找不到问题,怎么办 ?? 是我配置出问题了吗??代码如下,有大神能指教一下吗,
GPIO_InitTypeDef GPIO_InitStructure;
tiM_TimeBaseInitTypeDef TIM_TimeBaseStructure;
TIM_OCInitTypeDef TIM_OCInitStructure;
RCC_AHB1PeriphClockCmd ( RCC_AHB1Periph_GPIOA, ENABLE);
RCC_AHB1PeriphClockCmd ( RCC_APB1Periph_TIM2, ENABLE);
/* */
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;
GPIO_Init(GPIOA, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_1;
GPIO_Init(GPIOA, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2;
GPIO_Init(GPIOA, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_3;
GPIO_Init(GPIOA, &GPIO_InitStructure);
GPIO_PinAFConfig(GPIOA,GPIO_PinSource0,GPIO_AF_TIM2);
GPIO_PinAFConfig(GPIOA,GPIO_PinSource1,GPIO_AF_TIM2);
GPIO_PinAFConfig(GPIOA,GPIO_PinSource2,GPIO_AF_TIM2);
GPIO_PinAFConfig(GPIOA,GPIO_PinSource3,GPIO_AF_TIM2);
TIM_TimeBaseStructure.TIM_Period = (1000000-1); //µ±¶¨Ê±Æ÷´Ó0¼ÆÊýµ½ TIM_Period+1 £¬ÎªÒ»¸ö¶¨Ê±ÖÜÆÚ
TIM_TimeBaseStructure.TIM_Prescaler = 17; //ÉèÖÃÔ¤·ÖƵ
TIM_TimeBaseStructure.TIM_ClockDivision = TIM_CKD_DIV1 ; //ÉèÖÃʱÖÓ·ÖƵϵÊý£º²»·ÖƵ(ÕâÀïÓò»µ½)
TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up; //ÏòÉϼÆÊýģʽ
// ³õʼ»¯¶¨Ê±Æ÷TIMx, x[2,3,4,5]
TIM_TimeBaseInit(TIM2, &TIM_TimeBaseStructure);
/*PWMģʽÅäÖÃ*/
/* PWM1 Mode configuration: Channel1 */
TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_PWM1; //ÅäÖÃΪPWMģʽ1
TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable; //ʹÄÜÊä³ö
TIM_OCInitStructure.TIM_Pulse = 0; //ÉèÖóõʼPWMÂö³å¿í¶ÈΪ0
TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_High; //µ±¶¨Ê±Æ÷¼ÆÊýֵСÓÚCCR1_ValʱΪµÍµçƽ LEDµÆÁÁ
//ʹÄÜͨµÀ1
TIM_OC1Init(TIM2, &TIM_OCInitStructure);
/*ʹÄÜͨµÀÖØÔØ*/
TIM_OC1PreloadConfig(TIM2, TIM_OCPreload_Enable);
//ʹÄÜͨµÀ2
TIM_OC2Init(TIM2, &TIM_OCInitStructure);
/*ʹÄÜͨµÀÖØÔØ*/
TIM_OC2PreloadConfig(TIM2, TIM_OCPreload_Enable);
//ʹÄÜͨµÀ3
TIM_OC3Init(TIM2, &TIM_OCInitStructure);
/*ʹÄÜͨµÀÖØÔØ*/
TIM_OC3PreloadConfig(TIM2, TIM_OCPreload_Enable);
//ʹÄÜͨµÀ4
TIM_OC4Init(TIM2, &TIM_OCInitStructure);
/*ʹÄÜͨµÀÖØÔØ*/
TIM_OC4PreloadConfig(TIM2, TIM_OCPreload_Enable);
TIM_CtrlPWMOutputs(TIM2, ENABLE);
// ¿ªÆô¼ÆÊýÆ÷ÖжÏ
//TIM_ITConfig(TIM2,TIM_IT_Update,ENABLE);
// ʹÄܼÆÊýÆ÷
TIM_Cmd(TIM2, ENABLE);
一周热门 更多>