STM32 PWM通过RC低通滤波转双极性SPWM测试

STM32 PWM通过RC低通滤波转双极性SPWM测试


双极性SPWM调制讲解以及基于stm32的代码生成

✨理论相关知识,可以参考上面的相关内容。本文只是对该功能进行验证。

  • 🌿测试硬件对象:STM32F427,不局限于型号,任意一个高级定时器都可以进行功能测试。

  • 🔖二阶低通滤波器参考电路:

  • 🌿TIM1高级定时器带死区时间控制参数的PWM互补输出波形:

  • 🌿死区时间:

  • 🌿经过二阶RC低通滤波后的波形。(橙色为PWM输入波形,红色为经过二阶RC滤波后的输出波形)

  • 🔰二阶RC滤波和一阶RC滤波波形对比

🛠STM32CubeMX工程配置

  • 🌿开启一路互补PWM输出。(具体频率参数可以根据需求自行配置)
  • 🌿死区时间设置:
  • 🌿另外配置一个20khz的定时器中断,用来根据正弦规律改占空比。(频率和上面的PWM频率参数一致)

📑业务代码

  • 🌿在main函数中开启定时器PWM输出。
c 复制代码
 /* USER CODE BEGIN 2 */
	HAL_TIM_Base_Start_IT(&htim2);//开启定时器2中断
	HAL_TIM_PWM_Start(&htim1,TIM_CHANNEL_1);//开启四路pwm波
	HAL_TIMEx_PWMN_Start(&htim1,TIM_CHANNEL_1);
  /* USER CODE END 2 */
  • 🌿在定时器2,中断回调函数中,注入定时器1的PWM通道计数器的的比较值:
c 复制代码
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;	
  }
}

📚工程源码

c 复制代码
链接:https://pan.baidu.com/s/1foLw5GocQhpzJVN_2qlLag?pwd=9r9x 
提取码:9r9x
相关推荐
打地基的小白10 小时前
软件I2C-基于江科大源码进行的原理解析和改造升级
stm32·单片机·嵌入式硬件·通信模式·i2c
Echo_cy_10 小时前
STM32 DMA+AD多通道
stm32·单片机·嵌入式硬件
朴人11 小时前
【从零开始实现stm32无刷电机FOC】【实践】【7.2/7 完整代码编写】
stm32·单片机·嵌入式硬件·foc
追梦少年时11 小时前
STM32中断——外部中断
stm32·单片机·嵌入式硬件
bai_lan_ya11 小时前
stm32定时器中断和外部中断
stm32·单片机·嵌入式硬件
玄奕子11 小时前
GPT对话知识库——在STM32的平台下,通过SPI读取和写入Flash的步骤。
stm32·单片机·gpt·嵌入式·嵌入式驱动
py.鸽鸽11 小时前
王者农药更新版
stm32
星汇极客12 小时前
【星汇极客】单片机竞赛之2024睿抗机器人大赛-火线速递赛道(持续更新)
stm32·单片机·嵌入式硬件·机器人
Daemon.Chen13 小时前
【STM32开发之寄存器版】(五)-窗口看门狗WWDG
stm32·单片机·嵌入式硬件
嵌入式杂谈15 小时前
STM32中断编程详解:配置外部中断和中断服务例程
stm32·单片机·嵌入式硬件