利用 ePWM模块编写三相全桥道交电路的发波程序,载波频4 10Khz
时间: 2024-03-21 15:38:31 浏览: 167
好的,我理解了你的问题。下面是一个基于 ePWM 模块编写的三相全桥道交电路的发波程序,载波频率为 4 10KHz。
```c
#include "F28x_Project.h"
#define PWM_PERIOD 2000 // PWM 周期长度
#define DEAD_TIME 50 // 死区时间长度
void setup_ePWM(void);
void main(void)
{
// 初始化系统配置
InitSysCtrl();
// 配置 ePWM 模块
setup_ePWM();
while (1) {
// 主循环
}
}
void setup_ePWM(void)
{
// 配置 GPIO 口
GPIO_SetupPinOptions(0, GPIO_OUTPUT, GPIO_ASYNC);
GPIO_SetupPinOptions(1, GPIO_OUTPUT, GPIO_ASYNC);
GPIO_SetupPinOptions(2, GPIO_OUTPUT, GPIO_ASYNC);
GPIO_SetupPinOptions(3, GPIO_OUTPUT, GPIO_ASYNC);
// 配置 ePWM 模块的时钟源
CpuSysRegs.PCLKCR2.bit.EPWM1 = 1;
CpuSysRegs.PCLKCR0.bit.TBCLKSYNC = 0;
// 配置 ePWM1 模块的计数器
EPwm1Regs.TBCTL.bit.CTRMODE = TB_COUNT_UPDOWN;
EPwm1Regs.TBCTL.bit.PHSEN = TB_DISABLE;
EPwm1Regs.TBCTL.bit.PRDLD = TB_SHADOW;
EPwm1Regs.TBPRD = PWM_PERIOD;
EPwm1Regs.TBPHS.half.TBPHS = 0;
EPwm1Regs.TBCTR = 0;
// 配置 ePWM1 模块的计数器时钟分频
EPwm1Regs.TBCTL.bit.HSPCLKDIV = TB_DIV1;
EPwm1Regs.TBCTL.bit.CLKDIV = TB_DIV1;
// 配置 ePWM1 模块的 A/B 相
EPwm1Regs.AQCTLA.bit.CAU = AQ_CLEAR;
EPwm1Regs.AQCTLA.bit.CAD = AQ_SET;
EPwm1Regs.AQCTLB.bit.CBU = AQ_CLEAR;
EPwm1Regs.AQCTLB.bit.CBD = AQ_SET;
// 配置 ePWM2 模块
EPwm2Regs.TBCTL.bit.CTRMODE = TB_COUNT_UPDOWN;
EPwm2Regs.TBCTL.bit.PHSEN = TB_DISABLE;
EPwm2Regs.TBCTL.bit.PRDLD = TB_SHADOW;
EPwm2Regs.TBPRD = PWM_PERIOD;
EPwm2Regs.TBPHS.half.TBPHS = PWM_PERIOD / 3;
EPwm2Regs.TBCTR = 0;
EPwm2Regs.TBCTL.bit.HSPCLKDIV = TB_DIV1;
EPwm2Regs.TBCTL.bit.CLKDIV = TB_DIV1;
EPwm2Regs.AQCTLA.bit.CAU = AQ_SET;
EPwm2Regs.AQCTLA.bit.CAD = AQ_CLEAR;
EPwm2Regs.AQCTLB.bit.CBU = AQ_SET;
EPwm2Regs.AQCTLB.bit.CBD = AQ_CLEAR;
// 配置 ePWM3 模块
EPwm3Regs.TBCTL.bit.CTRMODE = TB_COUNT_UPDOWN;
EPwm3Regs.TBCTL.bit.PHSEN = TB_DISABLE;
EPwm3Regs.TBCTL.bit.PRDLD = TB_SHADOW;
EPwm3Regs.TBPRD = PWM_PERIOD;
EPwm3Regs.TBPHS.half.TBPHS = PWM_PERIOD * 2 / 3;
EPwm3Regs.TBCTR = 0;
EPwm3Regs.TBCTL.bit.HSPCLKDIV = TB_DIV1;
EPwm3Regs.TBCTL.bit.CLKDIV = TB_DIV1;
EPwm3Regs.AQCTLA.bit.CAU = AQ_CLEAR;
EPwm3Regs.AQCTLA.bit.CAD = AQ_SET;
EPwm3Regs.AQCTLB.bit.CBU = AQ_CLEAR;
EPwm3Regs.AQCTLB.bit.CBD = AQ_SET;
// 配置死区时间
EPwm1Regs.DBCTL.bit.OUT_MODE = DB_FULL_ENABLE;
EPwm1Regs.DBCTL.bit.POLSEL = DB_ACTV_HIC;
EPwm1Regs.DBCTL.bit.IN_MODE = DBA_ALL;
EPwm1Regs.DBRED = DEAD_TIME;
EPwm1Regs.DBFED = DEAD_TIME;
EPwm2Regs.DBCTL.bit.OUT_MODE = DB_FULL_ENABLE;
EPwm2Regs.DBCTL.bit.POLSEL = DB_ACTV_HIC;
EPwm2Regs.DBCTL.bit.IN_MODE = DBA_ALL;
EPwm2Regs.DBRED = DEAD_TIME;
EPwm2Regs.DBFED = DEAD_TIME;
EPwm3Regs.DBCTL.bit.OUT_MODE = DB_FULL_ENABLE;
EPwm3Regs.DBCTL.bit.POLSEL = DB_ACTV_HIC;
EPwm3Regs.DBCTL.bit.IN_MODE = DBA_ALL;
EPwm3Regs.DBRED = DEAD_TIME;
EPwm3Regs.DBFED = DEAD_TIME;
// 启用 ePWM1、ePWM2、ePWM3 模块
EPwm1Regs.TBCTL.bit.CTRMODE = TB_COUNT_UPDOWN;
EPwm2Regs.TBCTL.bit.CTRMODE = TB_COUNT_UPDOWN;
EPwm3Regs.TBCTL.bit.CTRMODE = TB_COUNT_UPDOWN;
CpuSysRegs.PCLKCR0.bit.TBCLKSYNC = 1;
}
```
需要注意的是,上面的程序只是一个基础的参考框架,你需要根据具体的需求进行修改和优化。同时,还需要根据具体的硬件平台进行适配和调试。
阅读全文