- UID
- 373967
- 帖子
- 8982
- 主題
- 2609
- 精華
- 0
- 積分
- 1003
- 楓幣
- 28
- 威望
- 980
- 存款
- 35699
- 贊助金額
- 0
- 推廣
- 0
- GP
- 1205
- 閱讀權限
- 70
- 在線時間
- 459 小時
- 註冊時間
- 2023-1-12
- 最後登入
- 2024-12-18
|
TMS320F28xx 88太陽能逆變器的程式碼,這個程式碼是一個基本的參考,需要根據具體的硬件設置進行修改:
#include <stdint.h>
#include "DSP28x_Project.h"
#define PWM_FREQUENCY 1000
#define EPWM1_TIMER_TBPRD 1875 // PWM period, 75MHz / 1875 = 40kHz
#define EPWM1_TIMER_CMPA 937 // 50% duty cycle
#define EPWM1_TIMER_CMPB 1875 // 100% duty cycle
void main(void)
{
InitSysCtrl();
InitPieCtrl();
IER = 0x0000;
IFR = 0x0000;
InitPieVectTable();
EALLOW;
PieVectTable.EPWM1_INT = &epwm1_isr;
EDIS;
InitEPwm();
IER |= M_INT3;
EINT;
ERTM;
while(1);
}
interrupt void epwm1_isr(void)
{
EPwm1Regs.ETCLR.bit.INT = 1;
}
void InitEPwm()
{
EALLOW;
CpuSysRegs.PCLKCR0.bit.TBCLKSYNC = 0;
CpuSysRegs.PCLKCR0.bit.GTBCLKSYNC = 0;
EPwm1Regs.TBCTL.bit.CTRMODE = 0x3;
EPwm1Regs.TBCTL.bit.SYNCOSEL = 0x2;
EPwm1Regs.TBPRD = EPWM1_TIMER_TBPRD;
EPwm1Regs.TBPHS.half.TBPHS = 0x0000;
EPwm1Regs.CMPA.half.CMPA = EPWM1_TIMER_CMPA;
EPwm1Regs.CMPB = EPWM1_TIMER_CMPB;
EPwm1Regs.TBCTL.bit.PHSEN = 0x0;
EPwm1Regs.TBCTL.bit.PRDLD = 0x1;
EPwm1Regs.TBCTR = 0x0000;
EPwm1Regs.TBCTL.bit.HSPCLKDIV = 0x0;
EPwm1Regs.TBCTL.bit.CLKDIV = 0x0;
EPwm1Regs.AQCTLA.bit.CAU = 0x2;
EPwm1Regs.AQCTLA.bit.CAD = 0x1;
EPwm1Regs.AQCTLB.bit.ZRO = 0x2;
EPwm1Regs.AQCTLB.bit.PRD = 0x1;
EPwm1Regs.ETSEL.bit.INTSEL = 0x1;
EPwm1Regs.ETSEL.bit.INTEN = 0x1;
EPwm1Regs.ETPS.bit.INTPRD = 0x1;
CpuSysRegs.PCLKCR0.bit.TBCLKSYNC = 1;
CpuSysRegs.PCLKCR0.bit.GTBCLKSYNC = 1;
EDIS;
}
需要注意的是,此代碼僅包含基本的PWM控制,需要根據具體的太陽能逆變器的硬件設置進行修改。 |
|