This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

TMS320F28379D: timer timing issue and PWM interrupt not being called

Part Number: TMS320F28379D
Other Parts Discussed in Thread: C2000WARE

Tool/software:

Dear Experts,

I am trying to initialize the timer and PWM.First issue is the timer interrupt -is being called but I see there is a timing issue.

Here is my calculation for 1 second timer:

SYSCLK: 200MHz

    CpuTimer0Regs.PRD.bit.LSW = 0x2D00;
    CpuTimer0Regs.PRD.bit.MSW = 0x0131;
    CpuTimer0Regs.TPR.bit.TDDR= 10;

Second, the PWM interrupt that is enabled at CTR=0 is not al all being called.

Here is the code

#include "F28x_Project.h"

extern void InitSysCtrl(void);
extern void InitPieCtrl(void);
extern void InitPieVectTable(void);

interrupt void TimerOvf(void);
interrupt void PWM_Int(void);

void Initialize_GPIO(void);
void Initialize_PWM1(void);
void Custom_Init(void);
void timer0_init(void);
int pwm,b=0;
void main(void)
{

   InitSysCtrl();
   Custom_Init();
   DINT;
   Initialize_GPIO();
   Initialize_PWM1();
   InitPieCtrl();

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

   EALLOW;
   PieCtrlRegs.PIEIER1.bit.INTx7 = 1;
   PieCtrlRegs.PIEIER3.bit.INTx1 = 1;

   PieVectTable.TIMER0_INT = &TimerOvf;
   PieVectTable.EPWM1_INT = &PWM_Int;
   PieCtrlRegs.PIECTRL.bit.ENPIE= 1;
   EDIS;

   IER |= 3;
   EINT;  // Enable Global interrupt INTM
   ERTM;  // Enable Global realtime interrupt DBGM
   timer0_init();
   CpuTimer0Regs.TCR.bit.TSS=0;
   while(1)
       {


        }
}
void Initialize_GPIO(void)
{
    EALLOW;
    GpioCtrlRegs.GPBDIR.bit.GPIO62 = 1;
    GpioCtrlRegs.GPCDIR.bit.GPIO73= 1;
    GpioCtrlRegs.GPAMUX1.bit.GPIO0 = 1; //EPwm1
    EDIS;

}
void Custom_Init(void)
{
    EALLOW;
    ClkCfgRegs.AUXPLLMULT.bit.IMULT=20;
    ClkCfgRegs.SYSCLKDIVSEL.bit.PLLSYSCLKDIV=0;
    ClkCfgRegs.SYSPLLCTL1.bit.PLLCLKEN = 1;
    ClkCfgRegs.LOSPCP.bit.LSPCLKDIV = 2;
    ClkCfgRegs.PERCLKDIVSEL.bit.EPWMCLKDIV = 0;
    CpuSysRegs.PCLKCR0.bit.TBCLKSYNC = 1;   ///source initsysctrl
    CpuSysRegs.PCLKCR2.bit.EPWM1 = 1;
    DevCfgRegs.CPUSEL0.bit.EPWM1 = 0;
    EDIS;
}

void Initialize_PWM1(void)
{
      EPwm1Regs.TBCTL.bit.CTRMODE = 0;             // Count up
      EPwm1Regs.TBPRD = 10000;                    // Set timer period
      EPwm1Regs.TBCTL.bit.PHSEN = 0;               // Disable phase loading
      EPwm1Regs.TBPHS.bit.TBPHS = 0x0000;          // Phase is 0
      EPwm1Regs.TBCTR = 0x0000;                    // Clear counter
      EPwm1Regs.TBCTL.bit.HSPCLKDIV = 0;           // Clock ratio to SYSCLKOUT
      EPwm1Regs.TBCTL.bit.CLKDIV = 0;
      EPwm1Regs.TBCTL.bit.SYNCOSEL = 1;            // SYNC output on CTR = 0
      // Setup shadow register load on ZERO
      EPwm1Regs.CMPCTL.bit.SHDWAMODE = 0;
      EPwm1Regs.CMPCTL.bit.SHDWBMODE = 0;
      EPwm1Regs.CMPCTL.bit.LOADAMODE = 0;
      EPwm1Regs.CMPCTL.bit.LOADBMODE = 0;
      // Set Compare values
      EPwm1Regs.CMPA.bit.CMPA = 10000/2;      // Set compare A value
      // Set actions
      EPwm1Regs.AQCTLA.bit.ZRO = 2;                // Set PWM1A on Zero
      EPwm1Regs.AQCTLA.bit.CAU = 1;                // Clear PWM1A on event A, up count
      //interrput enable
      EPwm1Regs.ETSEL.bit.INTSEL = 1; //@ CTR = 0
      EPwm1Regs.ETSEL.bit.INTEN = 1;

}
void timer0_init(void)
{
    EALLOW;
    CpuTimer0Regs.PRD.bit.LSW = 0x2D00;
    CpuTimer0Regs.PRD.bit.MSW = 0x0131;
    CpuTimer0Regs.TPR.bit.TDDR= 10;

    CpuTimer0Regs.TCR.bit.TIE= 1;
    CpuTimer0Regs.TCR.bit.TSS=1;
    CpuTimer0Regs.TCR.bit.FREE=0;
    CpuTimer0Regs.TCR.bit.TRB=0;
    EDIS;
}
void TimerOvf(void)
{
    b= b+1;
    if(b>10)
    {
        b=0;
    }
    GpioDataRegs.GPBTOGGLE.bit.GPIO62=1;
    CpuTimer0Regs.TCR.bit.TIF = 1;

    PieCtrlRegs.PIEACK.all = PIEACK_GROUP1;

}

void PWM_Int(void)
{
    pwm = pwm+1;
    if(pwm>10)
    {pwm =0;}
    GpioDataRegs.GPCTOGGLE.bit.GPIO73 = 1;
 //   EPwm1Regs.ETCLR.bit.INT = 1;
    PieCtrlRegs.PIEACK.all = PIEACK_GROUP3;
}

Thanks in advance!

  • Hello,

    To clarify, if you set a breakpoint in your PWM interrupt, the breakpoint is not getting hit at all, correct? Does the program pause in another point in the code or get stuck in the timer ISR at all? What is happening when you run it?

    I also first wanted to check if you have referenced our C2000Ware examples already? The software examples (in both location directories below) show how to set up interrupts (there are EPWM examples, Timer examples, and interrupt examples available). These can be helpful to verify your peripheral configurations and interrupt setups. If the PWM interrupt is not getting hit at all, then either the CPU is stuck elsewhere or the interrupt configurations or PWM configurations may be incorrect.

    • {C2000Ware}\driverlib\f2837xd\examples\cpu1\
    • {C2000Ware}\device_support\f2837xd\examples\cpu1

    Best Regards,

    Allison

  • I resolved it myself after enable a couple of bits. Thanks!