打印

28069生成SPWM

[复制链接]
941|1
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
17302259960|  楼主 | 2018-3-11 22:43 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
SPWM, pi, se, gp, ni
这是我自己写的程序,按理说,应该能生成spwm。可是只有PWM,没有调制成SPWM,求大神看下
#include "DSP28x_project.h"

void initio(void)
{
        EALLOW;
        GpioCtrlRegs.GPAMUX1.bit.GPIO0=1;
        GpioCtrlRegs.GPAMUX1.bit.GPIO1=1;
        EDIS;
}

void initpwm1(void)
{
        EPwm1Regs.TBPRD=4688;
        EPwm1Regs.TBPHS.half.TBPHS=0;
        EPwm1Regs.TBCTR=2344;
        EPwm1Regs.TBCTL.bit.CTRMODE=TB_COUNT_UPDOWN;
        EPwm1Regs.TBCTL.bit.PHSEN=TB_DISABLE;
        EPwm1Regs.TBCTL.bit.PRDLD=TB_SHADOW;
        EPwm1Regs.TBCTL.bit.SYNCOSEL=TB_SYNC_DISABLE;
        EPwm1Regs.TBCTL.bit.HSPCLKDIV=TB_DIV1;
        EPwm1Regs.TBCTL.bit.CLKDIV=TB_DIV1;
        EPwm1Regs.CMPCTL.bit.SHDWAMODE=CC_SHADOW;
        EPwm1Regs.CMPCTL.bit.SHDWBMODE=CC_SHADOW;
        EPwm1Regs.CMPCTL.bit.LOADAMODE=CC_CTR_ZERO;
        EPwm1Regs.CMPCTL.bit.LOADBMODE=CC_CTR_ZERO;
        EPwm1Regs.AQCTLA.bit.CAU=AQ_SET;
        EPwm1Regs.AQCTLA.bit.CAD=AQ_CLEAR;
        EPwm1Regs.AQCTLB.bit.CAU=AQ_CLEAR;
        EPwm1Regs.AQCTLB.bit.CAD=AQ_SET;
       
        EPwm1Regs.DBCTL.bit.IN_MODE=DBA_ALL;
        EPwm1Regs.DBCTL.bit.POLSEL=DB_ACTV_LOC;
        EPwm1Regs.DBCTL.bit.OUT_MODE=DB_ACTV_LO;
        EPwm1Regs.DBRED=125;
        EPwm1Regs.DBFED=125;
        EPwm1Regs.ETSEL.bit.INTSEL=0x03;
        EPwm1Regs.ETSEL.bit.INTEN=0x01;
        EPwm1Regs.ETPS.bit.INTPRD=0x03;
}
void initpwmpie(void)
{
        EALLOW;
        PieVectTable.EPWM1_INT=&pwm1_isrq;
        EDIS;
        EALLOW;
        SysCtrlRegs.PCLKCR0.bit.TBCLKSYNC=0;
        EDIS;
        initpwm1();
        EALLOW;
        SysCtrlRegs.PCLKCR0.bit.TBCLKSYNC=1;
        EDIS;
        GpioDataRegs.GPADAT.bit.GPIO6=0;
        IER|=M_INT3;
        PieCtrlRegs.PIEIER3.bit.INTx1=1;
        EINT;
        ERTM;
}
interrupt void pwm1_isrq(void)     // EPWM-1
{
  // Insert ISR Code here

          // Insert ISR Code here


        
                N1=128;
                n1=128*(1+i1)/N1-1;
                a1=4050;
                k1=a1/255;
                b1=(unsigned int)(2344-k1*128);
                z1=(unsigned int)(k1*sintab[n1]+b1+1);
                EPwm1Regs.CMPA.half.CMPA=z1;
                EPwm1Regs.CMPB=z1;
                i1=i1+1;
                if(i1==255)
{               
                i1=0;
}
                EPwm1Regs.ETCLR.bit.INT=1;
                PieCtrlRegs.PIEACK.all=PIEACK_GROUP3;
}
#define uint unsigned int
#define uchar unsigned char
unsigned char sintab[]=
{
                0x80,0x83,0x86,0x89,0x8D,0x90,0x93,0x96,
                0x99,0x9C,0x9F,0xA2,0xA5,0xA8,0xAB,0xAE,
                0xB1,0xB4,0xB7,0xBA,0xBC,0xBF,0xC2,0xC5,
                0xC7,0xCA,0xCC,0xCF,0xD1,0xD4,0xD6,0xD8,
                0xDA,0xDD,0xDF,0xE1,0xE3,0xE5,0xE7,0xE9,
                0xEA,0xEC,0xEE,0xEF,0xF1,0xF2,0xF4,0xF5,
                0xF6,0xF7,0xF8,0xF9,0xFA,0xFB,0xFC,0xFD,
                0xFD,0xFE,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
                0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFE,0xFD,
                0xFD,0xFC,0xFB,0xFA,0xF9,0xF8,0xF7,0xF6,
                0xF5,0xF4,0xF2,0xF1,0xEF,0xEE,0xEC,0xEA,
                0xE9,0xE7,0xE5,0xE3,0xE1,0xDE,0xDD,0xDA,
                0xD8,0xD6,0xD4,0xD1,0xCF,0xCC,0xCA,0xC7,
                0xC5,0xC2,0xBF,0xBC,0xBA,0xB7,0xB4,0xB1,
                0xAE,0xAB,0xA8,0xA5,0xA2,0x9F,0x9C,0x99,
                0x96,0x93,0x90,0x8D,0x89,0x86,0x83,0x80,
                0x80,0x7C,0x79,0x78,0x72,0x6F,0x6C,0x69,
                0x66,0x63,0x60,0x5D,0x5A,0x57,0x55,0x51,
                0x4E,0x4C,0x48,0x45,0x43,0x40,0x3D,0x3A,
                0x38,0x35,0x33,0x30,0x2E,0x2B,0x29,0x27,
                0x25,0x22,0x20,0x1E,0x1C,0x1A,0x18,0x16,
                0x15,0x13,0x11,0x10,0x0E,0x0D,0x0B,0x0A,
                0x09,0x08,0x07,0x06,0x05,0x04,0x03,0x02,
                0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
                0x00,0x00,0x00,0x00,0x00,0x01,0x02,0x02,
                0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x0A,
                0x0B,0x0d,0x0e,0x10,0x11,0x13,0x15,0x16,
                0x18,0x1a,0x1c,0x1e,0x20,0x22,0x25,0x27,
                0x29,0x2b,0x2e,0x30,0x33,0x35,0x38,0x3a,
                0x3d,0x40,0x43,0x45,0x48,0x4c,0x4e,0x51,
                0x55,0x57,0x5a,0x5d,0x60,0x63,0x66,0x69,
                0x6c,0x6f,0x72,0x76,0x79,0x7c,0x80
};
                float k1=0,k2=0,k3=0;
                unsigned int i1=0,i2=43,i3=85;
                unsigned int fc,fr=50;
                unsigned int b1=0,z1,N1,n1;
                float a1=0;

void main(void)
{

                InitSysCtrl();
                DINT;
                InitPieCtrl();
                IER=0x0000;
                IFR=0x0000;
                InitPieVectTable();

                initio();
                initpwmpie();
                while(1);
}

相关帖子

沙发
17302259960|  楼主 | 2018-3-12 11:26 | 只看该作者
解决了。

使用特权

评论回复
发新帖 我要提问
您需要登录后才可以回帖 登录 | 注册

本版积分规则

8

主题

20

帖子

0

粉丝