#include"DSP28x_Project.h"
#define CPU_CLK 150e6 //系统时钟150MHz
#define TBCTLVAL 0x200E //控制寄存器的值
Uint32 PWM_CLK,PWM_CLK1,PWM_CLK2;
float SP,SP1,SP2;
void main(void)
{
InitSysCtrl(); //初始化系统
InitGpio(); //初始化GPIIO
InitPieCtrl(); //清除所有中断
IER = 0x0000;
IFR = 0x0000;
InitPieVectTable(); //初始化中断向量表
InitEPwm3Gpio(); //初始化PWM1引脚
PWM_CLK = 1000;
SP = CPU_CLK/(2*PWM_CLK);
EPwm3Regs.TBSTS.all = 0; //将时基的状态寄存器清零
EPwm3Regs.TBPHS.half.TBPHS = 0; //相位寄存器设置为0
EPwm3Regs.TBCTR = 0; //时基计数器清零
EPwm3Regs.CMPCTL.all = 0x50; //CMPA和CMPB配置为立即模式
EPwm3Regs.CMPA.half.CMPA = SP/2; //设置占空比为0.5,SP是周期寄存器的值
EPwm3Regs.CMPB = 0;
EPwm3Regs.AQCTLA.all = 0x60; //当时间基准计数器的值等于CMPA的值,且正在递增计数,EPWMxA输出高电平;当时间基准计数器的值等于CMPA的值,且正在递减计数,EPWMxA输出低电平
EPwm3Regs.AQCTLB.all = 0;
EPwm3Regs.AQSFRC.all = 0;
EPwm3Regs.AQCSFRC.all = 0;
EPwm3Regs.DBCTL.all = 0xb; //EPwm1B与EPwm1A相关联,即EPwm1B随着EPwm1A的变化而变化
EPwm3Regs.DBRED = 25; //上升沿的死区时间设置为25
EPwm3Regs.DBFED = 25; //下降沿的死区时间设置为25
EPwm3Regs.TZSEL.all = 0; //没有用到联防区模块,全部失效
EPwm3Regs.TZCTL.all = 0;
EPwm3Regs.TZEINT.all = 0;
EPwm3Regs.TZ**.all = 0;
EPwm3Regs.TZCLR.all = 0;
EPwm3Regs.TZFRC.all = 0;
EPwm3Regs.ETSEL.all = 0;
EPwm3Regs.ET**.all = 0;
EPwm3Regs.ETCLR.all = 0;
EPwm3Regs.ETFRC.all = 0;
EPwm3Regs.PCCTL.all = 0;
EPwm3Regs.TBCTL.all = 0x0010 + TBCTLVAL; //增减模式
EPwm3Regs.TBPRD = SP;
PWM_CLK1 = 500;
SP1 = CPU_CLK/(2*PWM_CLK1);
InitEPwm1Gpio();
EPwm1Regs.TBSTS.all = 0; //将时基的状态寄存器清零
EPwm1Regs.TBPHS.half.TBPHS = 0; //相位寄存器设置为0
EPwm1Regs.TBCTR = 0; //时基计数器清零
EPwm1Regs.CMPCTL.all = 0x50; //CMPA和CMPB配置为立即模式
EPwm1Regs.CMPA.half.CMPA = SP1/2; //设置占空比为0.5,SP是周期寄存器的值
EPwm1Regs.CMPB = 0;
EPwm1Regs.AQCTLA.all = 0x60; //当时间基准计数器的值等于CMPA的值,且正在递增计数,EPWMxA输出高电平;当时间基准计数器的值等于CMPA的值,且正在递减计数,EPWMxA输出低电平
EPwm1Regs.AQCTLB.all = 0;
EPwm1Regs.AQSFRC.all = 0;
EPwm1Regs.AQCSFRC.all = 0;
EPwm1Regs.DBCTL.all = 0xb; //EPwm1B与EPwm1A相关联,即EPwm1B随着EPwm1A的变化而变化
EPwm1Regs.DBRED = 25; //上升沿的死区时间设置为25
EPwm1Regs.DBFED = 25; //下降沿的死区时间设置为25
EPwm1Regs.TZSEL.all = 0; //没有用到联防区模块,全部失效
EPwm1Regs.TZCTL.all = 0;
EPwm1Regs.TZEINT.all = 0;
EPwm1Regs.TZ**.all = 0;
EPwm1Regs.TZCLR.all = 0;
EPwm1Regs.TZFRC.all = 0;
EPwm1Regs.ETSEL.all = 0;
EPwm1Regs.ET**.all = 0;
EPwm1Regs.ETCLR.all = 0;
EPwm1Regs.ETFRC.all = 0;
EPwm1Regs.PCCTL.all = 0;
EPwm1Regs.TBCTL.all = 0x0010 + TBCTLVAL; //增减模式
EPwm1Regs.TBPRD = SP1;
PWM_CLK2 = 2000;
SP2 = CPU_CLK/(2*PWM_CLK2);
InitEPwm2Gpio();
EPwm2Regs.TBSTS.all = 0; //将时基的状态寄存器清零
EPwm2Regs.TBPHS.half.TBPHS = 0; //相位寄存器设置为0
EPwm2Regs.TBCTR = 0; //时基计数器清零
EPwm2Regs.CMPCTL.all = 0x50; //CMPA和CMPB配置为立即模式
EPwm2Regs.CMPA.half.CMPA = SP2/2; //设置占空比为0.5,SP是周期寄存器的值
EPwm2Regs.CMPB = 0;
EPwm2Regs.AQCTLA.all = 0x60; //当时间基准计数器的值等于CMPA的值,且正在递增计数,EPWMxA输出高电平;当时间基准计数器的值等于CMPA的值,且正在递减计数,EPWMxA输出低电平
EPwm2Regs.AQCTLB.all = 0;
EPwm2Regs.AQSFRC.all = 0;
EPwm2Regs.AQCSFRC.all = 0;
EPwm2Regs.DBCTL.all = 0xb; //EPwm1B与EPwm1A相关联,即EPwm1B随着EPwm1A的变化而变化
EPwm2Regs.DBRED = 25; //上升沿的死区时间设置为25
EPwm2Regs.DBFED = 25; //下降沿的死区时间设置为25
EPwm2Regs.TZSEL.all = 0; //没有用到联防区模块,全部失效
EPwm2Regs.TZCTL.all = 0;
EPwm2Regs.TZEINT.all = 0;
EPwm2Regs.TZ**.all = 0;
EPwm2Regs.TZCLR.all = 0;
EPwm2Regs.TZFRC.all = 0;
EPwm2Regs.ETSEL.all = 0;
EPwm2Regs.ET**.all = 0;
EPwm2Regs.ETCLR.all = 0;
EPwm2Regs.ETFRC.all = 0;
EPwm2Regs.PCCTL.all = 0;
EPwm2Regs.TBCTL.all = 0x0010 + TBCTLVAL; //增减模式
EPwm2Regs.TBPRD = SP2;
for(; ;)
{
}
}
//看了示波器,只有输出2000Hz的波形,其他500Hz和1000Hz的为啥没有??哪里写错了,请指教,小白一枚。
|