应用TIM1的ch3和ch4产生相位相差180度的PWM波问题

2019-03-23 18:32发布

我用TIM1的ch1和ch1N,ch2和ch2N产生两对互补的PWM波,ch3和ch4产生相位相差180度的PWM,但现在问题是产生的互补的PWM波没有问题,但是相位相差180度的PWM波只有一路有波形,另外一路没有输出(始终是低),相位相差180度的ch3和ch4的初始化配置如下:
GPIO_InitTypeDef GPIO_InitStructure;
TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;
TIM_OCInitTypeDef  TIM_OCInitStructure;

/* GPIOA clocks enable */
RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA, ENABLE);
/* TIM1 clock enable */
RCC_APB2PeriphClockCmd(RCC_APB2Periph_TIM1, ENABLE);

GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10 | GPIO_Pin_11;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
GPIO_Init(GPIOA,&GPIO_InitStructure);

/* Connect TIM pins to AF6 */
GPIO_PinAFConfig(GPIOA, GPIO_PinSource10, GPIO_AF_6);
GPIO_PinAFConfig(GPIOA, GPIO_PinSource11, GPIO_AF_6);

/* Time Base configuration */
TIM_TimeBaseStructure.TIM_Prescaler = 0;         
TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_CenterAligned1;   
TIM_TimeBaseStructure.TIM_Period = 600;         
TIM_TimeBaseStructure.TIM_ClockDivision = TIM_CKD_DIV1;      
TIM_TimeBaseStructure.TIM_RepetitionCounter = 0;        
TIM_TimeBaseInit(TIM1,&TIM_TimeBaseStructure);         
  TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_PWM1;        
TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable;     
TIM_OCInitStructure.TIM_OutputNState = TIM_OutputNState_Disable;   
TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_High;      
TIM_OCInitStructure.TIM_OCNPolarity = TIM_OCNPolarity_Low;      
TIM_OCInitStructure.TIM_OCIdleState = TIM_OCIdleState_Reset;     
TIM_OCInitStructure.TIM_OCNIdleState = TIM_OCNIdleState_Reset;
TIM_OCInitStructure.TIM_Pulse = 200;           
TIM_OC3Init(TIM1,&TIM_OCInitStructure);            
TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_PWM2;        
TIM_OCInitStructure.TIM_Pulse = 400;         
TIM_OC4Init(TIM1,&TIM_OCInitStructure);           

TIM_CtrlPWMOutputs(TIM1, ENABLE);            
TIM_Cmd(TIM1,ENABLE);   
求高手帮忙指点,谢谢。
此帖出自小平头技术问答
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。