帮我写一个利用F28335编程产生应用不对称规则采样法生成的对称三相SPWM波的代码
时间: 2023-03-31 20:01:51 浏览: 214
采用不对称采样计算SPWM波生成
好的,我可以回答这个问题。以下是利用F28335编程产生应用不对称规则采样法生成的对称三相SPWM波的代码:
```
#include <DSP2833x_Device.h>
#include <DSP2833x_Examples.h>
#define PWM_PERIOD 500 // PWM周期为500个计数器时钟周期
#define PWM_DEADBAND 100 // 死区时间为100个计数器时钟周期
Uint16 pwm1, pwm2, pwm3; // 三相PWM占空比
Uint16 pwm_deadband = PWM_DEADBAND / 2; // 死区时间的一半
void main(void)
{
InitSysCtrl(); // 初始化系统时钟
InitPieCtrl(); // 初始化PIE中断控制器
InitPieVectTable(); // 初始化PIE中断向量表
EALLOW;
PieVectTable.EPWM1_INT = &EPWM1_ISR; // 将EPWM1中断向量表指向EPWM1_ISR函数
EDIS;
InitEPwm1(); // 初始化EPWM1
IER |= M_INT3; // 使能EPWM1中断
EINT; // 使能全局中断
while(1)
{
// 产生对称三相SPWM波
pwm1 = (Uint16)(PWM_PERIOD / 2 * (1 + sin(2 * PI * 1 / 3)));
pwm2 = (Uint16)(PWM_PERIOD / 2 * (1 + sin(2 * PI * 2 / 3)));
pwm3 = (Uint16)(PWM_PERIOD / 2 * (1 + sin(2 * PI * 3 / 3)));
// 更新EPWM1的占空比
EPwm1Regs.CMPA.half.CMPA = pwm1;
EPwm1Regs.CMPB = pwm2;
EPwm1Regs.CMPC = pwm3;
}
}
void InitEPwm1(void)
{
EALLOW;
// 配置GPIO引脚为EPWM1输出
GpioCtrlRegs.GPAMUX1.bit.GPIO = 1;
GpioCtrlRegs.GPAMUX1.bit.GPIO1 = 1;
GpioCtrlRegs.GPAMUX1.bit.GPIO2 = 1;
// 配置EPWM1计数器时钟
EPwm1Regs.TBCTL.bit.CTRMODE = TB_COUNT_UPDOWN;
EPwm1Regs.TBCTL.bit.PHSEN = TB_DISABLE;
EPwm1Regs.TBCTL.bit.HSPCLKDIV = TB_DIV1;
EPwm1Regs.TBCTL.bit.CLKDIV = TB_DIV1;
// 配置EPWM1计数器周期
EPwm1Regs.TBPRD = PWM_PERIOD;
// 配置EPWM1的死区时间
EPwm1Regs.DBCTL.bit.OUT_MODE = DB_FULL_ENABLE;
EPwm1Regs.DBCTL.bit.POLSEL = DB_ACTV_HIC;
EPwm1Regs.DBCTL.bit.IN_MODE = DBA_ALL;
EPwm1Regs.DBRED = pwm_deadband;
EPwm1Regs.DBFED = pwm_deadband;
// 配置EPWM1的占空比
EPwm1Regs.CMPA.half.CMPA = ;
EPwm1Regs.CMPB = ;
EPwm1Regs.CMPC = ;
// 配置EPWM1的动态比较模式
EPwm1Regs.AQCTLA.bit.CAU = AQ_SET;
EPwm1Regs.AQCTLA.bit.CAD = AQ_CLEAR;
EPwm1Regs.AQCTLB.bit.CBU = AQ_SET;
EPwm1Regs.AQCTLB.bit.CBD = AQ_CLEAR;
EPwm1Regs.AQCTLC.bit.CCU = AQ_SET;
EPwm1Regs.AQCTLC.bit.CCD = AQ_CLEAR;
// 配置EPWM1的中断
EPwm1Regs.ETSEL.bit.INTSEL = ET_CTR_ZERO;
EPwm1Regs.ETSEL.bit.INTEN = 1;
EPwm1Regs.ETPS.bit.INTPRD = ET_1ST;
EDIS;
}
interrupt void EPWM1_ISR(void)
{
// 清除EPWM1中断标志位
EPwm1Regs.ETCLR.bit.INT = 1;
// 更新EPWM1的占空比
EPwm1Regs.CMPA.half.CMPA = pwm1;
EPwm1Regs.CMPB = pwm2;
EPwm1Regs.CMPC = pwm3;
}
```
阅读全文