求各位指导一下,我下面的程序,我配置TIM1给互补输出,通道一占空比为80%,通道二为50%,通道三位20%,软件仿真后,其相应的通道输出和配置的一样为80%、50%和20%,但是相应的互补输出通道却全是20%,要求应该和相应配置的一样为80%、50%和20%啊,这是问什么呢?
#include"stm32f10x.h"
void GPIO_init(void)
{
GPIO_InitTypeDef GPIO_InitStructure;//声明端口结构,需要放在前面
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA|RCC_APB2Periph_GPIOB,ENABLE);//开启相应端口时钟
// RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO,ENABLE);
//*端口A8,A9,A10是TIM1_PWM波的输出端***************************?
GPIO_InitStructure.GPIO_Pin=GPIO_Pin_8|GPIO_Pin_9|GPIO_Pin_10;
GPIO_InitStructure.GPIO_Mode=GPIO_Mode_AF_PP;//PWM波设为复用推挽输出
GPIO_InitStructure.GPIO_Speed=GPIO_Speed_50MHz;//端口频率可设为2,10,50??
GPIO_Init(GPIOA,&GPIO_InitStructure);//启动A端口
//***************************************************************************
//**************端口B13,B14,B15是TIM1_PWM波的互补输出端**********************
GPIO_InitStructure.GPIO_Pin=GPIO_Pin_13|GPIO_Pin_14|GPIO_Pin_15;
GPIO_InitStructure.GPIO_Speed=GPIO_Speed_50MHz;//端口频率可设为2,10,50
GPIO_InitStructure.GPIO_Mode=GPIO_Mode_AF_PP;//PWM波的复用推挽输出
GPIO_Init(GPIOB,&GPIO_InitStructure);//启动B端口
}
//**************************************************************************
//****TIM1_PWM波1通道初始化*************************************************
void TIM1_PWM_1_init(void)
{
TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;
TIM_OCInitTypeDef TIM_OCInitStructure;
TIM_BDTRInitTypeDef TIM_BDTRInitStructure;
RCC_APB2PeriphClockCmd(RCC_APB2Periph_TIM1,ENABLE);
TIM_TimeBaseStructure.TIM_Period=1000-1;
TIM_TimeBaseStructure.TIM_Prescaler=72-1;
TIM_TimeBaseStructure.TIM_ClockDivision=0;
TIM_TimeBaseStructure.TIM_CounterMode=TIM_CounterMode_Down;
TIM_TimeBaseStructure.TIM_RepetitionCounter=0;
TIM_TimeBaseInit(TIM1,&TIM_TimeBaseStructure);
TIM_ARRPreloadConfig(TIM1,ENABLE);//使能TIM1在ARR上的预装载寄存器
TIM_OCInitStructure.TIM_OCMode=TIM_OCMode_PWM1;//选择定时器模式TIM脉冲宽度调制模式1
TIM_OCInitStructure.TIM_OutputState=TIM_OutputState_Enable;//选择输出比较状态
TIM_OCInitStructure.TIM_OutputNState=TIM_OutputNState_Enable;//选择互补输出比较状态
TIM_OCInitStructure.TIM_OCPolarity=TIM_OCPolarity_High;//选择输出极性
TIM_OCInitStructure.TIM_OCNPolarity=TIM_OCNPolarity_High;//选择互补输出极性
TIM_OCInitStructure.TIM_Pulse=800;//设置待装入捕获比较寄存器的脉冲值
TIM_OC1Init(TIM1,&TIM_OCInitStructure);//捕获比较匹配器结构1通道赋值
TIM_OCInitStructure.TIM_Pulse=500;//设置待装入捕获比较寄存器的脉冲值
TIM_OC2Init(TIM1,&TIM_OCInitStructure);
TIM_OCInitStructure.TIM_Pulse=200;//设置待装入捕获比较寄存器的脉冲值
TIM_OC3Init(TIM1,&TIM_OCInitStructure);
TIM_OC1PreloadConfig(TIM1,TIM_OCPreload_Enable);//使能TIM1在CCR1上的预装载寄存器
TIM_OC2PreloadConfig(TIM1,TIM_OCPreload_Enable);
TIM_OC3PreloadConfig(TIM1,TIM_OCPreload_Enable);
//死区设置
TIM_BDTRInitStructure.TIM_OSSRState=TIM_OSSRState_Enable;//TIM1_OSSRState设置在运行模式下非工作状态选项
TIM_BDTRInitStructure.TIM_OSSIState=TIM_OSSIState_Enable;//TIM1_OSSIState设置在空闲模式下非工作状态选项(使能TIM1 OSSI状态)
TIM_BDTRInitStructure.TIM_LOCKLevel=TIM_LOCKLevel_OFF;//TIM1_LOCKLevel设置了锁电平参数(不锁任何位)
TIM_BDTRInitStructure.TIM_DeadTime=0x00;//这里调整死区大小0-0xff,TIM1_DeadTIM1指定了输出打开和关闭状态之间的延时
TIM_BDTRInitStructure.TIM_Break=TIM_Break_Disable;//TIM1_Break使能或者失能TIM1刹车输入(失能TIM1刹车输入)
TIM_BDTRInitStructure.TIM_BreakPolarity=TIM_BreakPolarity_High;//TIM1_BreakPolarity设置TIM1刹车输入管脚极性(TIM1刹车输入管脚极性高)
TIM_BDTRInitStructure.TIM_AutomaticOutput=TIM_AutomaticOutput_Enable;//TIM1_AutomaticOutput使能或者失能自动输出功能(自动输出功能使能)
TIM_BDTRConfig(TIM1,&TIM_BDTRInitStructure);//(设置刹车特性,死区时间,锁电平,OSSI,OSSR状态和AOE(自动输出使能))
TIM_Cmd(TIM1,ENABLE);//使能或者失能指定的TIM1
TIM_CtrlPWMOutputs(TIM1,ENABLE);//使能或者失能TIM1外设的主输出
}
|