我用的是f28016,只开了eva的定时器,但发生中断的时候TBPRD TBCTR不相等,TBCTR总比TBPRD小,请问这是哪里有问题,程序如下:
void init_eva_time1(void)
{
// Setup TBCLK
// TBCLK=SYSCLKOUT/(HSPCLKDIV*CLKDIV)=60M/(2*2)=15M
// PWM FREQUENCY=15M/(EPWM1_TIMER_TBPRD*2)=15M/(750*2)=10K
EPwm1Regs.TBCTL.bit.CTRMODE = 2; // up down
EPwm1Regs.TBPRD = 750; / t period
EPwm1Regs.TBCTL.bit.PHSEN = 0; // Disable phase loading Clearing the TBCTL[PHSEN] bit configures the ePWM to ignore the synchronization input pulse
EPwm1Regs.TBPHS.half.TBPHS = 0x0000; // Phase is 0
EPwm1Regs.TBCTR = 0x0000; // Clear counter
EPwm1Regs.TBCTL.bit.HSPCLKDIV =1; // /2
EPwm1Regs.TBCTL.bit.CLKDIV = 1; // /2
// Setup shadow register load on PERIOD
// EPwm1Regs.CMPCTL.bit.SHDWAMODE = 0; //Shadow mode
// EPwm1Regs.CMPCTL.bit.LOADAMODE = 1; //Load on CTR = PRD
// Set Compare values
// EPwm1Regs.CMPA.half.CMP_A = 300; // Set Compare A value
// EPwm1Regs.CMPB = 300; // Set Compare B value
// EPwm1Regs.AQCTLA.bit.CAU=1;//force low,when incrementing
// EPwm1Regs.AQCTLA.bit.CAD=2;//force high,when decrementing
// EPwm1Regs.AQCTLB.bit.CBU=1;//force low,when incrementing
// EPwm1Regs.AQCTLB.bit.CBD=2;//force high,when decrementing
// set deadband
EPwm1Regs.DBCTL.bit.OUT_MODE = 3; //deadband enabled for both rising-edge and falling-edge
EPwm1Regs.DBCTL.bit.POLSEL = 0; //AH mode
EPwm1Regs.DBCTL.bit.IN_MODE = 3; //EPWMB is the source
EPwm1Regs.DBRED = 35; //rising-edge delay
EPwm1Regs.DBFED = 35; //falling-edge delay
EPwm1Regs.ETSEL.bit.INTSEL = 2; // period interrupt TBCTR = TBPRD
EPwm1Regs.ETSEL.bit.INTEN = 1; // enable interrupt
EPwm1Regs.ETPS.bit.INTPRD = 1; // Generate INT on first event
}
interrupt void eva_time1_isr(void)
{
// Clear INT flag for this timer
EPwm1Regs.ETCLR.bit.INT = 1;
// Acknowledge this interrupt to receive more interrupts from group 3
PieCtrlRegs.PIEACK.all = PIEACK_GROUP3;
}
此帖出自
小平头技术问答
kkk=EPwm1Regs.TBCTR;
保存一下进入到中断子程序时候的 EPwm1Regs.TBCTR;
的值。
楼主设置的是:CTRMODE = 2; 上升下降模式,从发生中断到进入中断子程序需要一些时间,我估计kkk的值和周期只相差并不大20来个时钟周期吧。
一周热门 更多>