用一个TIM发相位相差180度、占空比小于50%的两路PWM用于驱动推挽变换器,但是每次复位之后都会有一个脉冲,不知道是怎么来的。如图 这个是软启动时的 还有启动时没有开TIM时的波形 我的配置如下 void TIM4_Configuration(void) { TIM_TimeBaseInitTypeDef TIM_TBInitStructure; TIM_OCInitTypeDef TIM_OCInitStructure; uint16_t PrescalerValue = 0; PrescalerValue = (uint16_t) (SystemCoreClock / 24000000) - 1; RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM4, ENABLE); TIM_TBInitStructure.TIM_ClockDivision = TIM_CKD_DIV1; TIM_TBInitStructure.TIM_CounterMode = TIM_CounterMode_CenterAligned1; TIM_TBInitStructure.TIM_Period = 1200; //10kHz Equal to 20kHz for push-pull TIM_TBInitStructure.TIM_Prescaler = PrescalerValue; TIM_TBInitStructure.TIM_RepetitionCounter = 1; TIM_TimeBaseInit(TIM4, &TIM_TBInitStructure); TIM_PrescalerConfig(TIM4, PrescalerValue, TIM_PSCReloadMode_Immediate); TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_PWM1; TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable; TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_High; TIM_OCInitStructure.TIM_OCIdleState = TIM_OCIdleState_Reset; TIM_OCInitStructure.TIM_Pulse = 60; TIM_OC3Init(TIM4, &TIM_OCInitStructure); TIM_OC3PreloadConfig(TIM4, TIM_OCPreload_Enable); TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_PWM2; TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable; TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_High; TIM_OCInitStructure.TIM_OCIdleState = TIM_OCIdleState_Reset; TIM_OCInitStructure.TIM_Pulse = 1140; TIM_OC4Init(TIM4, &TIM_OCInitStructure); TIM_OC4PreloadConfig(TIM4, TIM_OCPreload_Enable); TIM_ARRPreloadConfig(TIM4, ENABLE); TIM_SetCounter(TIM4, 600); TIM_ClearFlag(TIM4, TIM_FLAG_CC3| TIM_FLAG_CC4); TIM_ITConfig(TIM4, TIM_IT_CC4, ENABLE); TIM_Cmd(TIM4, ENABLE); } 是配置有问题么?怎么才能解决呢?谢谢各位啦! |
RE:stm32f103发PWM遇到问题,求帮助
回复:stm32f103发PWM遇到问题,求帮助
看配置没有问题,建议仿真一下配置过程,到底是看看是哪儿引起的脉冲输出。
问题已解决,只要将timer寄存器赋600那句放在配置OC寄存器之前就行了。谢谢您的建议!