做一个驱动IGBT的项目,需要一组对称且占空比不超过50%(主要是留死区出来),现在使用TIME2 channel3 ,channel4两个通道输出PWM, 采用中央对齐的方式,波形大体出来了,只是有两个问题出现。1:利用逻辑窗口观察第一个PWM周期不对,重复几次会出现下图两种情况。重启再观察有可能出现图2的情况。2:逻辑分析窗口波形不会自动变化,必须鼠标动一下一下窗口才行,经常出现这种情况,不知道如何设置。
求助!不知道原子君和诸位大神能否指点一二。
[mw_shl_code=applescript,true]void TIM2_PWM_Init(u16 arr,u16 psc)
{
GPIO_InitTypeDef GPIO_InitStructure;
TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;
TIM_OCInitTypeDef TIM_OCInitStructure;
RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM2, ENABLE);
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA , ENABLE);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOA, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_3;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOA, &GPIO_InitStructure);
TIM_TimeBaseStructure.TIM_Period = arr;
TIM_TimeBaseStructure.TIM_Prescaler =psc;
TIM_TimeBaseStructure.TIM_ClockDivision = 0;
TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_CenterAligned1;
TIM_TimeBaseInit(TIM2, &TIM_TimeBaseStructure);
TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_PWM1;
TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable;
TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_High;
TIM_OCInitStructure.TIM_Pulse = 0;
TIM_OC3Init(TIM2, &TIM_OCInitStructure);
TIM_OC3PreloadConfig(TIM2, TIM_OCPreload_Enable);
TIM_OCInitStructure.TIM_OCMode=TIM_OCMode_PWM1; //éèÖÃÎaPWM1êä3öÄ£ê½
TIM_OCInitStructure.TIM_OutputState=TIM_OutputState_Enable; //ê1Äü¸Ãí¨μ
TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_Low; //TIM_OCPolarity_Low
TIM_OCInitStructure.TIM_Pulse=0;
TIM_OC4Init(TIM2,&TIM_OCInitStructure); //°′ÕÕÖ¸¶¨2Îêy3õê¼»ˉ
TIM_OC4PreloadConfig(TIM2, TIM_OCPreload_Enable); //Ôê1ÄüTIMxÔúCCR1ԤװÔú¼Ä′æÆ÷
TIM_CtrlPWMOutputs(TIM2,ENABLE);
TIM_ARRPreloadConfig(TIM2, ENABLE);
TIM_Cmd(TIM2, ENABLE);
}
[/mw_shl_code]
主程序[mw_shl_code=applescript,true]int main(void)
{
delay_init();
LED_Init(); //3õê¼»ˉóëLEDᬽóμÄó2¼t½ó¿ú
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2); //éèÖÃNVICÖD¶Ï·Ö×é2:2λÇàÕ¼óÅÏ輶£¬2λÏìó|óÅÏ輶
uart_init(115200); //′®¿ú3õê¼»ˉÎa115200
TIM2_PWM_Init(99,179);
TIM_SetCompare3(TIM2,40);
TIM_SetCompare4(TIM2,60);
while(1)
{
}
}
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
之前使用过TIM1死区功能,但由于STM32机制的原因两个对称的PWM,占空比并不相同,那么实际运用中可能存在正负电流不平衡的问题。同样非常感谢您。
一周热门 更多>