STM32F103高级定时器互补PWM问题

2019-07-21 07:41发布

在使用STM32F103的高级定时器TIM8时,遇到一个问题:初始化的互补PWM波形输出时,同时初始化3对互补通道,CH1CH1NCH2CH2NCH3CH3N,使用时,需要将CH1=1CH1N=0CH2=0CH2N=1,到这里都可以实现,但是下面的CH3=1CH3N=1,不会实现,同时为0倒是会,请问怎么去配置呢?
初始化代码如下:voidTIM8_Configuration(void) //72M{       TIM_TimeBaseInitTypeDef  TIM_TimeBaseStructure;      TIM_OCInitTypeDefTIM_OCInitStructure;       TIM_BDTRInitTypeDefTIM_BDTRInitStructure;                RCC_APB2PeriphClockCmd(RCC_APB2Periph_TIM8,ENABLE);       RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO,ENABLE);       TIM_TimeBaseStructure.TIM_Period=99;       TIM_TimeBaseStructure.TIM_Prescaler=71;         TIM_TimeBaseStructure.TIM_ClockDivision =TIM_CKD_DIV1 ;       TIM_TimeBaseStructure.TIM_CounterMode=TIM_CounterMode_CenterAligned1;       TIM_TimeBaseInit(TIM8,&TIM_TimeBaseStructure);         //PWM互补信号输出PC6PA7       TIM_OCInitStructure.TIM_OCMode=TIM_OCMode_PWM1;//PWM输出模式           TIM_OCInitStructure.TIM_OutputState=TIM_OutputState_Enable;       TIM_OCInitStructure.TIM_OutputNState=TIM_OutputNState_Enable;//互补输出使能       TIM_OCInitStructure.TIM_Pulse=0;//初始占空比       TIM_OCInitStructure.TIM_OCPolarity=TIM_OCPolarity_Low;       TIM_OCInitStructure.TIM_OCNPolarity=TIM_OCNPolarity_Low;       TIM_OCInitStructure.TIM_OCIdleState=TIM_OCIdleState_Set;//死区后输出状态       TIM_OCInitStructure.TIM_OCNIdleState=TIM_OCNIdleState_Reset;       TIM_OC1Init(TIM8,&TIM_OCInitStructure);       TIM_OC1PreloadConfig(TIM8,TIM_OCPreload_Enable);//PWM输出口PB13       TIM_OC1FastConfig(TIM8,TIM_OCFast_Enable);        //PWM互补信号输出PC7PB0       TIM_OCInitStructure.TIM_OCMode=TIM_OCMode_PWM1;       TIM_OCInitStructure.TIM_OutputState=TIM_OutputState_Enable;       TIM_OCInitStructure.TIM_OutputNState=TIM_OutputNState_Enable;       TIM_OCInitStructure.TIM_Pulse=0;       TIM_OCInitStructure.TIM_OCPolarity=TIM_OCPolarity_Low;       TIM_OCInitStructure.TIM_OCNPolarity=TIM_OCNPolarity_Low;       TIM_OCInitStructure.TIM_OCIdleState=TIM_OCIdleState_Set;//死区后输出状态       TIM_OCInitStructure.TIM_OCNIdleState=TIM_OCNIdleState_Reset;       TIM_OC2Init(TIM8,&TIM_OCInitStructure);       TIM_OC2PreloadConfig(TIM8,TIM_OCPreload_Enable);//PWM输出口PB14       TIM_OC2FastConfig(TIM8,TIM_OCFast_Enable);        //PWM互补信号输出PC8PB1       TIM_OCInitStructure.TIM_OCMode=TIM_OCMode_PWM1;       TIM_OCInitStructure.TIM_OutputState=TIM_OutputState_Enable;       TIM_OCInitStructure.TIM_OutputNState=TIM_OutputNState_Enable;       TIM_OCInitStructure.TIM_Pulse=0;       TIM_OCInitStructure.TIM_OCPolarity=TIM_OCPolarity_Low;       TIM_OCInitStructure.TIM_OCNPolarity=TIM_OCNPolarity_Low;       TIM_OCInitStructure.TIM_OCIdleState=TIM_OCIdleState_Set;//死区后输出状态       TIM_OCInitStructure.TIM_OCNIdleState=TIM_OCNIdleState_Reset;       TIM_OC3Init(TIM8,&TIM_OCInitStructure);       TIM_OC3PreloadConfig(TIM8,TIM_OCPreload_Enable);//PWM输出口PB14       TIM_OC3FastConfig(TIM8,TIM_OCFast_Enable);         //死区设置  TIM_BDTRInitStructure.TIM_OSSRState =TIM_OSSRState_Disable;//使能  TIM_BDTRInitStructure.TIM_OSSIState =TIM_OSSIState_Disable;//使能  TIM_BDTRInitStructure.TIM_LOCKLevel =TIM_LOCKLevel_OFF;//不锁任何位  TIM_BDTRInitStructure.TIM_DeadTime =0xCF;//死区设置为5us  TIM_BDTRInitStructure.TIM_Break =TIM_Break_Disable;//使能TIM刹车输入  TIM_BDTRInitStructure.TIM_BreakPolarity=TIM_BreakPolarity_High;//TIM刹车输入管脚为高       TIM_BDTRInitStructure.TIM_AutomaticOutput=TIM_AutomaticOutput_Enable;//自动输出功能使能 TIM_BDTRConfig(TIM8,&TIM_BDTRInitStructure);        //TIM_OCInitStructure.TIM_OCNIdleState=TIM_OCIdleState_Reset;    TIM_ARRPreloadConfig(TIM8,ENABLE);       //TIM_CCPreloadControl(TIM8,ENABLE);       TIM_CtrlPWMOutputs(TIM8,ENABLE);       TIM_Cmd(TIM8,ENABLE);}主函数如下:intmain(void){                     RCC_Configuration();//时钟配置       TIM8_Configuration();    //TIM8初始化  while(1)        {               TIM8->CCR1=60;               //TIM_CCxCmd(TIM8,TIM_Channel_1,TIM_CCx_Disable);               //TIM_CCxNCmd(TIM8,TIM_Channel_1,TIM_CCxN_Disable);                              //TIM_SetCompare2(TIM8,60);                //TIM8->CCR2=60;               //TIM8->CCR3=60;             //TIM_CCxCmd(TIM8,TIM_Channel_2,TIM_CCx_Enable);           TIM_CCxNCmd(TIM8,TIM_Channel_2,TIM_CCxN_Enable);              TIM_ForcedOC2Config(TIM8,TIM_ForcedAction_InActive);   }}此时使用的是通道CH1CH2两组互补波形,(示波器是4通道),波形如下图所示:CH1对应TIM8-CH1CH2对应TIM8-CH1NCH3对应TIM8-CH2CH4对应TIM8-CH2N从图上可以看到,TIM8-CH2TIM8-CH2N没有同时指高,请问怎么设置?
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。