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.

TMS320F28335 Compiler CCSv3.3

Hallo,

I use Code generation tools v5.2.11!

if I remove the volatile in this function, I got errors in calculating from time to time.

It must be the for slope?

static doesn't work!

Any idea? Stack problem?

Of cause all variables are not in use outside of this function.

float32 FilterLinReg (objMavg *p, float32 p_fDataX, float32 p_fDataY)
{
    volatile Uint16 i, j, k;
    volatile float32 fSumX, fSumY, fSumXx, fSumXy;
    fSumX = fSumY = fSumXy = fSumXx = 0.0;
    // check if memory is complete and mark as FULL
    if (p->uK >= p->uN)
    {
        p->uK    = 0;
        p->fFull = FILTER_FULL;
    }
    // store actual value to next position
    *(p->pfData + p->uK) = p_fDataY;
    // index to next position
    p->uK++;


    // regression length at start is shorter
    if (p->fFull == FILTER_FULL)
    {
        j = p->uN;
        // filter full, start at uK value
        k = p->uK;
    }
    else
    {
        j = p->uK;
        // filter not full, start at 0 value
        k = 0;
    }

    // calculate REGRESSION sums over the actual memory
    if( j>1)
    {
        for(i = 0; i <= (j-1); i++)
        {
            if(k >= p->uN)
                k=0;
            // sum of all y values
            // 23.02.16 bug ??? fSumY += *(p->pfData + i);
            fSumY += *(p->pfData + k);
            // sum of all x values
            fSumX += (i) * p_fDataX;
            // sum of all y * x values
            fSumXy += *(p->pfData + k) * ((i) * p_fDataX);
            // sum of all x² values    
            fSumXx += ((i) * p_fDataX) * ((i) * p_fDataX);
            k++;
        }
        // calculate regression y = a + bx, at the moment only b
        p->fY = (fSumXy-((fSumX*fSumY)/(float)j)) / (fSumXx-((fSumX*fSumX)/(float)j));
         }
    else
    {
        p->fY = 0.0;
    }
    return p->fY;
    //return fSumX;
}



/*!
\fn    void FiltLinRegInit(objMavg *p, float32 *data, const Uint16 n)
\brief Initilisation of Linear Regression with up to 2^16 values.
                   
\author    R. Koester
\date        27.01.2016
\param[in]  *p - pointer to filter object
            data - adress of data buffer
            n - length of data buffer
\return    void

\details Changes:

*/
void FiltLinRegInit(objMavg *p, float32 *data, const Uint16 n)
{
    // set Buffer pointer to data array
    p->pfData = data;
    // store number of values (size of dataarray)
    p->uN    = n;
    // reset data array to 0.0
    for (p->uK = 0; p->uK < p->uN; p->uK++)
    {
        *(p->pfData + p->uK) = ((float32) 0.0);
    }
    // delete actual counter, sum and Full semaphore
    p->uK    = ((Uint32) 0);
    //p->fSum  = ((float32) 0.0);
    p->fFull = ((Uint16) 0);
}

  • Ralf Koester said:
    if I remove the volatile in this function, I got errors in calculating from time to time.

    I agree the volatile keyword is not necessary to get correct execution of this code.  Please describe exactly what you see when things go wrong.  How do you see it?  That "time to time" wording concerns me.  Software problems usually occur every time.  Could this be a hardware problem?

    Thanks and regards,

    -George

  • Also tell us your exact command-line options.
  • Hallo,
    from time to time means diificult to debug, but I've found, that the "for" slope which is calculating a linear regression.
    "j" is always 25 after 25 times calling this function (all 2 ms).
    I've tried to stop the µC when having wrong calculations with a breakpoint and it seems, that the "for" slope ended before 25 rounds.
    Could this a compiler or stack problem?

    Command-line:
    "C:\Program Files (x86)\Texas Instruments\C2000 Code Generation Tools 5.2.11\bin\cl2000" -pm -pdsw225 -adRAM=0 -op3 -o3 -fr"C:/projekte/092-0045DFT/2833x_FLASH" -i"C:/projekte/092-0045DFT/src/include" -d"_DEBUG" -d"LARGE_MODEL" -d"FLASH" -ml -v28 --float_support=fpu32 -mf5 -mo -@"F2833x_FLASH.lkf"

    br
    Ralf
  • Ralf Koester said:
    that the "for" slope which is calculating a linear regression.

    I'm sorry, but I'm not sure what you mean.  Please state in terms like "variable j has the value NNN, when it should be MMM."  And say exactly how you see it.  Are you looking at variables in the watch window in CCS?  Or what?

    Thanks and regards,

    -George

  • Hallo Gorge,

    sorry for the undetailed information. The info about "j" should only discribe that j is not important, because always 25.

    (only the first 24 calls j is slower, the error appears later when j is always 25).

    I use breakpoints to stop and see what the variables are, yes in the Watch window.

    Ralf

  • Hello Ralf,

    I am not sure what is causing your issue, however, maybe you should try the following (try #2 first).  You could also first check to see if your stack is large enough by filling the upper half of your stack with zeros (using the memory window after entering main) .  Then watch the stack in the memory window to see how much the stack gets filled

    1. Set your stack as large as you can set it.  For example, In the linker command file define:

    MEMORY
    {
    PAGE 0 :
    
     ...
    
      RAMM0M1    : origin = 0x000050, length = 0x0007B0,
    ...
    
    }
    
    SECTIONS
    {
    
    ....
    
    .stack           : > RAMM0M1,         PAGE = 0
    
    ,..
    
    }

    2. Create a C structure that contains variables that can store debugging information.  Do something like the following.  Then call place the DEBUG_IT throughout your code.

    typedef
    {
        unsigned int j;
        float fSumX;
        ...
    } DEBUG_INFO;
    
    #define DEBUG_INFO_SIZE  1000
    
    DEBUG_INFO DebugInfo[DEBUG_INFO_SIZE  ];
    
    unsigned long debugIndex = 0;
    
    #define DEBUG_IT \
     DebugInfo[debugIndex].j = j; \
     DebugInfo[debugIndex].fSumX = fSumX \
     ... \
     debugIndex = (debugIndex++)%DEBUG_INFO_SIZE;
     
     
     
    
    Stephen

  • Ralf Koester said:
    (only the first 24 calls j is slower, the error appears later when j is always 25).

    There is still no clear description of the error.

    Thanks and regards,

    -George

  • Hello,

    I created a project file for you that you can use to test your code.  It reads data from a text file, calls your functions and outputs relevant data to a text file.

    You'll have to modify main.c and the project properties to fit your problem.  Also, the target configuration file uses the simulator (which is in CCSv5.5).  The simulator can be ported to CCS6 (See Jan6,2016 of 

    https://e2e.ti.com/support/development_tools/code_composer_studio/f/81/p/339132/1611955#1611955

    )

    TestForumCode.zip

    Stephen