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
相关推荐
不过四级不改名6772 小时前
蓝桥杯嵌入式备赛教程(1、led,2、lcd,3、key)
stm32·嵌入式硬件·蓝桥杯
小A1593 小时前
STM32完全学习——SPI接口的FLASH(DMA模式)
stm32·嵌入式硬件·学习
超级码农ProMax6 小时前
STM32——“SPI Flash”
stm32·单片机·嵌入式硬件
Asa3197 小时前
stm32点灯Hal库
stm32·单片机·嵌入式硬件
end_SJ8 小时前
初学stm32 --- 外部中断
stm32·单片机·嵌入式硬件
嵌入式小强工作室10 小时前
stm32 查找进硬件错误方法
stm32·单片机·嵌入式硬件
wenchm11 小时前
细说STM32F407单片机DMA方式读写SPI FLASH W25Q16BV
stm32·单片机·嵌入式硬件
逝灮11 小时前
【蓝桥杯——物联网设计与开发】拓展模块4 - 脉冲模块
stm32·单片机·嵌入式硬件·mcu·物联网·蓝桥杯·脉冲测量
云山工作室11 小时前
基于单片机的电梯声控系统设计(论文+源码)
stm32·单片机·嵌入式硬件·毕业设计·毕设
Asa31914 小时前
STM32-按键扫描配置
stm32·单片机·嵌入式硬件