STM32PWM不能双路同时输出

2019-07-14 19:23发布

tiM3的CH1,CH2单路输出都是可以的,但两个同时用时输出却只有一个,完全一样的
void tim1PWM_init(void)                                //PWM输出测试函数
{
    TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;
        TIM_OCInitTypeDef TIM_OCInitStructure;
    RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM3, ENABLE);
       
        TIM_TimeBaseStructure.TIM_Period =1999;
        TIM_TimeBaseStructure.TIM_Prescaler =500;
        TIM_TimeBaseStructure.TIM_ClockDivision =0;//TIM_CKD_DIV1;
        TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;
        TIM_TimeBaseInit(TIM3, & TIM_TimeBaseStructure);


       //1通道
        TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_PWM2;
        TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable;
        TIM_OCInitStructure.TIM_Pulse =1000;                                       
        TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_High;                  
       TIM_OC1Init(TIM3, &TIM_OCInitStructure);                                    
       TIM_OC1PreloadConfig(TIM3, TIM_OCPreload_Enable);

       //2通道
       TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_PWM2;
        TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable;
        TIM_OCInitStructure.TIM_Pulse =100;
        TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_Low;
        TIM_OC2Init(TIM3, & TIM_OCInitStructure);
        TIM_OC2PreloadConfig(TIM3, TIM_OCPreload_Enable);

        TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable;  
        TIM_ARRPreloadConfig(TIM3, ENABLE);       
        TIM_Cmd(TIM3, ENABLE);
}

屏幕截图(75).png
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。