我有个问题想请教下,我用STM32F103C8T6芯片的time1定时器的OC2,OC4产生两路占空比可调的PWM方波,用它来驱动H桥芯片,现在的问题是,程序运行过程中,出现了PWM方波输出停止了,不输出了,不知道是什么原因
void PWM_init(void)
{
TIM_TimeBaseStructure.TIM_Prescaler = 0x1;
TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;
TIM_TimeBaseStructure.TIM_Period = 16000;
TIM_TimeBaseStructure.TIM_ClockDivision = 0x0;
TIM_TimeBaseStructure.TIM_RepetitionCounter=0X00;
TIM_TimeBaseInit(TIM1, &TIM_TimeBaseStructure);
TIM_OCInitTypeStructure.TIM_OCMode=TIM_OCMode_PWM2;
TIM_OCInitTypeStructure.TIM_OutputState=TIM_OutputState_Enable;
TIM_OCInitTypeStructure.TIM_OutputNState=TIM_OutputNState_Disable;
TIM_OCInitTypeStructure.TIM_Pulse=0;
TIM_OCInitTypeStructure.TIM_OCPolarity=TIM_OCPolarity_Low;
TIM_OC2Init(TIM1,&TIM_OCInitTypeStructure);
TIM_OCInitTypeStructure.TIM_Pulse=0;
TIM_OC4Init(TIM1,&TIM_OCInitTypeStructure);
TIM_Cmd (TIM1,ENABLE);
TIM_CtrlPWMOutputs(TIM1, ENABLE);
}
void PWM_SET_L(uint32_t j)
{
TIM_OCInitTypeStructure.TIM_Pulse=0;
TIM_OC2Init(TIM1,&TIM_OCInitTypeStructure);
delay(10);
TIM_OCInitTypeStructure.TIM_Pulse=j;
TIM_OC4Init(TIM1,&TIM_OCInitTypeStructure);
TIM_Cmd (TIM1,ENABLE);
TIM_CtrlPWMOutputs(TIM1, ENABLE);
}
void PWM_SET_H(uint32_t j)
{
TIM_OCInitTypeStructure.TIM_Pulse=0;
TIM_OC4Init(TIM1,&TIM_OCInitTypeStructure);
delay(10);
TIM_OCInitTypeStructure.TIM_Pulse=j;
TIM_OC2Init(TIM1,&TIM_OCInitTypeStructure);
TIM_Cmd (TIM1,ENABLE);
TIM_CtrlPWMOutputs(TIM1, ENABLE);
}
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
一周热门 更多>