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.

CCS/TMS320F28379D: Debuger got stuck in .cinit Boot 28.asm

Part Number: TMS320F28379D

Tool/software: Code Composer Studio

I was working on program One part which contains I2C and  other part contains ECAP, SCI etc modules.

First I made them separate because i am new learner. 

Both were separate working fine.

But when i tried to combine these two program now it is getting caught in  PROCESS CINIT INITIALIZATION TABLE.

Why is it so ? & How to get out of this ?

  • The .cinit section holds initialized program variables which get copied into RAM at run-time.  If you have a lot of intialized data, that process can take a long time - long enough for the watchdog timer to trip and reset the device - so it looks like you're always stuck in this routine. Try commenting out any large initialized arrays.

    You can also disable the watchdog by setting WD_DISABLE to 1 in this line of the file "F2837xD_CodeStartBranch.asm".

    WD_DISABLE  .set  0    ;set to 1 to disable WD, else set to 0

    If neither works, feel free to zip and attach your code to a post and I'll try to find it.

    Regards,

    Richard

  • Dear Richard ,

    Thanks for your immediate reply.

    The .cinit section holds initialized program variables which get copied into RAM at run-time.  If you have a lot of intialized data, that process can take a long time - long enough for the watchdog timer to trip and reset the device - so it looks like you're always stuck in this routine. Try commenting out any large initialized arrays.

    You can also disable the watchdog by setting WD_DISABLE to 1 in this line of the file "F2837xD_CodeStartBranch.asm".

    I tried removing unnecessary initialized data  and i also disabled watch Dog .

    Now some other problem is coming.

    It is getting stuck in below loop:

    #if (((defined(_INLINE) || defined(_MEMSET)) && \
    !(defined(_TMS320C6X) && !defined(__C6X_MIGRATION__))) && \
    !defined(__ARM_ARCH) && !defined(__ARP32__) && !defined(__FROZEN__))

    why is this happening ?

     

  • Impossible to say without seeing more of your code. Please zip and post your project and I'll take a look.  Thanks.

    Regards,

    Richard

  • Dear Richard

    Thanks for your support.

    Am really sorry . Actually i am in such a condition that i can not send you code publicly.

    Getting stuck in string.h problem gone now.

    I am proceeding forward  to add more code.

    I have to add more float datatype arrays. Each array contains 11 element .

    I have to use these arrays for interpolation.

    But problem is once i add even single array in working code "interrupt illegal operation handler() " is getting called . I dont know why.

    Is this is memory problem ?

    Am Adding screenshots of my program : commented array i want add in my program and i have shared screenshot of run mode of ccs after decommenting those arrays.

  • It could be a memory problem.  Illegal operations most often arise because an invalid opcode fetch or illegal memory access.  Check your array indexing to be sure you're not reading outside the range.  How many of these arrays do you have?

    Regards,

    Richard

  • 11 arrays i have (each array contains 11 element).

    Datatype of array is Float.

    If i keep 5 arrays code is working fine .

    once i keep all 11 arrays, its going in  "interrupt illegal operation handler() "

  • 242 words is not much. I doubt it's memory placement, but do look at the linker file, and look at the map file to be sure you know where the arrays are in memory. 

    I'm pretty sure the problem is in your code somewhere.  Please do check the array indexing as I suggested.  It's probably simple but I don't think I can offer more guidance without seeing the project or at least some of the code.

    Regards,

    Richard

  • Sorry to bother you.

    How to check map file for which  arrays are in the memory ?

    How to check array indexing ?

    I a really sorry for silly questions but i am having lots of doubt in my mind,

    I have attached RAM linker (converted in pdf) file, my main C code source file which are in my project and memory allocation for code.

    It looks like .stack and .text sections are full.

    Closed_Loop_All_Altitude.c
    //#############################################################################
    //
    // FILE:    Closed_Loop_Bangalore.c
    //
    // TITLE:   Capture ePWM3.
    //
    //! eCAP1 is configured to capture the time between rising edge of output.
    //!
    //! \b External \b Connections \n
    //! - eCAP1 is on GPIO16            // 100% speed is 1732Hz
    //! - GPIO1 for START / STOP CMD
    //  - GPIO6 for SR Relay        (DO)
    //  - GPIO7 for RL7(Fuel Ramp)  (DO)
    //  - GPIO8 for Ignition        (DO)
    //  - GPIO9 for Light Up        (DO)
    //  - ADC pin: ADCINA2 / ANALOGIN J3-09 for Exhaust gas temperature
    //  - ADC pin: ADCINB2 / ANALOGIN J3-08 for Input voltage
    //  - DAC pin: ADCINA0 / ANALOGIN(DACA) J3-10 for Output V to engine
    //  - GPIO43 is the SCI Rx pin
    //  - GPIO42 is the SCI Tx pin
    //
    // Included Files
    //
    
    #include "driverlib.h"
    #include "device.h"
    #include "functions.h"
    #include <stdio.h>
    #include "mpl3115a2_i2c.h"
    
    #define  Divider  22829389;
    //#define EX_ADC_RESOLUTION    12   //For 12bit ADC
    //
    // Globals
    uint16_t cpuTimer0IntCount;
    uint16_t IntCount;
    //uint32_t ecap1IntCount;
    uint16_t start;
    uint16_t IniTemp;
    uint16_t LightUp;
    uint16_t LUcount;
    int16_t Temperature;
    //uint16_t Serialcount;
    //uint16_t Toggle;
    
    char string[120]; // Array to store string from float value
    char *msg; // Pointer used to point String array to send data through SCIA
    
    float InputVoltage;       // For Storing ADC result   B3
    float Ex_Gas_Temp;       // For storing ADC result on B2
    float dacVal;             // For updating DAC output
    
    
    //float Lagout;           // Variable to use in speed data for closed loop
    float t1;              // To store all 3 ECAP Averaged event count
    float Speed;           // To store %speed
    // float V;              // Global closed output voltage variable to update DAC value
    //static float Iout, deltaT,Ipreout,preout2;
    static float Kp,Kp1,Kp2,Ni,Nd,Kd,Kt,Tl,Kk,V1,V2,Tt,EgtErr,Egtact,Keg1,VminL,T,Lagout,Nerr,Ndoth,Ndot,Ndotl,Ndacc,Nddcc,dZErr,Nact,Ki,Mlead,w,Ad,dV,Nki,Kint;
    
    
    float cap2Count;
    float cap3Count;
    float cap4Count;
    
    float Temperature1;
    float Pressure;
    uint32_t  Data[5];
    uint16_t counter;
    
    
    
    // Lookup Table for Closed Loop
      float S[]={0,10,20,30,40,50,60,70,80,90,100};
      float acc[]={6,6,1.5,1.5,1.5,1.5,6,6,6,6,6};
      float dcc[]={-8,-8,-8,-8,-8,-8,-8,-8,-8,-8,-8};
      float Vmax[]={0,1.5,1.6,1.8,2.37,3.3,3.9,4.5,5,5,5};
      float Vmin[]={1.5,1.5,1.5,1.5,1.5,2.2,2.47,2.7,3.2,3.5,4.4};
      //float T1[]={-55,-45,-35,-25,-15,-5,5,15,20,25,30};   //Inlet Temperature (T1)
      //float NiMax[]={87,88,90,92,93,96,98,100,100,100,100}; // Lookup table for Maximum demand speed with respect to Inlet Temperature (T1)
      //float P1array[]={1.47,2.793,4.116,5.439,6.762,8.085,9.849,10.731,12.054,13.377,14.7}; // Inlet Pressure (P1)
      //float NIdle[]={80,80,80,80,78,75,72,69,66,63,60}; //Lookup table for Idle speed with respect to inlet Pressure (P1)
      //float P3P1ratio[]={1,1,1,1.1131,1.1885,1.3770,1.5656,1.8295,2.1689,2.5837,3.2624};
      //float zeta[]={5,5,4,4,3.5,3,2.5,2.5,1.7,1,1};
    
    
    
      //
      // Function Prototypes
      //
    //void initI2C(void);
    //void initMPL3115A2(void);
    uint16_t readData();
    //uint16_t writeData(uint16_t RegAddress, int Data);
    __interrupt void i2cAISR(void);
    
    
    //
    // Function Prototypes
    //
    
    void error(void);
    //void initECAP(void);          // Function for Initializing ECAP
    __interrupt void ecap1ISR(void);
    
    //void initADCs(void);          // Function for Initializing ADC
    //void initADCSOCs(void);
    //void configureDAC(void);
    
    __interrupt void cpuTimer0ISR();
    //void configCPUTimer(uint32_t, float, float);
    //void initCPUTimers(void);
    
    
    
    /*float Lower_Win1(float *L);
    float Lower_Win2(float *Nt, float *Nl, float *Temp);
    float Lower_Win3(float *V1,float *V2 );
    float Higher_Win1(float *r1,float *r2);
    float adder_1(float *t, float *r);
    float adder_5(float *deltaV1);
    float Leadadder(float *t, float *r, float *z);
    float Diff(float *DifIn);
    float LeadDiff(float *DifIn);
    float EgtLeadDiff(float *DifIn);
    float Integral(float *I);
    float lag(float *s, int i);
    float intpol(float *x,float *y, float xd);
    */
    void Stopcmd(void);
    
    
    
    
    
    //
    // Main
    //
    void main(void)
    {
    
    
        //
        // Initialize device clock and peripherals
        //
        Device_init();
    
        //
        // Disable pin locks and enable internal pullups.
        //
        Device_initGPIO();
    
        //
               // Initialize GPIOs 32 and 33 for use as SDA A and SCL A respectively
               //
               GPIO_setPinConfig(GPIO_104_SDAA);
               GPIO_setPadConfig(104, GPIO_PIN_TYPE_PULLUP);
               GPIO_setQualificationMode(104, GPIO_QUAL_ASYNC);
    
               GPIO_setPinConfig(GPIO_105_SCLA);
               GPIO_setPadConfig(105, GPIO_PIN_TYPE_PULLUP);
               GPIO_setQualificationMode(105, GPIO_QUAL_ASYNC);
    
        //
        // Initialize PIE and clear PIE registers. Disables CPU interrupts.
        //
        Interrupt_initModule();
    
        //
        // Initialize the PIE vector table with pointers to the shell Interrupt
        // Service Routines (ISR).
        //
        Interrupt_initVectorTable();
    
    
    
    
    
           //
           // GPIO43 is the SCI Rx pin.
           //
           GPIO_setMasterCore(43, GPIO_CORE_CPU1);
           GPIO_setPinConfig(GPIO_43_SCIRXDA);
           GPIO_setDirectionMode(43, GPIO_DIR_MODE_IN);
           GPIO_setPadConfig(43, GPIO_PIN_TYPE_STD);
           GPIO_setQualificationMode(43, GPIO_QUAL_ASYNC);
    
           //
           // GPIO42 is the SCI Tx pin.
           //
           GPIO_setMasterCore(42, GPIO_CORE_CPU1);
           GPIO_setPinConfig(GPIO_42_SCITXDA);
           GPIO_setDirectionMode(42, GPIO_DIR_MODE_OUT);
           GPIO_setPadConfig(42, GPIO_PIN_TYPE_STD);
           GPIO_setQualificationMode(42, GPIO_QUAL_ASYNC);
    
        //
        // Configure GPIO4/5 as DO
        //
        GPIO_setPadConfig(41, GPIO_PIN_TYPE_STD);
        GPIO_setPinConfig(GPIO_41_GPIO41);
        GPIO_setDirectionMode(41, GPIO_DIR_MODE_OUT);
    
        GPIO_setPadConfig(1, GPIO_PIN_TYPE_PULLUP);    // GPIO1 for START / STOP CMD
        GPIO_setPinConfig(GPIO_1_GPIO1);
        GPIO_setDirectionMode(1, GPIO_DIR_MODE_IN);
    
        GPIO_setPadConfig(2, GPIO_PIN_TYPE_STD);
        GPIO_setPinConfig(GPIO_2_GPIO2);
        GPIO_setDirectionMode(2, GPIO_DIR_MODE_OUT);
    
        GPIO_setPadConfig(6, GPIO_PIN_TYPE_STD);    // GPIO6 for SR Relay  (DO)
        GPIO_setPinConfig(GPIO_6_GPIO6);
        GPIO_setDirectionMode(6, GPIO_DIR_MODE_OUT);
    
        GPIO_setPadConfig(7, GPIO_PIN_TYPE_STD);   // GPIO7 for RL7(Fuel Ramp)  (DO)
        GPIO_setPinConfig(GPIO_7_GPIO7);
        GPIO_setDirectionMode(7, GPIO_DIR_MODE_OUT);
    
        GPIO_setPadConfig(8, GPIO_PIN_TYPE_STD);   // GPIO8 for Ignition   (DO)
        GPIO_setPinConfig(GPIO_8_GPIO8);
        GPIO_setDirectionMode(8, GPIO_DIR_MODE_OUT);
    
        GPIO_setPadConfig(9, GPIO_PIN_TYPE_STD);   // GPIO9 for Light up Detection   (DO)
        GPIO_setPinConfig(GPIO_9_GPIO9);
        GPIO_setDirectionMode(9, GPIO_DIR_MODE_OUT);
    
    
        GPIO_writePin(41,0);
        GPIO_writePin(2,1);
    
        GPIO_writePin(6,0);  // SR Relay OFF
        GPIO_writePin(7,0);  // Fuel Relay (RL7) OFF
        GPIO_writePin(8,0);  // Ignition relay OFF
        GPIO_writePin(9,0);  // No light Up as system is starting
        //
        // Configure GPIO 16 as eCAP input
        //
        XBAR_setInputPin(XBAR_INPUT7, 16);
        GPIO_setPinConfig(GPIO_16_GPIO16);
        GPIO_setDirectionMode(16, GPIO_DIR_MODE_IN);
        GPIO_setQualificationMode(16, GPIO_QUAL_SYNC);
    
        //
        // Interrupts that are used in this example are re-mapped to ISR functions
        // found within this file.
        //
    
        Interrupt_register(INT_I2CA, &i2cAISR);
        Interrupt_register(INT_ECAP1, &ecap1ISR);
        Interrupt_register(INT_TIMER0, &cpuTimer0ISR);
    
    
    
    
        //
        // Configure ADC,ADCSOCs,DAC,eCAP,CPUTimer
        //
    
        initADCs();
        initADCSOCs();
    
        configureDAC();
        initI2C();
        initCPUTimers() ;
        initECAP();
    
    
        //
        // Initialize SCIA and its FIFO.
        //
        SCI_performSoftwareReset(SCIA_BASE);
    
        //
        // Configure SCIA for echoback.
        //
        SCI_setConfig(SCIA_BASE, DEVICE_LSPCLK_FREQ, 115200, (SCI_CONFIG_WLEN_8 |
                                                            SCI_CONFIG_STOP_ONE |
                                                            SCI_CONFIG_PAR_NONE));
        SCI_resetChannels(SCIA_BASE);
        SCI_resetRxFIFO(SCIA_BASE);
        SCI_resetTxFIFO(SCIA_BASE);
        SCI_clearInterruptStatus(SCIA_BASE, SCI_INT_TXFF | SCI_INT_RXFF);
        SCI_enableFIFO(SCIA_BASE);
        SCI_enableModule(SCIA_BASE);
        SCI_performSoftwareReset(SCIA_BASE);
    
    
    
    
        //
        // Initialize counters:
        //
        cap2Count = 0U;
        cap3Count = 0U;
        cap4Count = 0U;
       // ecap1IntCount = 0U;
        IntCount=0;
        cpuTimer0IntCount=0;
        start=0;
        LUcount=0;
        IniTemp=0;
        Temperature=0;
        //Toggle=1;
        //Serialcount=0;
    
        configCPUTimer(CPUTIMER0_BASE, DEVICE_SYSCLK_FREQ, 30000);
        //
        // Enable interrupts required for this example
        //
        Interrupt_enable(INT_I2CA);
        Interrupt_enable(INT_ECAP1);
        CPUTimer_enableInterrupt(CPUTIMER0_BASE);
        Interrupt_enable(INT_TIMER0);
    
    
        CPUTimer_startTimer(CPUTIMER0_BASE);
        while(1)
           {
               if(GPIO_readPin(1)==0)
               {
                   GPIO_writePin(6,1);  // SR Relay ON
                   GPIO_writePin(7,1);  // Fuel Relay (RL7) ON
                   GPIO_writePin(8,1);  // Ignition Relay ON
                   start=1;
                   break;
               }
    
           }
    
    
        //
        // Enable Global Interrupt (INTM) and Real time interrupt (DBGM)
        //
        EINT;
        ERTM;
    
        //initMPL3115A2();
    
        //
        // Loop forever. Suspend or place breakpoints to observe the buffers.
        //
        for(;;)
        {
    
    
            if(msgStatus == MSG_STATUS_SEND_NOSTOP)
            {
               while (writeData(CTRL_REG1, 0x29)!=SUCCESS) //OSR is 32, OST bit is 0
                {
    
                }
               while (writeData(CTRL_REG1, 0x2B)!=SUCCESS) //OSR is 32, OST bit is 1
                {
    
                }
    
               //
               // Send  address setup
               //
              while(readData() != SUCCESS)
               {
                 //
                 // Maybe setup an attempt counter to break an infinite
                 // while loop. The device will send back a NACK while it is
                 // performing a write operation.Even though the write
                 // is complete at this point, the Device could still be
                 // busy programming the data. Therefore, multiple
                 // attempts are necessary.
                 //
               }
    
              //
              // Update current message pointer and message status
              //
              msgStatus = MSG_STATUS_SEND_NOSTOP_BUSY;
    
            }
    
           else if(msgStatus == MSG_STATUS_RESTART)
             {
               //
               // Read data portion
               //
               while(readData() != SUCCESS)
               {
                   //
                   // Maybe setup an attempt counter to break an infinite
                   // while loop.
                   //
               }
    
               //
               // Update current message pointer and message status
               //
               msgStatus = MSG_STATUS_READ_BUSY;
    
             }
    
    
          t1=  (cap2Count+cap3Count+cap4Count)/3 ;
          if (t1==0)
          {
              t1=10*Divider;
          }
          Speed= (0.5/t1)*Divider;
    
          dacVal=(V*0.6*4095)/3;
          DAC_setShadowValue(DACA_BASE, dacVal); // Update DAC output value  pin: ADCINA0 / ANALOGIN(DACA) J3-10
                              //
                              // Convert, wait for completion, and store results
                              //
    
                              ADC_forceSOC(ADCA_BASE, ADC_SOC_NUMBER2);
                              ADC_forceSOC(ADCB_BASE, ADC_SOC_NUMBER2);
    
                              //
                              // Wait for ADCB to complete, then acknowledge flag
                              //
                              while(ADC_getInterruptStatus(ADCA_BASE, ADC_INT_NUMBER2) == false)
                                     {
                                     }
                              ADC_clearInterruptStatus(ADCA_BASE, ADC_INT_NUMBER2);
    
    
                              //
                              // Wait for ADCB to complete, then acknowledge flag
                              //
                               while(ADC_getInterruptStatus(ADCB_BASE, ADC_INT_NUMBER2) == false)
                                    {
                                    }
                               ADC_clearInterruptStatus(ADCB_BASE, ADC_INT_NUMBER2);
    
                              //
                              // Store results
                              //
                             Ex_Gas_Temp = ADC_readResult(ADCARESULT_BASE, ADC_SOC_NUMBER2); //pin: ADCINA2 / ANALOGIN J3-09
    
    
                              InputVoltage = ADC_readResult(ADCBRESULT_BASE, ADC_SOC_NUMBER2); //pin: ADCINB2 / ANALOGIN J3-08
    
                             LightUp=Ex_Gas_Temp;
    
                             if(Ex_Gas_Temp>0)
                             {
                                 if(LUcount==0)
                                 {
                                     IniTemp=Ex_Gas_Temp;
                                 }
                                 LUcount=1;
                             }
    
                             Temperature=LightUp-IniTemp;
    
    
    
    
        }
    }
    
    
    
    
    //
    // eCAP 1 ISR
    //
    __interrupt void ecap1ISR(void)
    {
        //
        // Get the capture counts. Each capture should be 4x the ePWM count
        // because of the ePWM clock dividers.
        //
        cap2Count = ECAP_getEventTimeStamp(ECAP1_BASE, ECAP_EVENT_2);
        cap3Count = ECAP_getEventTimeStamp(ECAP1_BASE, ECAP_EVENT_3);
        cap4Count = ECAP_getEventTimeStamp(ECAP1_BASE, ECAP_EVENT_4);
    
    
      //  ecap1IntCount++;
    
    
    
    
        //
        // Clear interrupt flags for more interrupts.
        //
        ECAP_clearInterrupt(ECAP1_BASE,ECAP_ISR_SOURCE_CAPTURE_EVENT_4);
        ECAP_clearGlobalInterrupt(ECAP1_BASE);
    
        //
        // Start eCAP
        //
        ECAP_reArm(ECAP1_BASE);
    
    
        //
        // Acknowledge the group interrupt for more interrupts.
        //
        Interrupt_clearACKGroup(INTERRUPT_ACK_GROUP4);
    }
    
    
    //
    // cpuTimer0ISR - Counter for CpuTimer0
    //
    __interrupt void cpuTimer0ISR(void)
    {
           /*  if (Toggle==1)
               {
                   GPIO_writePin(41,1);
                   Toggle=0;
               }
           */
    
    
    
    
               Kp=0.8;     //1.0;     //over all loop gain
               Ki=0.01;     // Over all integral gain cop-outer loop
    
              // Kf=0.4783;   // Engine Fuel system gain
             //  Ke=39.8888;  //Engine Fuel system gain
               Kd=0.2 ;
               Kp1=1;   //1.5;
               T=0.4 ;
             //  T2=1 ;
    
               //Kd2=0.1;
               Kp2=0.5;
            //   float P=0;  // To pass Zero value in function
    
             //  data1= Speed;
    
               //data2= Egtact;
               //sprintf(string, "\n speed:%.2f\t EGT:%.1f\t Nddcc:%.1f\t Nact:%.1f\t Ad:%.2f\t dV:%.3f\t V1:%.1f\t V2:%.1f\t V:%.1f  \n\0 ", Speed,Egtact,Nddcc,Nact,Ad,dV,V1,V2,V );
               //msg =string;
               //SCI_writeCharArray(SCIA_BASE, (uint16_t*)msg, 110);
    
    
       if(GPIO_readPin(1)==0)     // Wait for START command
          {
                if (start==0)
                {
                    GPIO_writePin(6,1);  // SR Relay ON
                    GPIO_writePin(7,1);  // Fuel Relay (RL7) ON
                    GPIO_writePin(8,1);  // Ignition Relay ON
                    start=1;
                }
    
             //  if(Serialcount==2)
                {
                  sprintf(string, "\n speed:%.2f\t Nd:%.1f\t EGT:%.1f\t Nddcc:%.1f\t Nact:%.1f\t Ad:%.2f\t dV:%.3f\t V1:%.1f\t V2:%.1f\t V:%.1f  \0 ", Speed,Nd,Egtact,Nddcc,Nact,Ad,dV,V1,V2,V );
                  msg =string;
                  SCI_writeCharArray(SCIA_BASE, (uint16_t*)msg, 110);
               //  Serialcount=0;
                 }
    
              // Serialcount++;
    
               cpuTimer0IntCount++;
    
               Ni= ((InputVoltage*40)/4095)+60;  //Input in percentage(Demand)
    
               Nd=Lower_Win1(&Ni);       //Limit demand Speed to 100%
    
               Lagout=Speed;             // Storing %Speed Signal
    
               Egtact=Ex_Gas_Temp*1000/2730; // Exhaust Gas Temperature conversion 2V as a 1000 degree celcious
    
               if(Lagout<50)
                 {
                    Tt=1000;
                 }
              else
                 {
                    Tt=900;
                 }
    
               EgtErr=adder_1(&Tt,&Egtact);
    
               Keg1=EgtErr*Kp2;
             //  Megt=Kd2*T2*EgtErr;
           //    Keg2=EgtLeadDiff(&Megt);
    
            //   Tegt1=Leadadder( &Keg1, &Keg2, &P);
             //  Tegt=lag(&Tegt1,1);
               Nerr =adder_1(&Nd,&Lagout);     //Error between Demanded speed and engine speed
               Ndot=Nerr*Kp;                   // Demanded Acceleration
    
    
               Ndotl=intpol(S,acc,Lagout);     // Interpolation for acceleration
    
               Ndacc=Lower_Win2( &Ndot,&Ndotl,&Keg1);   // Limit demand acceleration to 2% till Engine speed reaches to 50% then Limit to 6%
    
               Ndoth=intpol(S,dcc,Lagout);        // Interpolation for deceleration
    
               Nddcc=Higher_Win1(&Ndacc,&Ndoth);
               Nact= Diff(&Lagout);               // Actual Acceleration
             //  Tegt=lag(&Nact,1);
               dZErr=adder_1(&Nddcc,&Nact);       // Delta Zero Error
               Kk=Kp1*dZErr;
               Mlead=Kd*T*dZErr;
               Kt=LeadDiff(&Mlead);
               Nki=Ki*dZErr;
               Kint=Integral(&Nki);
    
               Ad=Leadadder(&Kk, &Kt, &Kint);    // Lead function output
               Tl= lag(&Ad,2);                   // lag at the output of lead function
               dV=(Tl*0.03);
               V1=adder_5(&dV);
               V2= intpol(S,Vmax,Lagout);       // Interpolation for Ramp output according to speed
    
               w= Lower_Win3( &V1,&V2 );       //Lower Win for V1 & V2
    
               VminL=intpol(S,Vmin,Lagout);
    
               if (Temperature<=150)
               {
                   V=1.5;
                   GPIO_writePin(9,0);
               }
               else
               {
                   V=Higher_Win1(&w,&VminL);
                   GPIO_writePin(9,1);
               }
    
               IntCount++;
               if(IntCount>=1 && IntCount<=40)
               {
                   preout2=0;
                   Ipreout=0;
               }
    
               if(cpuTimer0IntCount>=500)
               {
                   GPIO_writePin(8,0);    // Ignition OFF after 15sec
               }
    
    
          }
    
       else
       {
           Stopcmd();
       }
    
              /*  if (Toggle==0)
                {
                    GPIO_writePin(41,0);
                    Toggle=1;
                }
             */
    /*
        //DEVICE_DELAY_US(10000);
    
        if(cpuTimer0IntCount==1)
        {
            GPIO_writePin(0,1);
            cpuTimer0IntCount=0;
        }
        else if (cpuTimer0IntCount==0)
        {
            GPIO_writePin(0,0);
            cpuTimer0IntCount++;
        }
    */
        //
        // Acknowledge this interrupt to receive more interrupts from group 1
        //
        Interrupt_clearACKGroup(INTERRUPT_ACK_GROUP1);
    
    }
    
    
    //
    // error - Error function
    //
    void error()
    {
        ESTOP0;
    }
    
    void Stopcmd(void)
    {
        V=0;
        GPIO_writePin(6,0);  // SR Relay OFF
        GPIO_writePin(7,0);  // Fuel Relay (RL7) OFF
        GPIO_writePin(8,0);  // Ignition relay OFF
        GPIO_writePin(9,0);  // No light Up detection due to engine off
        IntCount=0;
        cpuTimer0IntCount=0;
       // Serialcount=0;
        start=0;
        LUcount=0;
    
    
    }
    
    
    //
    // readData - Function to prepare for the data that is to be read from the device
    //
    uint16_t
    readData()
    {
        //
        // Wait until the STP bit is cleared from any previous master
        // communication. Clearing of this bit by the module is delayed until after
        // the SCD bit is set. If this bit is not checked prior to initiating a new
        // message, the I2C could get confused.
        //
        if(I2C_getStopConditionStatus(I2CA_BASE))
        {
            return(ERROR_STOP_NOT_READY);
        }
    
        //
        // Setup slave address
        //
        I2C_setSlaveAddress(I2CA_BASE, SLAVE_ADDRESS);
    
        //
        // If we are in the the address setup phase, send the address without a
        // stop condition.
        //
        if(msgStatus == MSG_STATUS_SEND_NOSTOP)
        {
            //
            // Check if bus busy
            //
            if(I2C_isBusBusy(I2CA_BASE))
            {
                return(ERROR_BUS_BUSY);
            }
    
            //
            // Send data to setup data address
            //
            I2C_setDataCount(I2CA_BASE, 1);
           // I2C_putData(I2CA_BASE, msg->readAddress);
            I2C_putData(I2CA_BASE, OUT_P_MSB);
           // I2C_putData(I2CA_BASE, 0x01 );
           // I2C_putData(I2CA_BASE, msg->outPcsb);
            //I2C_putData(I2CA_BASE, msg->outPlsb);
    
            I2C_setConfig(I2CA_BASE, I2C_MASTER_SEND_MODE);
            I2C_sendStartCondition(I2CA_BASE);
    
            //currentMsgPtr->msgStatus = MSG_STATUS_RESTART;
    
        }
        else if(msgStatus == MSG_STATUS_RESTART)
        {
            //
            // Address setup phase has completed. Now setup how many bytes expected
            // and send restart as master-receiver.
            //
            I2C_setDataCount(I2CA_BASE, NUM_BYTES);
            I2C_setConfig(I2CA_BASE, I2C_MASTER_RECEIVE_MODE);
            I2C_sendStartCondition(I2CA_BASE);
            I2C_sendStopCondition(I2CA_BASE);
    
            //currentMsgPtr->msgStatus = MSG_STATUS_SEND_NOSTOP;
    
        }
    
        return(SUCCESS);
    }
    
    
    //
    // i2cAISR - I2C A ISR (non-FIFO)
    //
    __interrupt void
    i2cAISR(void)
    {
        I2C_InterruptSource intSource;
        uint16_t i;
    
    
       // currentMsgPtr = &i2cMsgIn;
    
    
        //
        // Read interrupt source
        //
        intSource = I2C_getInterruptSource(I2CA_BASE);
    
        //
        // Interrupt source = stop condition detected
        //
        if(intSource == I2C_INTSRC_STOP_CONDITION)
        {
    
             if(msgStatus == MSG_STATUS_SEND_NOSTOP_BUSY)
    
              {
                msgStatus = MSG_STATUS_SEND_NOSTOP;
              }
    
             else if(msgStatus == MSG_STATUS_READ_BUSY)
    
              {
                   msgStatus = MSG_STATUS_SEND_NOSTOP ;
    
                    for(i=0; i < NUM_BYTES; i++)
                    {
    
                        Data[i]=I2C_getData(I2CA_BASE);
    
                    }
    
              Pressure = (float) (((Data[0] << 16) | (Data[1] << 8) | (Data[2] & 0xC0)) >> 6) + (float) ((Data[2] & 0x30) >> 4) * 0.25;
              Temperature1= (float) ((short)((Data[3] << 8) | (Data[4] & 0xF0)) >> 4) * 0.0625;
                //Pressure1= (long) ((Data[0]<<16) | (Data[1]<<8 ) | (Data[2] ) )  ;
                //Pressure1 >>=6;
                // Pressure=(Pressure1*0.25);
              }
    
        }
        //
        // Interrupt source = Register Access Ready
        //
        // This interrupt is used to determine when the device address setup
        // portion of the read data communication is complete. Since no stop bit
        // is commanded, this flag tells us when the message has been sent
        // instead of the SCD flag.
        //
        else if(intSource == I2C_INTSRC_REG_ACCESS_RDY)
        {
            //
            // If a NACK is received, clear the NACK bit and command a stop.
            // Otherwise, move on to the read data portion of the communication.
            //
            if((I2C_getStatus(I2CA_BASE) & I2C_STS_NO_ACK) != 0)
            {
                I2C_sendStopCondition(I2CA_BASE);
                I2C_clearStatus(I2CA_BASE, I2C_STS_NO_ACK);
            }
    
            else if(msgStatus == MSG_STATUS_SEND_NOSTOP_BUSY)
                    {
                        msgStatus = MSG_STATUS_RESTART;
                    }
    
        }
        else
        {
            //
            // Generate some error from invalid interrupt source
    
            asm("   ESTOP0");
        }
    
        //
        // Issue ACK to enable future group 8 interrupts
        //
        Interrupt_clearACKGroup(INTERRUPT_ACK_GROUP8);
        counter++;
    }
    
    
    

     ram.pdf

  • Thanks for sending the information, and no problem for asking these questions.

    Your linker command file looks fine. You can optionally tell the linker to generate a ".map" file if it completes successfully. You can name the file under 'Project->Properties->CCS Build->C2000 Linker->Basic Options'. It's a text file you can open in the editor to see what symbols get linked where, and how much of each memory block is used. Your arrays should end up in the .ebss section, which from the memory allocation I think is happening.

    By the way, if you want to map a particular variable into a specific memory block, you can use the DATA_SECTION pragma to do so. Check section 6.10 of the C compiler guide (spru514) for more information on that.

    I can't see from the code how you are using your arrays, but what I mean by checking array indexing is be sure you're not accidentally trying to access an element beyond the valid range. For example, an 11 element array might be:
    float a[11];

    If you access an element using...
    x = a[i];
    ...then i must be in the range 0 to 10. It must never be 11 or higher or you may end up in invalid memory causing the ESTOP you're seeing. I suggest stepping through your code to satisfy yourself that never happens.

    I'm not seeing anything obvious in the code which might cause this. Can you post the map file too please?

    Regards,

    Richard

  • Yes Richard.  I am not trying to access an element beyond the valid range of an array in my program.

    I found one problem with stack memory.

    In my code i am using sprintf() which needs more stack memory. I think that is the one culprit causing error.

    when i commented sprint() function code is working fine.

    Now question is how to add more memory for .stack section. I have already allocated  RAMGS13     : origin = 0x019000, length = 0x001000 memory for stack and I have incresed C system stack size to 0x1000 in 'Project->Properties->CCS Build->C2000 Linker->Basic Options -> Set C system stack size'.

    In RAM_lnk_cpu1.cmd file there is RAMGS14     : origin = 0x01A000, length = 0x001000 present which is nowhere used.

    I want combine these two memory. So that i will allocate more memory to .stack section.   

  • A stack overflow makes sense, but you can't allocate the stack there.  On C28x the stack pointer is only 16-bits in width so your .stack section has to live in memory below 0x10000.  It's going to be a matter of juggling the other sections to find a contiguous block larger than 0x400 for the stack.

    Regards,

    Richard

  • I have attached memory .map file of my code. In that module summary Grand Total is 10270 .

    You said "On C28x the stack pointer is only 16-bits in width so your .stack section has to live in memory below 0x10000" i did not get this statement.
    I have to use sprintf() function, i am using it for SCI. I am sending 10 parameters using SCI to computer so that i can store them.

    Is there any way to overcome this problem ?

    MemoryMap.pdf

  • In the linker command file you sent earlier, you have these lines:

    RAMGS13 : origin = 0x019000, length = 0x001000

    ...

    .stack : > RAMGS13, PAGE = 1

    I'm saying you can't put the .stack section in memory range with higher than 0xFFFF.  The stack uses a pointer which is only 16-bits in length so it's not reachable.  This is your problem.

    One way to fix this is to move your SDFM filter sections to higher memory addresses and put .stack in RAMGS2, for example:

    .stack : > RAMGS2, PAGE = 1

    Filter1_RegsFile : > RAMGS5, PAGE = 1, fill=0x1111

    Filter2_RegsFile : > RAMGS6, PAGE = 1, fill=0x2222 

    Filter3_RegsFile : > RAMGS7, PAGE = 1, fill=0x3333

    Filter4_RegsFile : > RAMGS8, PAGE = 1, fill=0x4444

    Difference_RegsFile : >RAMGS9, PAGE = 1, fill=0x3333

    Regards,

    Richard

  • Dear Richard

    1000 Thanks to You.

    Moving SDFM filter to higher memory addresses and putting .stack to RAMGS2, Worked for my program.

    Again thanks for giving patiently answers .