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/TMS320F28377S: Values of some expressions are not updating while running the code.

Part Number: TMS320F28377S

Tool/software: Code Composer Studio

The values of some expressions are not updating. I have debugged a code in CCS, the values of expression were updating till yesterday. Now, the values of all the expression are updating but two values are still 0. I am attaching the screenshot. I have read similar earlier post but that program has some error. This program has no error and I have not made any changes too.

  • Also Pa is Va*Ia and Pa1 is the previous value of Pa.
  • Hello,
    Without a reproducible test case, it is very difficult to provide any answers. Please provide one (source files and executable). Also, please let me know which exact version of CCS you are using.

    Thanks
    ki
  • I am using CCS7.2. I am attaching the file.5037.ccs.rar

    //###########################################################################
    //
    // FILE:   adc_soc_epwm_cpu01.c
    //
    // TITLE:  ADC triggering via epwm for F2837xS.
    //
    //! \addtogroup cpu01_example_list
    //! <h1> ADC ePWM Triggering (adc_soc_epwm)</h1>
    //!
    //! This example sets up the ePWM to periodically trigger the ADC.
    //!
    //! After the program runs, the memory will contain:\n
    //! - \b AdcaResults \b: A sequence of analog-to-digital conversion samples from
    //! pin A0. The time between samples is determined based on the period
    //! of the ePWM timer.
    //
    //###########################################################################
    // $TI Release: F2837xS Support Library v210 $
    // $Release Date: Tue Nov  1 15:35:23 CDT 2016 $
    // $Copyright: Copyright (C) 2014-2016 Texas Instruments Incorporated -
    //             http://www.ti.com/ ALL RIGHTS RESERVED $
    //###########################################################################
    
    //
    // Included Files
    //
    #include "F28x_Project.h"
    
    
    
    // Function Prototypes
    //
    void ConfigureADC(void);
    void ConfigureEPWM(void);
    void SetupADCEpwm(Uint16 channel);
    
    
    //
    // Defines
    //
    #define FL 65536
    #define zsum 1.2
    #define zp 0.32
    #define p1 0.04321
    #define Kp 0.1
    //
    // Globals
    //
    //Uint16 AdcaResults[RESULTS_BUFFER_SIZE];
    //Uint16 resultsIndex;
    
    float Err2;
    float Err;
    float two;
    float Err1;
    float Dn;
    float Dn1;
    float Dn2;
    float one;
    float Ia;
    float Id;
    float Va;
    float Vac;
    float Iac;
    float Va1;
    float Vd;
    float Pa;
    float Pa1;
    float Dnf;
    Uint16 CMPduty;
    
    //volatile Uint16 bufferFull;
    //
    void main(void)
    {
    //
    // Step 1. Initialize System Control:
    // PLL, WatchDog, enable Peripheral Clocks
    // This example function is found in the F2837xS_SysCtrl.c file.
    //
        InitSysCtrl();
    
    //
    // Step 2. Initialize GPIO:
    // This example function is found in the F2837xS_Gpio.c file and
    // illustrates how to set the GPIO to it's default state.
    //
        InitGpio(); // Skipped for this example
    
    //
    // Step 3. Clear all interrupts and initialize PIE vector table:
    // Disable CPU interrupts
    //
        DINT;
    
    //
    // Initialize the PIE control registers to their default state.
    // The default state is all PIE interrupts disabled and flags
    // are cleared.
    // This function is found in the F2837xS_PieCtrl.c file.
    //
        InitPieCtrl();
    
    //
    // Disable CPU interrupts and clear all CPU interrupt flags:
    //
        IER = 0x0000;
        IFR = 0x0000;
    
    //
    // Initialize the PIE vector table with pointers to the shell Interrupt
    // Service Routines (ISR).
    // This will populate the entire table, even if the interrupt
    // is not used in this example.  This is useful for debug purposes.
    // The shell ISR routines are found in F2837xS_DefaultIsr.c.
    // This function is found in F2837xS_PieVect.c.
    
    
    
        InitPieVectTable();
        CpuSysRegs.PCLKCR2.bit.EPWM2=1;
        EALLOW;
        ClkCfgRegs.SYSCLKDIVSEL.bit.PLLSYSCLKDIV=0;
        ClkCfgRegs.PERCLKDIVSEL.bit.EPWMCLKDIV=0;
        EDIS;
    
    
    // Configure the ADC and power it up
    //
        ConfigureADC();
    
    //
    // Configure the ePWM
    //
        ConfigureEPWM();
          // Interrupt where we will change the Compare Values
          //
        EALLOW;
          EPwm2Regs.ETSEL.bit.INTSEL = ET_CTR_ZERO;       // Select INT on Zero event
          EPwm2Regs.ETSEL.bit.INTEN = 1;                  // Enable INT
          EPwm2Regs.ETPS.bit.INTPRD = 1;             // Generate INT on 3rd event
       EDIS;
    //
    // Setup the ADC for ePWM triggered conversions on channel 0
    //
        SetupADCEpwm(0);
    
        EALLOW;
    
            //
            // Disable internal pull-up for the selected output pins
            // for reduced power consumption
            // Pull-ups can be enabled or disabled by the user.
            // This will enable the pullups for the specified pins.
            // Comment out other unwanted lines.
            //
            GpioCtrlRegs.GPAPUD.bit.GPIO2 = 1;    // Disable pull-up on GPIO2 (EPWM2A)
            GpioCtrlRegs.GPAPUD.bit.GPIO3 = 1;    // Disable pull-up on GPIO3 (EPWM2B)
    
    
            //
            // Configure EPwm-2 pins using GPIO regs
            // This specifies which of the possible GPIO pins will be EPWM2 functional pins.
            // Comment out other unwanted lines.
            //
            GpioCtrlRegs.GPAMUX1.bit.GPIO2 = 1;   // Configure GPIO2 as EPWM2A
            GpioCtrlRegs.GPAMUX1.bit.GPIO3 = 1;   // Configure GPIO3 as EPWM2B
    
    
            EDIS;
    // Enable global Interrupts and higher priority real-time debug events:
    //
        IER |= M_INT1; //Enable group 1 interrupts
        EINT;  // Enable Global interrupt INTM
        ERTM;  // Enable Global realtime interrupt DBGM
    //
    // enable PIE interrupt
    //
        PieCtrlRegs.PIEIER1.bit.INTx1 = 1;
    
    //
    // sync ePWM
    //
        EALLOW;
        CpuSysRegs.PCLKCR0.bit.TBCLKSYNC = 1;
    
    
            //start ePWM
            //
            EPwm2Regs.ETSEL.bit.SOCAEN = 1;  //enable SOCA
            EPwm2Regs.TBCTL.bit.CTRMODE = 0; //unfreeze, and enter up count mode
    
            do
                      {
                              EALLOW;
    
                              Err2=Err1;
                              Err1=Err;
                              Dn2=Dn1;
                              Dn1=Dn;
                              Pa1=Pa;
                              Va1=Va;
                            //AdcaRegs.ADCPPB1CONFIG.bit.CONFIG=0;
                          // AdcaRegs.ADCPPB1CONFIG.bit.TWOSCOMPEN=0; //Change the sign
                          // AdcaRegs.ADCPPB1OFFREF=0; // Subtract 0.55 V from the result at pin A0 and A1.
    
                          // AdcaRegs.ADCPPB2CONFIG.bit.CONFIG=4;
                          // AdcaRegs.ADCPPB2CONFIG.bit.TWOSCOMPEN=0; //Change the sign
                          // AdcaRegs.ADCPPB2OFFREF=0; // Subtract 0.55 V from the result at pin A0 and A1.
    
                           Vd=AdcaResultRegs.ADCRESULT0;
                           Vac=3*((2*Vd/65536)-1);
                           Va=10*Vac;
                           Id=AdcaResultRegs.ADCRESULT4;
                           Iac=3*((2*Id/65536)-1);
                           Ia=(Iac-0.0585)/0.4352;
                           Pa=Va*Ia;
                           if (Pa>Pa1)
                           {
                               if (Va>Va1)
                               {
                                   Dn=Dn1-0.00002;
                               }
                               else if(Va<Va1)
                               {
                                   Dn=Dn1+0.00002;
                               }
                               else
                               {
                                   Dn=Dn1;
                               }
                           }
                           if (Pa<Pa1)
                           {
                               if (Va>Va1)
                                                         {
                                                             Dn=Dn1+0.00002;
                                                         }
                                                         else if(Va<Va1)
                                                         {
                                                             Dn=Dn1-0.00002;
                                                         }
                                                         else
                                                         {
                                                             Dn=Dn1;
                                                         }
                           }
                           if (Pa=Pa1)
                           {
                               Dn=Dn1;
                           }
    //                       Err=0.24-(Va);
    //                      Dn=(p1+1)*Dn1-(p1*Dn2)+(Kp*Err)-(Kp*(zsum)*Err1)+(Kp*zp*Err2);
                           if(Dn>0.85)
                           {
                               Dn=0.85;
                           }
                           else if(Dn<0.15)
                           {
                               Dn=0.15;
                           }
                           else
                           {
                               Dn=Dn;
                           }
                           Dnf=0.5;
                           CMPduty=(199*Dn);
                           EPwm2Regs.CMPA.bit.CMPA = CMPduty ;
                              EDIS;
    
    
    
                      } while(1);
    //
    // ConfigureADC - Write ADC configurations and power up the ADC for both
    //                ADC A and ADC B
    //
    } void ConfigureADC(void)
    {
        EALLOW;
    
        //
        //write configurations
        //
        AdcaRegs.ADCCTL2.bit.PRESCALE = 0x0000; //set ADCCLK divider to 200MHz/1
        AdcSetMode(ADC_ADCA, ADC_RESOLUTION_12BIT, ADC_SIGNALMODE_SINGLE);
    
        //
        //Set pulse positions to late
        //
        AdcaRegs.ADCCTL1.bit.INTPULSEPOS = 1;
    
        //
        //power up the ADC
        //
        AdcaRegs.ADCCTL1.bit.ADCPWDNZ = 1;
    
        //
        //delay for 1ms to allow ADC time to power up
        //
        DELAY_US(1000);
    
        EDIS;
    }
    
    //
    // ConfigureEPWM - Configure EPWM SOC and compare values
    //
    void ConfigureEPWM(void)
    {
        EALLOW;
        // Assumes ePWM clock is already enabled
        EPwm2Regs.ETSEL.bit.SOCAEN    = 1;    // Enable SOC on A group
        EPwm2Regs.ETSEL.bit.SOCASEL    = 4;   // Select SOC when CMPA equal to TBPRD
        EPwm2Regs.ETPS.bit.SOCAPRD = 1;       // Generate pulse on 1st event
            // Set compare A value to 2048 counts
        EPwm2Regs.TBPRD = 199;             // Set period to 65536 counts
        EPwm2Regs.TBCTL.bit.CTRMODE = 0;      // up counter
    
        EPwm2Regs.TBCTL.bit.CTRMODE = TB_COUNT_UP; // Count up
        EPwm2Regs.TBCTL.bit.PHSEN = TB_DISABLE;    // Disable phase loading
        EPwm2Regs.TBPHS.bit.TBPHS = 0x0000;        // Phase is 0
        EPwm2Regs.TBCTR = 0x0000;                  // Clear counter
        EPwm2Regs.TBCTL.bit.HSPCLKDIV = 0;   // Clock ratio to SYSCLKOUT
        EPwm2Regs.TBCTL.bit.CLKDIV = 0;
        // Set actions
    
      EPwm2Regs.AQCTLA.bit.PRD = AQ_CLEAR;            // Clear PWM2A on Period
      EPwm2Regs.AQCTLA.bit.CAU = AQ_SET;              // Set PWM2A on event A,
      // Interrupt where we will change the Compare Values
            //
            EPwm2Regs.ETSEL.bit.INTSEL = 4;       // Select INT on Zero event
            EPwm2Regs.ETSEL.bit.INTEN = 1;                  // Enable INT
            EPwm2Regs.ETPS.bit.INTPRD = 01;             // Generate INT on every event          // up count
        EDIS;
    }
    
    
    // SetupADCEpwm - Setup ADC EPWM acquisition window
    //
    void SetupADCEpwm(Uint16 channel)
    {
        Uint16 acqps;
    
        //
        //determine minimum acquisition window (in SYSCLKS) based on resolution
        //
        if(ADC_RESOLUTION_12BIT == AdcaRegs.ADCCTL2.bit.RESOLUTION)
        {
            acqps = 14; //75ns
        }
        else //resolution is 16-bit
        {
            acqps = 79; //320ns
        }
    
        //
        //Select the channels to convert and end of conversion flag
        //
        EALLOW;
        AdcaRegs.ADCSOC0CTL.bit.CHSEL = channel;  //SOC0 will convert pin A0
        AdcaRegs.ADCSOC0CTL.bit.ACQPS = acqps; //sample window is 100 SYSCLK cycles
        AdcaRegs.ADCSOC0CTL.bit.TRIGSEL = 7; //trigger on ePWM2 SOCA/C
        AdcaRegs.ADCINTSEL1N2.bit.INT1SEL = 0; //end of SOC0 will set INT1 flag
        AdcaRegs.ADCINTSEL1N2.bit.INT1E = 1;   //enable INT1 flag
        AdcaRegs.ADCINTFLGCLR.bit.ADCINT1 = 1; //make sure INT1 flag is cleared
        AdcaRegs.ADCSOC4CTL.bit.CHSEL = 4;  //SOC1 will convert pin A2 and A3
            AdcaRegs.ADCSOC4CTL.bit.ACQPS = acqps; //sample window is 100 SYSCLK cycles
            AdcaRegs.ADCSOC4CTL.bit.TRIGSEL = 7; //trigger on ePWM2 SOCA/C
            AdcaRegs.ADCINTSEL1N2.bit.INT2SEL = 1; //end of SOC1 will set INT1 flag
            AdcaRegs.ADCINTSEL1N2.bit.INT2E = 4;   //enable INT2 flag
            AdcaRegs.ADCINTFLGCLR.bit.ADCINT2 = 1; //make sure INT2 flag is cleared
        EDIS;
    }
    
    // End of file
    //
    

  • Ashima Kulshreshtha said:
    the values of expression were updating till yesterday. Now, the values of all the expression are updating but two values are still 0.

    Did you make code modifications to adc_soc_epwm_cpu01.c and after that it stopped working? It looks like there is bug on line 248 of the code. You likely meant:

    if (Pa==Pa1)

    Thanks

    ki

  • Thanks Ki, it was a bug. How to identify that there is a bug in that line, as i didn't see any symbol on line 248?
  • There is nothing wrong syntax-wise, hence you would not see any notification. You would just need to use the debugger to manually step through and analyze the code (which is what I did). Watchpoints that watch for writes to those variables in question would have also worked.