基于DSP的pwm整流器C代码
时间: 2023-08-01 13:14:22 浏览: 146
以下是一个基于TMS320F28335 DSP的PWM整流器的C语言代码,你可以根据需要进行修改和适配:
```c
#include "DSP2833x_Device.h"
#define PWM_DUTY_CYCLE 1000 // PWM占空比
void GPIO_Configuration(void);
void PWM_Configuration(void);
void main(void)
{
InitSysCtrl();
InitPieCtrl();
IER = 0x0000;
IFR = 0x0000;
InitPieVectTable();
GPIO_Configuration();
PWM_Configuration();
while (1)
{
// 你的代码逻辑
}
}
void GPIO_Configuration(void)
{
EALLOW;
GpioCtrlRegs.GPAMUX1.bit.GPIO0 = 0;
GpioCtrlRegs.GPADIR.bit.GPIO0 = 0;
EDIS;
}
void PWM_Configuration(void)
{
EPwm1Regs.TBPRD = 1999;
EPwm1Regs.TBPHS.bit.TBPHS = 0;
EPwm1Regs.TBCTL.bit.CTRMODE = 0;
EPwm1Regs.TBCTL.bit.PHSEN = 0;
EPwm1Regs.TBCTL.bit.PRDLD = 0;
EPwm1Regs.TBCTL.bit.SYNCOSEL = 3;
EPwm1Regs.CMPCTL.bit.SHDWAMODE = 1;
EPwm1Regs.CMPCTL.bit.SHDWBMODE = 1;
EPwm1Regs.CMPCTL.bit.LOADAMODE = 0;
EPwm1Regs.CMPCTL.bit.LOADBMODE = 0;
EPwm1Regs.CMPA.bit.CMPA = PWM_DUTY_CYCLE - 1;
EPwm1Regs.CMPB.bit.CMPB = 0;
EPwm1Regs.AQCTLA.bit.CAU = 2;
EPwm1Regs.AQCTLA.bit.CAD = 1;
EPwm1Regs.AQCTLB.bit.CBU = 2;
EPwm1Regs.AQCTLB.bit.CBD = 1;
EPwm1Regs.DBCTL.bit.IN_MODE = 0;
EPwm1Regs.DBCTL.bit.OUT_MODE = 3;
EPwm1Regs.DBCTL.bit.POLSEL = 2;
EPwm1Regs.DBCTL.bit.HALFCYCLE = 1;
EPwm1Regs.DBRED = 0;
EPwm1Regs.DBFED = 0;
EPwm1Regs.TZSEL.bit.OSHT1 = 0;
EPwm1Regs.TZSEL.bit.OSHT2 = 0;
EPwm1Regs.TZSEL.bit.OSHT3 = 0;
EPwm1Regs.TZCTL.bit.TZA = 3;
EPwm1Regs.TZCTL.bit.TZB = 3;
EPwm1Regs.TZCLR.bit.OST = 1;
EPwm1Regs.TZFRC.bit.OST = 1;
EPwm1Regs.TBCTL.bit.CTRMODE = 0;
EPwm1Regs.TBCTL.bit.PHSEN = 0;
EPwm1Regs.TBCTL.bit.PRDLD = 0;
EPwm1Regs.TBCTL.bit.SYNCOSEL = 3;
}
```
这个代码使用了TMS320F28335 DSP的EPwm1模块来生成PWM波形,并且使用了EPwm1的A和B通道来控制输出,通过修改PWM_DUTY_CYCLE的值可以改变占空比。
阅读全文