DSP28335中文资料 - 图文 下载本文

DSP28335测试总结

void UpdatePwm3B(float32 pw,float32 f); void UpdatePwm4A(float32 pw,float32 f); void UpdatePwm4B(float32 pw,float32 f); void UpdatePwm5A(float32 pw,float32 f); void UpdatePwm5B(float32 pw,float32 f); void UpdatePwm6A(float32 pw,float32 f); void UpdatePwm6B(float32 pw,float32 f);

//初始化PWM函数//

void InitPwm(int16 c,float32 f) {

switch(c) { case 0: InitPwm1AB(f); break; case 1: InitPwm1AB(f); break; case 2: InitPwm2AB(f); break; case 3: InitPwm2AB(f); break; case 4: InitPwm3AB(f); break; case 5: InitPwm3AB(f); break; case 6: InitPwm4AB(f); break; case 7: InitPwm4AB(f); break;

23

DSP28335测试总结

}

case 8: InitPwm5AB(f); break; case 9: InitPwm5AB(f); break; case 10: InitPwm6AB(f); break; case 11: InitPwm6AB(f); break; default: break; }

//PWM信号产生函数//

void UpdatePwm(int16 c,float32 pw,float32 f)//入口参数:通道、占空比、频率 { if(pw<=0.0001) pw=0.0001; else if(pw>99.9999) pw=99.9999; pw = pw/100.0; switch(c) { case 0: UpdatePwm1A(pw,f); break; case 1: UpdatePwm1B(pw,f); break; case 2: UpdatePwm2A(pw,f); break;

24

DSP28335测试总结

case 3:

UpdatePwm2B(pw,f); break; case 4:

UpdatePwm3A(pw,f); break; case 5:

UpdatePwm3B(pw,f); break; case 6:

UpdatePwm4A(pw,f); break; case 7:

UpdatePwm4B(pw,f); break; case 8:

UpdatePwm5A(pw,f); break; case 9:

UpdatePwm5B(pw,f); break; case 10:

UpdatePwm6A(pw,f); break; case 11:

UpdatePwm6B(pw,f); break;

default:break; }

}

//初始化子函数,对第一个函数作注释// void InitPwm1AB(float32 f) {

Uint16 T= 2343750/f-1.0;//系统时钟SYSCLKOUT=150MHzTBCLK=6.6666667ns,在连续增计数模式下,f=150000000/(TBPDR+1) // T = 150 000 000 /CLKDIV/HSPCLKDIV/f - 1.0 EALLOW;

25

,DSP28335测试总结

//先初始化通用输入输出口//

GpioCtrlRegs.GPAPUD.bit.GPIO0 = 0; GpioCtrlRegs.GPAMUX1.bit.GPIO0 = 1; GpioCtrlRegs.GPAPUD.bit.GPIO1 = 0; GpioCtrlRegs.GPAMUX1.bit.GPIO1 = 1;

EPwm1Regs.TBPHS.half.TBPHS = 0; // 在相位寄存器中设置计数器的起始计数位置

//下面两条语句组合对PWM的时钟进行分频 EPwm1Regs.TBCTL.bit.CLKDIV = 6; EPwm1Regs.TBCTL.bit.HSPCLKDIV = 0;

EPwm1Regs.TBPRD = T; //在周期寄存器中设置计数器的计数周期

//TBCTL为定时器控制寄存器

EPwm1Regs.TBCTL.bit.CTRMODE = TB_COUNT_UP; //设置计数模式位为连续增计数模式,产生对称方波

EPwm1Regs.TBCTL.bit.PHSEN = TB_DISABLE; // 将定时器相位使能位关闭 EPwm1Regs.TBCTL.bit.PRDLD = TB_SHADOW;//映射寄存器SHADOW使能并配置映射寄存器为自动读写

EPwm1Regs.TBCTL.bit.SYNCOSEL = TB_CTR_ZERO; // 定时器时钟源选择,一共有四种时钟源

EPwm1Regs.CMPA.half.CMPA= 0.0001*T;// 设置EPWM1A比较值寄存器的比较值,即体现EPWM1A的占空比 EPwm1Regs.CMPB= 0.0001*T;

EPwm1Regs.CMPCTL.bit.SHDWAMODE = CC_SHADOW;//A模块比较模式 EPwm1Regs.CMPCTL.bit.SHDWBMODE = CC_SHADOW;//B模块比较模式 EPwm1Regs.CMPCTL.bit.LOADAMODE = CC_CTR_ZERO; // A模块比较使能,通过写0来清除SHDWAMODE位来使能load on CTR=Zero

EPwm1Regs.CMPCTL.bit.LOADBMODE = CC_CTR_ZERO; // B模块比较使能,通过写0来清除SHDWBMODE位来使能load on CTR=Zero

//AQCTLA为输出A比较方式控制寄存器

EPwm1Regs.AQCTLA.bit.ZRO = AQ_SET; // TBCTR(计数器)计到零时使输出为反向

EPwm1Regs.AQCTLA.bit.CAU = AQ_CLEAR;//TBCTR(计数器)与CMPA在up计数时相等使输出为high,这关系的输出的占空比 EPwm1Regs.AQCTLB.bit.ZRO = AQ_SET; EPwm1Regs.AQCTLB.bit.CBU = AQ_CLEAR;

26