TMS320F28027: Timer based State Machines not calling various Tasks

Part Number: TMS320F28027
Other Parts Discussed in Thread: CONTROLSUITE, C2000WARE, TIDM-DC-DC-BUCK, C2000WARE-DIGITALPOWER-SDK

Tool/software:

HI all,

I am trying to implement state machine based tasks in 28027. I referred some programmes given in control suite. I am however not able to go between various tasks A0, A1, A2 etc. What could be the reason for this.

I am attaching the code for your reference. It also goes to ESTOP 0 after few seconds.

#include "DSP28x_Project.h"     // Device Headerfile and Examples Include File
#include "MATH_EMAVG_IQ.h"
#include "Solar_IQ.h"
#include "IQmathLib.h"
#include <math.h>
#include "VARIABLES_CONSTANTS.h"



// -------------------------------- FRAMEWORK --------------------------------------
// State Machine function prototypes
//----------------------------------------------------------------------------------
// Alpha states
void A0(void);  //state A0
// A branch states
void A1(void);  //state A1
void A2(void);  //state A2
void A3(void);  //state A3
void A4(void);  //state A4
int A0_State=0, A1_State=0, A2_State=0, A3_State=0, A4_State=0;
// Variable declarations
void (*Alpha_State_Ptr)(void);  // Base States pointer
void (*A_Task_Ptr)(void);       // State pointer A branch


//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
// VARIABLE DECLARATIONS - GENERAL
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

// -------------------------------- FRAMEWORK --------------------------------------

int16   VTimer0[4];                 // Virtual Timers slaved off CPU Timer 0
int16   VTimer1[4];                 // Virtual Timers slaved off CPU Timer 1
int16   VTimer2[4];                 // Virtual Timers slaved off CPU Timer 2


void main(void)
   {
   InitSysCtrl();
   MemCopy(&RamfuncsLoadStart, &RamfuncsLoadEnd, &RamfuncsRunStart);
      InitFlash();
      // Step 4. Initialize the Device Peripheral. This function can be
      //         found in DSP2802x_CpuTimers.c
         InitCpuTimers();   // For this example, only initialize the Cpu Timers
      // Timing sync for background loops
      // Timer period definitions found in PeripheralHeaderIncludes.h

         //ConfigCpuTimer(struct CPUTIMER_VARS *Timer, float Freq, float Period)
         //CpuTimer0Regs.PRD.all =  60000 ;     // A tasks
         ConfigCpuTimer(&CpuTimer0, 60, 1000000);


          // Tasks State-machine init
         Alpha_State_Ptr = &A0;
              A_Task_Ptr = &A1;
              VTimer0[0] = 0;

   DINT;
   InitPieCtrl();

// Disable CPU interrupts and clear all CPU interrupt flags:
   IER = 0x0000;
   IFR = 0x0000;

   InitPieVectTable();

   EALLOW;
   SysCtrlRegs.PCLKCR0.bit.TBCLKSYNC = 0;
   EDIS;

      CpuTimer0Regs.TCR.all = 0x4001; // Use write-only instruction to set TSS bit = 0



   EALLOW;
   SysCtrlRegs.PCLKCR0.bit.TBCLKSYNC = 1;
   EDIS;



   // Enable CPU int1 which is connected to CPU-Timer 0, CPU int13
   // which is connected to CPU-Timer 1, and CPU int 14, which is connected
   // to CPU-Timer 2:
     IER |= M_INT1;
     IER |= M_INT3;



// Enable EPWM INTn in the PIE: Group 3 interrupt 1-3
 //  PieCtrlRegs.PIEIER1.bit.INTx1 = 1;   // Enable INT 1.1 in the PIE
   PieCtrlRegs.PIEIER3.bit.INTx2 = 1;

   PieCtrlRegs.PIEIER1.bit.INTx7 = 1;  // Enable INT 1.7 (Timer 0 interrupt)

   CpuTimer0Regs.TCR.bit.TIE = 1;
// Enable global Interrupts and higher priority real-time debug events:
   EINT;   // Enable Global interrupt INTM
   ERTM;   // Enable Global realtime interrupt DBGM



      //--------------------------------- FRAMEWORK -------------------------------------
          for(;;)  //infinite loop
          {
              // State machine entry & exit point
              //===========================================================
              (*Alpha_State_Ptr)();   // jump to an Alpha state (A0,B0,...)
              //===========================================================



          }
} //END MAIN CODE

//=================================================================================
//  STATE-MACHINE SEQUENCING AND SYNCRONIZATION
//=================================================================================

//--------------------------------- FRAMEWORK -------------------------------------
void A0(void)
{


    // loop rate synchronizer for A-tasks
    if(CpuTimer0Regs.TCR.bit.TIF == 1)
    {
      A0_State++;
      CpuTimer0Regs.TCR.bit.TIF = 0;  // clear flag
        //-----------------------------------------------------------
        (*A_Task_Ptr)();        // jump to an A Task (A1,A2,A3,...)
        //-----------------------------------------------------------
      VTimer0[0]++;           // virtual timer 0, instance 0 (spare)
    }

//    Alpha_State_Ptr = &B0;      // Comment out to allow only A tasks
}

//=================================================================================
//  A - TASKS
//=================================================================================
//--------------------------------------------------------
void A1(void)
//--------------------------------------------------------
{
   A1_State++;
//    FlagA1++;
    //-------------------
    //the next time CpuTimer0 'counter' reaches Period value go to A2
    A_Task_Ptr = &A2;
    //-------------------
}

//-----------------------------------------------------------------
void A2(void)
//-----------------------------------------------------------------
{
  A2_State++;
 //   FlagA2=1;
    //-------------------
    //the next time CpuTimer0 'counter' reaches Period value go to A1
    A_Task_Ptr = &A3;
    //-------------------
}

//-----------------------------------------
void A3(void)
//-----------------------------------------
{

    A3_State++;
    //-----------------
    //the next time CpuTimer0 'counter' reaches Period value go to A1
    A_Task_Ptr = &A4;
    //-----------------
}


//----------------------------------------------------------
void A4(void)
//---------------------------------------------------------
{
    A4_State++;
    //-----------------
    //the next time CpuTimer0 'counter' reaches Period value go to A1
    A_Task_Ptr = &A1;
    //-----------------
}