完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
扫一扫,分享给好友
在做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句是不是导通其中的一桥,而另一桥关断?那哪个导通哪个关断呢?关于这个极性的设置好头大啊,望大神不吝详细指点一二! |
|
相关推荐 |
|
你正在撰写答案
如果你是对答案或其他答案精选点评或询问,请使用“评论”功能。
316 浏览 0 评论
AD7686芯片不传输数据给STM32,但是手按住就会有数据。
834 浏览 2 评论
1996 浏览 0 评论
如何解决MPU-9250与STM32通讯时,出现HAL_ERROR = 0x01U
1099 浏览 1 评论
hal库中i2c卡死在HAL_I2C_Master_Transmit
1525 浏览 1 评论
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2024-11-20 03:33 , Processed in 0.877535 second(s), Total 71, Slave 55 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号