完善资料让更多小伙伴认识你,还能领取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句是不是导通其中的一桥,而另一桥关断?那哪个导通哪个关断呢?关于这个极性的设置好头大啊,望大神不吝详细指点一二! |
|
相关推荐
1个回答
|
|
在您的问题中,您提到了使用STM32的Timer16来实现6路PWM输出,并且希望使用P+NMOS(互补MOS)模式来驱动BLDC电机。在这种模式下,您可以利用同步整流来减少续流损耗。为了实现这个目标,您需要正确设置PWM波形的极性。
首先,让我们了解一下STM32的Timer16和PWM输出的相关概念: 1. Timer16是一个16位定时器,可以用于产生PWM波形。 2. PWM(脉冲宽度调制)是一种调制技术,通过调整脉冲的宽度来控制信号的平均值。 3. P+NMOS驱动模式是指使用一个PMOS(正极性MOSFET)和一个NMOS(负极性MOSFET)来驱动电机。 在STM32中,您可以通过配置TIM_OCInitStructure结构体来设置PWM输出的参数。以下是一些关键参数的解释: - TIM_OCMode:PWM模式,您已经设置为TIM_OCMode_PWM1。 - TIM_OutputState:输出状态,您已经设置为TIM_OutputState_Enable,表示输出使能。 - TIM_OutputNState:互补输出状态,您已经设置为TIM_OutputNState_Enable,表示互补输出使能。 为了实现P+NMOS驱动模式,您需要确保PWM波形的极性正确。在STM32中,您可以通过设置TIM_OCPolarity和TIM_OCNPolarity来实现这一点: ```c TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_High; TIM_OCInitStructure.TIM_OCNPolarity = TIM_OCNPolarity_Low; ``` 这里,TIM_OCPolarity设置为主输出的极性,而TIM_OCNPolarity设置为互补输出的极性。通过这样设置,当PWM波形的主输出为高电平时,互补输出为低电平,反之亦然。这将允许PMOS和NMOS互补工作,从而实现同步整流。 在您的代码中,您需要添加这两行设置极性的代码。然后,您可以继续配置其他参数,如TIM_Pulse等,以满足您的具体需求。 最后,不要忘记初始化定时器和PWM通道,以及启动定时器: ```c TIM_TimeBaseInit(TIMx); // 初始化定时器 TIM_OCxInit(TIMx, &TIM_OCInitStructure); // 初始化PWM通道 TIM_Cmd(TIMx, ENABLE); // 启动定时器 ``` 希望这些信息能帮助您实现P+NMOS驱动模式下的BLDC电机驱动。如果您有任何疑问或需要进一步的帮助,请随时提问。 |
|
|
|
只有小组成员才能发言,加入小组>>
调试STM32H750的FMC总线读写PSRAM遇到的问题求解?
1659 浏览 1 评论
X-NUCLEO-IHM08M1板文档中输出电流为15Arms,15Arms是怎么得出来的呢?
1571 浏览 1 评论
998 浏览 2 评论
STM32F030F4 HSI时钟温度测试过不去是怎么回事?
695 浏览 2 评论
ST25R3916能否对ISO15693的标签芯片进行分区域写密码?
1617 浏览 2 评论
1878浏览 9评论
STM32仿真器是选择ST-LINK还是选择J-LINK?各有什么优势啊?
665浏览 4评论
STM32F0_TIM2输出pwm2后OLED变暗或者系统重启是怎么回事?
530浏览 3评论
548浏览 3评论
stm32cubemx生成mdk-arm v4项目文件无法打开是什么原因导致的?
517浏览 3评论
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2024-11-30 19:10 , Processed in 0.908345 second(s), Total 49, Slave 42 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号