写一个基于tms320f28355的三相逆变程序
时间: 2023-09-18 07:11:20 浏览: 260
以下是一个基于tms320f28355的三相逆变程序的示例代码。这个程序可以控制一个三相逆变器,将直流电压转换为交流电压。
```c
#include "DSP2833x_Device.h"
#include "DSP2833x_Examples.h"
#define PWM_PERIOD 4500
#pragma CODE_SECTION(epwm1_isr, "ramfuncs");
Uint16 CMPA1, CMPA2, CMPA3;
interrupt void epwm1_isr(void)
{
EPwm1Regs.CMPA.half.CMPA = CMPA1;
EPwm2Regs.CMPA.half.CMPA = CMPA2;
EPwm3Regs.CMPA.half.CMPA = CMPA3;
EPwm1Regs.ETCLR.bit.INT = 1;
PieCtrlRegs.PIEACK.all = PIEACK_GROUP3;
}
void InitEPwm()
{
EALLOW;
CpuSysRegs.PCLKCR2.bit.EPWM1 = 1;
CpuSysRegs.PCLKCR2.bit.EPWM2 = 1;
CpuSysRegs.PCLKCR2.bit.EPWM3 = 1;
EDIS;
EPwm1Regs.TBCTL.bit.PRDLD = TB_IMMEDIATE;
EPwm1Regs.TBPRD = PWM_PERIOD;
EPwm1Regs.TBCTL.bit.CTRMODE = TB_COUNT_UPDOWN;
EPwm1Regs.TBCTL.bit.PHSEN = TB_DISABLE;
EPwm1Regs.TBCTL.bit.SYNCOSEL = TB_CTR_ZERO;
EPwm1Regs.CMPCTL.bit.SHDWAMODE = CC_SHADOW;
EPwm1Regs.CMPCTL.bit.LOADAMODE = CC_CTR_ZERO;
EPwm1Regs.CMPA.half.CMPA = 0;
EPwm1Regs.AQCTLA.bit.CAU = AQ_SET;
EPwm1Regs.AQCTLA.bit.CAD = AQ_CLEAR;
EPwm2Regs.TBCTL.bit.PRDLD = TB_IMMEDIATE;
EPwm2Regs.TBPRD = PWM_PERIOD;
EPwm2Regs.TBCTL.bit.CTRMODE = TB_COUNT_UPDOWN;
EPwm2Regs.TBCTL.bit.PHSEN = TB_DISABLE;
EPwm2Regs.TBCTL.bit.SYNCOSEL = TB_SYNC_IN;
EPwm2Regs.CMPCTL.bit.SHDWAMODE = CC_SHADOW;
EPwm2Regs.CMPCTL.bit.LOADAMODE = CC_CTR_ZERO;
EPwm2Regs.CMPA.half.CMPA = 0;
EPwm2Regs.AQCTLA.bit.CAU = AQ_SET;
EPwm2Regs.AQCTLA.bit.CAD = AQ_CLEAR;
EPwm3Regs.TBCTL.bit.PRDLD = TB_IMMEDIATE;
EPwm3Regs.TBPRD = PWM_PERIOD;
EPwm3Regs.TBCTL.bit.CTRMODE = TB_COUNT_UPDOWN;
EPwm3Regs.TBCTL.bit.PHSEN = TB_DISABLE;
EPwm3Regs.TBCTL.bit.SYNCOSEL = TB_SYNC_IN;
EPwm3Regs.CMPCTL.bit.SHDWAMODE = CC_SHADOW;
EPwm3Regs.CMPCTL.bit.LOADAMODE = CC_CTR_ZERO;
EPwm3Regs.CMPA.half.CMPA = 0;
EPwm3Regs.AQCTLA.bit.CAU = AQ_SET;
EPwm3Regs.AQCTLA.bit.CAD = AQ_CLEAR;
EPwm1Regs.ETSEL.bit.INTSEL = ET_CTR_ZERO;
EPwm1Regs.ETSEL.bit.INTEN = 1;
EPwm1Regs.ETPS.bit.INTPRD = ET_1ST;
}
void SetPWM(float Vdc, float Va, float Vb, float Vc)
{
CMPA1 = (Uint16)((Vdc / 2 + Va) / Vdc * PWM_PERIOD);
CMPA2 = (Uint16)((Vdc / 2 + Vb) / Vdc * PWM_PERIOD);
CMPA3 = (Uint16)((Vdc / 2 + Vc) / Vdc * PWM_PERIOD);
}
void main()
{
InitEPwm();
SetPWM(100, 50, 0, 50); // 100V DC, 50V AC on phase A, 50V AC on phase C
while (1) {}
}
```
这个程序使用了 DSP2833x 库中的 EPWM 模块来生成三相逆变器的 PWM 信号。在 `InitEPwm` 函数中,我们对 EPWM1,EPWM2 和 EPWM3 进行了初始化,并设置了 PWM 信号的周期为 4500 个时钟周期。在 `SetPWM` 函数中,我们计算出了三个 PWM 信号的占空比,然后分别设置了 CMPA1,CMPA2 和 CMPA3 寄存器的值。在 `main` 函数中,我们调用 `SetPWM` 函数来设置 PWM 信号的占空比,然后程序进入一个无限循环。
当程序运行时,EPWM 模块会生成三个 PWM 信号,这些信号将被用于控制三相逆变器的输出。三个 PWM 信号的占空比可以通过调用 `SetPWM` 函数进行设置。在示例代码中,我们设置了一个 100V 的直流电压,并将其中 50V 的交流电压分别施加在 A 相和 C 相上,从而产生了一个相位差为 120 度的三相交流输出。
阅读全文