同一个定时器的不同通道产生的PWM不同步。我是用TIM1的CH1、CH2,结果发现波形不同步怎么回事??麻烦看一下:@正点原子
这是我的定时器还有PWM的配置:
****************************************************************************************
void TIM1_Mode_Init(void)
{
TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;
TIM_OCInitTypeDef TIM_OCInitStructure;
TIM_BDTRInitTypeDef TIM_BDTRInitStructure;
/*定时器初始化*/
Channel1Pulse = 0;//初始化,没有任何pwm输出
Channel2Pulse = 0;
TIM_TimeBaseStructure.TIM_Prescaler = 12; //设置用来作为TIM 时钟频率除数的预分频值
TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up; //计数器模式 /* 向上计数模式 */
TIM_TimeBaseStructure.TIM_Period = 999; //自动重装载寄存器周期的值
TIM_TimeBaseStructure.TIM_ClockDivision = TIM_CKD_DIV1; //时钟分割 不分频
// TIM_TimeBaseStructure.TIM_RepetitionCounter = 0; //设置 周期 计数值
TIM_TimeBaseInit(TIM1, &TIM_TimeBaseStructure);
TIM_TimeBaseInit(TIM8, &TIM_TimeBaseStructure);
/*TIM1 配置*/
TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_PWM1; //脉冲宽度调制模式2
TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable; //使能输出比较状态
TIM_OCInitStructure.TIM_OutputNState = TIM_OutputNState_Enable; //使能 互补 输出状态
TIM_OCInitStructure.TIM_Pulse = Channel1Pulse; //给1通道填入初始值
TIM_OCInitStructure.TIM_Pulse = Channel2Pulse; //给2通道填入初始值
TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_High; //输出比较极性低
TIM_OCInitStructure.TIM_OCNPolarity = TIM_OCNPolarity_High;//互补 输出极性低
TIM_OCInitStructure.TIM_OCIdleState = TIM_OCIdleState_Set; //MOE=0 设置 TIM1输出比较空闲状态
TIM_OCInitStructure.TIM_OCNIdleState = TIM_OCIdleState_Reset;//MOE=0 重置 TIM1输出比较空闲状态
// TIM_OCInitStructure.TIM_Pulse = Channel2Pulse; //给2通道填入初始值
TIM_OC1Init(TIM1, &TIM_OCInitStructure);//设定1通道好的参数 初始化TIM
TIM_OC1Init(TIM8, &TIM_OCInitStructure);//设定1通道好的参数 初始化TIM
TIM_OC2Init(TIM1, &TIM_OCInitStructure);//初始化
TIM_OC2Init(TIM8, &TIM_OCInitStructure);//初始化
/*设置刹车特性 死区时间 锁电平 OSSI OSSR 状态 AOE(自动输出使能)*/
TIM_BDTRInitStructure.TIM_OSSRState = TIM_OSSRState_Enable; //设置在运行模式下 非工作状态选项 OSSR
TIM_BDTRInitStructure.TIM_OSSIState = TIM_OSSIState_Enable; //设置在运行模式下 非工作状态选项 OSSI
TIM_BDTRInitStructure.TIM_LOCKLevel = TIM_LOCKLevel_1; //使用锁电平1
TIM_BDTRInitStructure.TIM_DeadTime = 80; //指定了输出和打开 关闭状态之间的延时 约 400ns
TIM_BDTRInitStructure.TIM_AutomaticOutput = TIM_AutomaticOutput_Enable;//自动输出功能使能
TIM_BDTRConfig(TIM1, &TIM_BDTRInitStructure); //初始化设定好的参数
TIM_BDTRConfig(TIM8, &TIM_BDTRInitStructure); //初始化设定好的参数
/* TIM1 counter enable */
TIM_Cmd(TIM1, ENABLE);
TIM_Cmd(TIM8, ENABLE);
/* Main Output Enable */
TIM_CtrlPWMOutputs(TIM1, ENABLE);
TIM_CtrlPWMOutputs(TIM8, ENABLE);
}
****************************************************************************************
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
一周热门 更多>