【双极性SPWM调制讲解以及基于stm32的代码生成-哔哩哔哩】 https://b23.tv/ytFxdkL
双极性spwm调制虽然没有单极性好用,但比单极性要简单易懂一些,以下教程是如何利用stm32实现双极性spwm调制.
怎么根据不同开关模式下的Uab值来输出连续的正弦波呢,我们先取几个特殊点分析。
•在正弦波峰值处,+VD宽度最大,因此T1,T4管此时的占空比达到最大,-VD宽度最小,因此T2,T3的最小,此时Uab为两者相减(因为2,3导通时为-VD),正好也是最大值。
在正弦波过0处, +VD宽度接近一半周期,因此T1,T4管此时的占空比约为一半, -VD也是,因此T2,T3的也是,此时Uab为两者相减(因为2,3导通时为-VD),正好也是过0。
•在正弦波谷值处, +VD宽度最小,因此T1,T4管此时的占空比达到最小, -VD宽度最大,因此T2,T3的最大,此时Uab为两者相减(因为2,3导通时为-VD),正好也是最小值。
这三种特殊点之间的变化过程,如果占空比是按正弦规律变化的,那么,不难理解,最终输出波形会是连续的正弦波形。
以上就是大致的原理。接下来就是代码的生成。
打开cubemx,选择芯片型号新建工程。
选择外部时钟并配置时钟树
接下来配置定时器1(也可以定时器8)pwm互补输出,这里选择通道一
频率为168M/(0+1)/(8399+1)=20KHZ;向上计数模式
配置死区和占空比;我这死区配的100多ns,大家根据实际需要配置
因为要以正弦规律改占空比,配置一个20khz的定时器中断
接下来就是工程命名,大家用英文路径。
生成工程转到keil。
文章来源地址https://www.toymoban.com/news/detail-611111.html
在合适位置加入下列代码
HAL_TIM_Base_Start_IT(&htim2);//开启定时器2中断
HAL_TIM_PWM_Start (&htim1,TIM_CHANNEL_1);//开启四路pwm波
HAL_TIMEx_PWMN_Start (&htim1,TIM_CHANNEL_1);
在合适位置复制以下代码,
uint16_t spwmcnt=0;//数组计数值:0~399;
float M=0.8;//调制比M:0~1
int spwm_group[400]={
33,99,165,231,297,362,428,494,559,624,690,755,819,884,948,1013,1076,
1140,1203,1266,1329,1392,1454,1515,1577,1638,1698,1758,1818,1877,1936,1994,2052,
2110,2166,2223,2278,2333,2388,2442,2495,2548,2600,2652,2703,2753,2802,2851,2899,
2946,2993,3039,3084,3129,3172,3215,3257,3298,3339,3378,3417,3455,3492,3528,3564,
3598,3632,3664,3696,3727,3757,3786,3814,3841,3868,3893,3917,3940,3963,3984,4005,
4024,4042,4060,4076,4092,4106,4119,4132,4143,4153,4163,4171,4178,4184,4190,4194,
4197,4199,4200,4200,4199,4197,4194,4190,4184,4178,4171,4163,4153,4143,4132,4119,
4106,4092,4076,4060,4042,4024,4005,3984,3963,3940,3917,3893,3868,3841,3814,3786,
3757,3727,3696,3664,3632,3598,3564,3528,3492,3455,3417,3378,3339,3298,3257,3215,
3172,3129,3084,3039,2993,2946,2899,2851,2802,2753,2703,2652,2600,2548,2495,2442,
2388,2333,2278,2223,2166,2110,2052,1994,1936,1877,1818,1758,1698,1638,1577,1515,
1454,1392,1329,1266,1203,1140,1076,1013,948,884,819,755,690,624,559,494,
428,362,297,231,165,99,33,-33,-99,-165,-231,-297,-362,-428,-494,-559,
-624,-690,-755,-819,-884,-948,-1013,-1076,-1140,-1203,-1266,-1329,-1392,-1454,-1515,-1577,
-1638,-1698,-1758,-1818,-1877,-1936,-1994,-2052,-2110,-2166,-2223,-2278,-2333,-2388,-2442,-2495,
-2548,-2600,-2652,-2703,-2753,-2802,-2851,-2899,-2946,-2993,-3039,-3084,-3129,-3172,-3215,-3257,
-3298,-3339,-3378,-3417,-3455,-3492,-3528,-3564,-3598,-3632,-3664,-3696,-3727,-3757,-3786,-3814,
-3841,-3868,-3893,-3917,-3940,-3963,-3984,-4005,-4024,-4042,-4060,-4076,-4092,-4106,-4119,-4132,
-4143,-4153,-4163,-4171,-4178,-4184,-4190,-4194,-4197,-4199,-4200,-4200,-4199,-4197,-4194,-4190,
-4184,-4178,-4171,-4163,-4153,-4143,-4132,-4119,-4106,-4092,-4076,-4060,-4042,-4024,-4005,-3984,
-3963,-3940,-3917,-3893,-3868,-3841,-3814,-3786,-3757,-3727,-3696,-3664,-3632,-3598,-3564,-3528,
-3492,-3455,-3417,-3378,-3339,-3298,-3257,-3215,-3172,-3129,-3084,-3039,-2993,-2946,-2899,-2851,
-2802,-2753,-2703,-2652,-2600,-2548,-2495,-2442,-2388,-2333,-2278,-2223,-2166,-2110,-2052,-1994,
-1936,-1877,-1818,-1758,-1698,-1638,-1577,-1515,-1454,-1392,-1329,-1266,-1203,-1140,-1076,-1013,
-948,-884,-819,-755,-690,-624,-559,-494,-428,-362,-297,-231,-165,-99,-33,
};
void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim) //中断回调函数 20k
{
if(htim==&htim2)
{
TIM1->CCR1 = 4200.f + M*spwm_group[spwmcnt] ;//20khz的频率改变400次,20000/400=50hz的正弦波;
spwmcnt++;
if(spwmcnt==400)spwmcnt=0;
}
}
编译,没有报错,可以正常使用。
其中T1,T4管由TIM1-CH1(PE9)驱动;
T2,T3管由TIM1-CH1N(PA7)驱动;
如何在上电路前检查自己的spwm对不对呢,首先可以把中断关了,固定占空比输出,用示波器看pwm波的频率对不对,互补两路间有没有合适的死区时间;无误后正常开启中断,准备两个合适且参数一样的RC滤波器,选择两路通道接上,并用示波器的两个通道同时看两个滤波器中电容两端波形,理论上CH1和CH1N为反相的50HZ正弦波。
如果有问题,欢迎留言交流,顺便把工程上传了,供大家下载(没有会员的就没必要特意开了哈)。
https://download.csdn.net/download/m0_65265936/86394301
文章来源:https://www.toymoban.com/news/detail-611111.html
到了这里,关于利用是stm32cubemx实现双极性spwm调制 基于stm32f407vet6的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!