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.
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; //----------------- }
Hi,
Please see this forum post for informatino on how to use the C2000 state machine. https://e2e.ti.com/support/microcontrollers/c2000-microcontrollers-group/c2000/f/c2000-microcontrollers-forum/667596/tms320f28069-task-state-machine?tisearch=e2e-sitesearch&keymatch=C2000WARE See the attached PDF in the first reply (Topic6DF.pdf).
Additionally, I will recommend that you leverage the examples and reference designs in C2000Ware SDK. This is our latest and up to date device support for our products. It should be noted controlSUITE is deprecated and no longer being maintained.
Regards,
Ozino
Hi Ozino,
THanks for the reply. I had gone through that earlier. However its still not clear. I need to know if something else is missing in setting cputimers.
Furthermore,CpuTimer0Regs.TCR.bit.TIF == 1 this condition never comes.
Please can you refer any example programs for 28027
Thanks & Regards,
Hi All
Can somebody suggest minimum working example for implementing state machines along with CPU timer settings?
Thanks & Regards,
Hi Sachin,
You can take a look at the TIDM-DC-DC-BUCK example available in the C2000Ware-DigitalPower-SDK on how to use the state-machines. You can also refer to the CPU Timer example in C2000Ware for more information on how to configure multiple CPU Timers.Topic6DF (1).pdf
Regards,
Ozino