在做bldc驱动上希望用p+nmos也就是comos模式驱动,可以利用同步整流减少续流损耗,但在实现的过程中对于mos管和stm32对于pwm波形极性的设置不甚明白,希望高手指点一二,不胜感激。 6路pwm输出设置: /* Channel 1, 2,3 and 4 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 = ps; TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_High; TIM_OCInitStructure.TIM_OCNPolarity = TIM_OCNPolarity_High; TIM_OCInitStructure.TIM_OCIdleState = TIM_OCIdleState_Reset; TIM_OCInitStructure.TIM_OCNIdleState = TIM_OCNIdleState_Set; TIM_OC1Init(TIM1, &TIM_OCInitStructure); /* Automatic Output enable, Break, dead time and lock configuration*/ TIM_BDTRInitStructure.TIM_OSSRState = TIM_OSSRState_Enable; TIM_BDTRInitStructure.TIM_OSSIState = TIM_OSSIState_Enable; TIM_BDTRInitStructure.TIM_LOCKLevel = TIM_LOCKLevel_OFF; TIM_BDTRInitStructure.TIM_DeadTime = 1; TIM_BDTRInitStructure.TIM_Break = TIM_Break_Enable; TIM_BDTRInitStructure.TIM_BreakPolarity = TIM_BreakPolarity_Low; TIM_BDTRInitStructure.TIM_AutomaticOutput = TIM_AutomaticOutput_Enable; TIM_BDTRConfig(TIM1, &TIM_BDTRInitStructure); 6步换相操作: if (step == 1) { /* Next step: Step 2 Configuration ---------------------------- */ /* Channel1 configuration */ // TIM_SelectOCxM(TIM1, TIM_Channel_1, TIM_OCMode_PWM1); TIM_CCxCmd(TIM1, TIM_Channel_1, TIM_CCx_Enable); #if 0 TIM_CCxNCmd(TIM1, TIM_Channel_1, TIM_CCxN_Disable); /**OC1N=CC1NP,CC1NP=0下桥臂关*/ TIM_OC1NPolarityConfig(TIM1, TIM_OCNPolarity_High); #endif /* Channel2 configuration */ // TIM_SelectOCxM(TIM1, TIM_Channel_2, TIM_OCMode_PWM1 ); TIM_CCxCmd(TIM1, TIM_Channel_2, TIM_CCx_Disable); TIM_CCxNCmd(TIM1, TIM_Channel_2, TIM_CCxN_Disable); /*OC2N=CC2NP,CC2NP=1下桥臂开*/ TIM_OC2NPolarityConfig(TIM1, TIM_OCNPolarity_Low); /* Channel3 configuration */ TIM_CCxCmd(TIM1, TIM_Channel_3, TIM_CCx_Disable); TIM_CCxNCmd(TIM1, TIM_Channel_3, TIM_CCxN_Disable); /*OC3N=CC3NP,CC3NP=0下桥臂关*/ TIM_OC3NPolarityConfig(TIM1, TIM_OCNPolarity_High); step++; } else if (step == 2) { /* Next step: Step 3 Configuration ---------------------------- */ /* Channel1 configuration */ TIM_CCxCmd(TIM1, TIM_Channel_1, TIM_CCx_Disable); #if 0 TIM_CCxNCmd(TIM1, TIM_Channel_1, TIM_CCxN_Disable); /**OC1N=CC1NP,CC1NP=0下桥臂关*/ TIM_OC1NPolarityConfig(TIM1, TIM_OCNPolarity_High); #endif /* Channel2 configuration */ // TIM_SelectOCxM(TIM1, TIM_Channel_2, TIM_OCMode_PWM1); TIM_CCxCmd(TIM1, TIM_Channel_2, TIM_CCx_Disable); #if 0 TIM_CCxNCmd(TIM1, TIM_Channel_2, TIM_CCxN_Disable); /*OC2N=CC2NP,CC2NP=1下桥臂开*/ TIM_OC2NPolarityConfig(TIM1, TIM_OCNPolarity_Low); #endif /* Channel3 configuration */ // TIM_SelectOCxM(TIM1, TIM_Channel_3, TIM_OCMode_PWM1); TIM_CCxCmd(TIM1, TIM_Channel_3, TIM_CCx_Enable); #if 0 TIM_CCxNCmd(TIM1, TIM_Channel_3, TIM_CCxN_Disable); /*OC3N=CC3NP,CC3NP=0下桥臂关*/ TIM_OC3NPolarityConfig(TIM1, TIM_OCNPolarity_High); #endif step++; } else if (step == 3) { /* Next step: Step 4 Configuration ---------------------------- */ /* Channel1 configuration */ // TIM_SelectOCxM(TIM1, TIM_Channel_1, TIM_OCMode_PWM1); TIM_CCxCmd(TIM1, TIM_Channel_1, TIM_CCx_Disable); TIM_CCxNCmd(TIM1, TIM_Channel_1, TIM_CCxN_Disable); /*OC1N=CC1NP,CC1NP=1下桥臂开*/ TIM_OC1NPolarityConfig(TIM1, TIM_OCNPolarity_Low); /* Channel2 configuration */ TIM_CCxCmd(TIM1, TIM_Channel_2, TIM_CCx_Disable); TIM_CCxNCmd(TIM1, TIM_Channel_2, TIM_CCxN_Disable); /*OC2N=CC2NP,CC2NP=0下桥臂关*/ TIM_OC2NPolarityConfig(TIM1, TIM_OCNPolarity_High); /* Channel3 configuration */ // TIM_SelectOCxM(TIM1, TIM_Channel_3, TIM_OCMode_PWM1); TIM_CCxCmd(TIM1, TIM_Channel_3, TIM_CCx_Enable); #if 0 TIM_CCxNCmd(TIM1, TIM_Channel_3, TIM_CCxN_Disable); /*OC3N=CC3NP,CC3NP=0下桥臂关*/ TIM_OC3NPolarityConfig(TIM1, TIM_OCNPolarity_High); #endif step++; } else if (step == 4) { /* Next step: Step 5 Configuration ---------------------------- */ /* Channel1 configuration */ // TIM_SelectOCxM(TIM1, TIM_Channel_1, TIM_OCMode_PWM1); TIM_CCxCmd(TIM1, TIM_Channel_1, TIM_CCx_Disable); /*下桥臂常开*/ TIM_OC1NPolarityConfig(TIM1, TIM_OCNPolarity_Low); TIM_CCxNCmd(TIM1, TIM_Channel_1, TIM_CCxN_Disable); /* Channel2 configuration */ // TIM_SelectOCxM(TIM1, TIM_Channel_2, TIM_OCMode_PWM1); TIM_CCxCmd(TIM1, TIM_Channel_2, TIM_CCx_Enable); #if 0 TIM_CCxNCmd(TIM1, TIM_Channel_2, TIM_CCxN_Disable); /*OC2N=CC2NP,CC2NP=0下桥臂关*/ TIM_OC2NPolarityConfig(TIM1, TIM_OCNPolarity_High); #endif /* Channel3 configuration */ TIM_CCxCmd(TIM1, TIM_Channel_3, TIM_CCx_Disable); #if 0 TIM_CCxNCmd(TIM1, TIM_Channel_3, TIM_CCxN_Disable); /*OC3N=CC3NP,CC3NP=0下桥臂关*/ TIM_OC3NPolarityConfig(TIM1, TIM_OCNPolarity_High); #endif step++; } else if (step == 5) { /* Next step: Step 6 Configuration ---------------------------- */ /* Channel1 configuration */ TIM_CCxCmd(TIM1, TIM_Channel_1, TIM_CCx_Disable); TIM_CCxNCmd(TIM1, TIM_Channel_1, TIM_CCxN_Disable); /**OC1N=CC1NP,CC1NP=0下桥臂关*/ TIM_OC1NPolarityConfig(TIM1, TIM_OCNPolarity_High); /* Channel2 configuration */ // TIM_SelectOCxM(TIM1, TIM_Channel_2, TIM_OCMode_PWM1); TIM_CCxCmd(TIM1, TIM_Channel_2, TIM_CCx_Enable); #if 0 TIM_CCxNCmd(TIM1, TIM_Channel_2, TIM_CCxN_Disable); /*OC2N=CC2NP,CC2NP=0下桥臂常关*/ TIM_OC2NPolarityConfig(TIM1, TIM_OCNPolarity_High); #endif /* Channel3 configuration */ // TIM_SelectOCxM(TIM1, TIM_Channel_3, TIM_OCMode_PWM1); TIM_CCxCmd(TIM1, TIM_Channel_3, TIM_CCx_Disable); TIM_CCxNCmd(TIM1, TIM_Channel_3, TIM_CCxN_Disable); /*OC3N=CC3NP,CC3NP=1下桥臂开*/ TIM_OC3NPolarityConfig(TIM1, TIM_OCNPolarity_Low); step++; } else { /* Next step: Step 1 Configuration ---------------------------- */ /* Channel1 configuration */ // TIM_SelectOCxM(TIM1, TIM_Channel_1, TIM_OCMode_PWM1); TIM_CCxCmd(TIM1, TIM_Channel_1, TIM_CCx_Enable); #if 0 TIM_CCxNCmd(TIM1, TIM_Channel_1, TIM_CCxN_Disable); /**OC1N=CC1NP,CC1NP=0下桥臂关*/ TIM_OC1NPolarityConfig(TIM1, TIM_OCNPolarity_High); #endif /* Channel2 configuration */ TIM_CCxCmd(TIM1, TIM_Channel_2, TIM_CCx_Disable); #if 0 TIM_CCxNCmd(TIM1, TIM_Channel_2, TIM_CCxN_Disable); /*OC2N=CC2NP,CC2NP=0下桥臂关*/ TIM_OC2NPolarityConfig(TIM1, TIM_OCNPolarity_High); #endif /* Channel3 configuration */ // TIM_SelectOCxM(TIM1, TIM_Channel_3, TIM_OCMode_PWM1); TIM_CCxCmd(TIM1, TIM_Channel_3, TIM_CCx_Disable); TIM_CCxNCmd(TIM1, TIM_Channel_3, TIM_CCxN_Disable); /*OC3N=CC3NP,CC3NP=1下桥臂开*/ TIM_OC3NPolarityConfig(TIM1, TIM_OCNPolarity_Low); step = 1; 请问其中: 1.同步整流是怎么实现的? 2. TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_High; TIM_OCInitStructure.TIM_OCNPolarity = TIM_OCNPolarity_High; TIM_OCInitStructure.TIM_OCIdleState = TIM_OCIdleState_Reset; TIM_OCInitStructure.TIM_OCNIdleState = TIM_OCNIdleState_Set; 这四句分别实现什么功能? 3.TIM_OC1NPolarityConfig(TIM1, TIM_OCNPolarity_High); 该句是为了设置pwm互补通道的输出极性,这里面的high和low分别代表什么意思?是输出1和0的意思吗,还是输出1导通和0导通? 4.对于pmos管和nmos管导通原理自然不一样,是相反的,在程序里怎么体现呢?打比方来讲对于3通道: TIM_CCxCmd(TIM1, TIM_Channel_3, TIM_CCx_Disable); TIM_CCxNCmd(TIM1, TIM_Channel_3, TIM_CCxN_Disable); 若上桥为pmos,下桥为nmos,上述2句是不是导通其中的一桥,而另一桥关断?那哪个导通哪个关断呢?关于这个极性的设置好头大啊,望大神不吝详细指点一二! |