想通过高精度PWM改变移相角,但是实验发现给小数的时候无法识别,依然按照整数来处理,(给整数可以移相,比如100到101,给小数不可以,比如100到100.5)代码如下
初始化
void InitEPwm2Example() //滞后臂
{
//
// Setup TBCLK
//
EALLOW;
EPwm2Regs.TBPRD = period1; // Set timer period
EPwm2Regs.TBPHS.half.TBPHS = PHS; // Phase is 0
EPwm2Regs.TBPHS.half.TBPHSHR = 0; // Phase is 0
EPwm2Regs.CMPA.half.CMPA=272;
{
//
// Setup TBCLK
//
EALLOW;
EPwm2Regs.TBPRD = period1; // Set timer period
EPwm2Regs.TBPHS.half.TBPHS = PHS; // Phase is 0
EPwm2Regs.TBPHS.half.TBPHSHR = 0; // Phase is 0
EPwm2Regs.CMPA.half.CMPA=272;
EPwm2Regs.TBCTL.bit.CTRMODE = TB_COUNT_UP; // Count up
EPwm2Regs.TBCTL.bit.PHSEN = TB_ENABLE;
EPwm2Regs.TBCTL.bit.PRDLD = TB_SHADOW;
EPwm2Regs.TBCTL.bit.SYNCOSEL = TB_SYNC_IN;
EPwm2Regs.TBCTL.bit.PHSEN = TB_ENABLE;
EPwm2Regs.TBCTL.bit.PRDLD = TB_SHADOW;
EPwm2Regs.TBCTL.bit.SYNCOSEL = TB_SYNC_IN;
EPwm2Regs.TBCTR = 0x0000; // Clear counter
EPwm2Regs.TBCTL.bit.HSPCLKDIV = TB_DIV1; // Clock ratio to SYSCLKOUT
EPwm2Regs.TBCTL.bit.CLKDIV = TB_DIV1;
EPwm2Regs.TBCTL.bit.HSPCLKDIV = TB_DIV1; // Clock ratio to SYSCLKOUT
EPwm2Regs.TBCTL.bit.CLKDIV = TB_DIV1;
EPwm2Regs.CMPCTL.bit.SHDWAMODE = CC_SHADOW;
EPwm2Regs.CMPCTL.bit.SHDWBMODE = CC_SHADOW;
EPwm2Regs.CMPCTL.bit.LOADAMODE = CC_CTR_ZERO;
EPwm2Regs.CMPCTL.bit.LOADBMODE = CC_CTR_ZERO;
EPwm2Regs.CMPCTL.bit.SHDWBMODE = CC_SHADOW;
EPwm2Regs.CMPCTL.bit.LOADAMODE = CC_CTR_ZERO;
EPwm2Regs.CMPCTL.bit.LOADBMODE = CC_CTR_ZERO;
// EPwm2Regs.AQCTLB.bit.CAU = AQ_CLEAR;
// EPwm2Regs.AQCTLB.bit.PRD = AQ_SET;
EPwm2Regs.AQCTLB.bit.CAU = AQ_NO_ACTION;
EPwm2Regs.AQCTLB.bit.PRD = AQ_NO_ACTION;
// EPwm2Regs.AQCTLB.bit.PRD = AQ_SET;
EPwm2Regs.AQCTLB.bit.CAU = AQ_NO_ACTION;
EPwm2Regs.AQCTLB.bit.PRD = AQ_NO_ACTION;
EPwm2Regs.DBCTL.bit.IN_MODE = 3;
EPwm2Regs.DBCTL.bit.OUT_MODE = DB_FULL_ENABLE;
// EPwm2Regs.DBCTL.bit.POLSEL = DB_ACTV_HIC;
EPwm2Regs.DBFED = db; //死区300ns
EPwm2Regs.DBRED = db;
EPwm2Regs.DBCTL.bit.OUT_MODE = DB_FULL_ENABLE;
// EPwm2Regs.DBCTL.bit.POLSEL = DB_ACTV_HIC;
EPwm2Regs.DBFED = db; //死区300ns
EPwm2Regs.DBRED = db;
EPwm2Regs.HRCNFG.all = 0x0;
EPwm2Regs.HRCNFG.bit.EDGMODE = HR_BEP; // MEP control on falling edge
EPwm2Regs.HRCNFG.bit.CTLMODE = HR_PHS;
EPwm2Regs.HRCNFG.bit.HRLOAD = HR_CTR_ZERO;
EPwm2Regs.HRCNFG.bit.EDGMODE = HR_BEP; // MEP control on falling edge
EPwm2Regs.HRCNFG.bit.CTLMODE = HR_PHS;
EPwm2Regs.HRCNFG.bit.HRLOAD = HR_CTR_ZERO;
EPwm2Regs.HRCNFG.bit.SWAPAB=0;
EPwm2Regs.HRCNFG.bit.SELOUTB=0;
EPwm2Regs.HRCNFG.bit.AUTOCONV = 0;
EPwm2Regs.HRPCTL.bit.HRPE = 1;
EPwm2Regs.HRPCTL.bit.TBPHSHRLOADE = 1;
EDIS;
EPwm2Regs.HRCNFG.bit.SELOUTB=0;
EPwm2Regs.HRCNFG.bit.AUTOCONV = 0;
EPwm2Regs.HRPCTL.bit.HRPE = 1;
EPwm2Regs.HRPCTL.bit.TBPHSHRLOADE = 1;
EDIS;
}
应用代码:
PID_Value.pidvalue = 100.5;
EPwm2Regs.TBPHS.half.TBPHS = (Uint16) PID_Value.pidvalue;
EPwm2Regs.TBPHS.half.TBPHSHR = (Uint16) ( (PID_Value.pidvalue – EPwm2Regs.TBPHS.half.TBPHS)*93+0.5) <<8;
EPwm2Regs.TBPHS.half.TBPHS = (Uint16) PID_Value.pidvalue;
EPwm2Regs.TBPHS.half.TBPHSHR = (Uint16) ( (PID_Value.pidvalue – EPwm2Regs.TBPHS.half.TBPHS)*93+0.5) <<8;
da qin zheng sheng:
pwm寄存器都是整型数据
,
user6532300:
是整型寄存器,但是我赋值的数据也是整型呢!我虽然写的是小球,后面处理之后还是整型
,
Green Deng:
如上所述,寄存器值一般都是整形的,如果没有必要的话还是尽量用整型值进行赋值。
,
user6532300:
您好,我的寄存器赋值都是整型呢,请问我的高精度pwm配置对不对,按照这种配置为啥不能小数时候移相呢,高精度不就是可以对小数进行处理嘛?