我做了一个动态改变占空比的程序 现在要加上刹车功能 故障时封锁SPWM输出
但是我一使能刹车 SPWM就出不来
高手帮忙看一下 我哪设置不对吗
修给占空比我是在 TIM5的中断中做的
void Timeconfig(void)
{
/* Time Base configuration */
TIM_TimeBaseStructure.TIM_Prescaler = 0;
TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_CenterAligned1 ;
TIM_TimeBaseStructure.TIM_Period = TIM1_Period;
TIM_TimeBaseStructure.TIM_ClockDivision = 0;
TIM_TimeBaseStructure.TIM_RepetitionCounter = 0;
TIM_TimeBaseInit(TIM1, &TIM_TimeBaseStructure);
//TIM_ARRPreloadConfig(TIM1, ENABLE);
/* Channel 1, Configuration in PWM mode */
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 = 680;
TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_High;
TIM_OCInitStructure.TIM_OCNPolarity = TIM_OCNPolarity_High;
TIM_OCInitStructure.TIM_OCIdleState = TIM_OCIdleState_Set;
TIM_OCInitStructure.TIM_OCNIdleState = TIM_OCIdleState_Reset;
TIM_OC1Init(TIM1, &TIM_OCInitStructure);
//死区设置
TIM_BDTRInitStructure.TIM_OSSRState = TIM_OSSRState_Enable;
TIM_BDTRInitStructure.TIM_OSSIState = TIM_OSSIState_Enable;
TIM_BDTRInitStructure.TIM_LOCKLevel = TIM_LOCKLevel_1;
TIM_BDTRInitStructure.TIM_DeadTime = 20; //这里调整死区大小0-0xff
TIM_BDTRInitStructure.TIM_Break = TIM_Break_Disable;
TIM_BDTRInitStructure.TIM_BreakPolarity = TIM_BreakPolarity_Low;
TIM_BDTRInitStructure.TIM_AutomaticOutput = TIM_AutomaticOutput_Enable;
TIM_BDTRConfig(TIM1, &TIM_BDTRInitStructure);
//启用CCR1寄存器的影子寄存器(直到产生更新事件才更改设置)
//TIM_OC1PreloadConfig(TIM1, TIM_OCPreload_Disable);
//TIM1_OC2模块设置(设置2通道占空比)
TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable;
TIM_OCInitStructure.TIM_OutputNState = TIM_OutputNState_Enable;
TIM_OCInitStructure.TIM_Pulse = 680;
TIM_OC2Init(TIM1, &TIM_OCInitStructure);
//启用CCR2寄存器的影子寄存器(直到产生更新事件才更改设置)
//TIM_OC2PreloadConfig(TIM1, TIM_OCPreload_Enable);
TIM_TimeBaseStructure.TIM_Prescaler= 0;
TIM_TimeBaseStructure.TIM_CounterMode= TIM_CounterMode_Up;
TIM_TimeBaseStructure.TIM_Period= 4000;
TIM_TimeBaseStructure.TIM_ClockDivision= 0;
TIM_TimeBaseInit( TIM5, &TIM_TimeBaseStructure );
TIM_ITConfig( TIM5, TIM_IT_Update, ENABLE );
TIM_Cmd( TIM5, ENABLE );
TIM_TimeBaseStructure.TIM_Prescaler= 719;
TIM_TimeBaseStructure.TIM_CounterMode= TIM_CounterMode_Up;
TIM_TimeBaseStructure.TIM_Period= 20;
TIM_TimeBaseStructure.TIM_ClockDivision= 0;
TIM_TimeBaseInit( TIM3, &TIM_TimeBaseStructure );
TIM_SelectOutputTrigger( TIM3, TIM_TRGOSource_Update );// ADC Trigger 5KHz
TIM_Cmd( TIM3, ENABLE );
/* TIM1 counter enable */
TIM_Cmd(TIM1, ENABLE);
/* TIM1 Main Output Enable */
TIM_CtrlPWMOutputs(TIM1, ENABLE);
} |