用F28335写一个EPWM斩波程序
时间: 2023-10-11 11:11:54 浏览: 102
基于f28335的三相变频电路程序
5星 · 资源好评率100%
EPWM(Enhanced Pulse Width Modulation)是一种用于控制电机和其他电力设备的技术。下面是一个用F28335编写的基本EPWM斩波程序:
```
#include "DSP2833x_Device.h"
#include "DSP2833x_Examples.h"
void InitEPwm(void);
void main(void)
{
InitSysCtrl();
InitEPwm();
EINT; // Enable interrupts
while (1) {}
}
void InitEPwm(void)
{
EPwm1Regs.TBPRD = 375; // Set the period of the PWM signal
EPwm1Regs.TBCTL.bit.CTRMODE = TB_COUNT_UP; // Count up mode
EPwm1Regs.TBCTL.bit.PHSEN = TB_DISABLE; // Disable phase shift
EPwm1Regs.TBCTL.bit.HSPCLKDIV = TB_DIV1; // HSPCLK = SYSCLKOUT
EPwm1Regs.TBCTL.bit.CLKDIV = TB_DIV1; // TBCLK = HSPCLK
EPwm1Regs.CMPA.half.CMPA = 187; // Set the duty cycle of the PWM signal
EPwm1Regs.AQCTLA.bit.CAU = AQ_SET; // Set the PWM output on high
EPwm1Regs.AQCTLA.bit.ZRO = AQ_CLEAR; // Clear the PWM output on low
EPwm1Regs.ETSEL.bit.SOCAEN = 1; // Enable SOCA
EPwm1Regs.ETSEL.bit.SOCASEL = 1; // Select event that causes SOCA
EPwm1Regs.ETPS.bit.SOCAPRD = ET_1ST; // Generate SOCA on first event
}
```
此代码初始化了EPWM1,设置了PWM周期为375个时钟周期,设置了PWM占空比为50%(187 / 375),并在高电平上设置PWM输出。该代码还启用了SOCA(Start Of Conversion A)事件,该事件在PWM周期的开头生成,以帮助同步采样。请注意,此代码仅适用于EPWM1,如果需要使用其他EPWM模块,则需要相应地更改代码。
阅读全文