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
相关推荐
scan18 小时前
单片机串口接收状态机STM32
stm32·单片机·串口·51·串口接收
Mortal_hhh10 小时前
VScode的C/C++点击转到定义,不是跳转定义而是跳转声明怎么办?(内附详细做法)
ide·vscode·stm32·编辑器
Mr.谢尔比11 小时前
电赛入门之软件stm32keil+cubemx
stm32·单片机·嵌入式硬件·mcu·信息与通信·信号处理
LightningJie11 小时前
STM32中ARR(自动重装寄存器)为什么要减1
stm32·单片机·嵌入式硬件
鹿屿二向箔11 小时前
STM32外设之SPI的介绍
stm32
西瓜籽@12 小时前
STM32——毕设基于单片机的多功能节能窗控制系统
stm32·单片机·课程设计
极客小张15 小时前
基于STM32的智能充电桩:集成RTOS、MQTT与SQLite的先进管理系统设计思路
stm32·单片机·嵌入式硬件·mqtt·sqlite·毕业设计·智能充电桩
m0_7393128718 小时前
【STM32】项目实战——OV7725/OV2604摄像头颜色识别检测(开源)
stm32·单片机·嵌入式硬件
嵌入式小章18 小时前
基于STM32的实时时钟(RTC)教学
stm32·嵌入式硬件·实时音视频
徐嵌19 小时前
STM32项目---水质水位检测
stm32·单片机·嵌入式硬件