0

I am using Code Composer Studio to work with an MSP430 MCU. These are the specs that I am working with:

  • CCS version: 5.5

  • Compiler version: TI v4.1.9

  • Compiler Optimization Settings: Optimization = 0

  • MSP430: MSP430F5528

I'm starting with a working device and adding a new function to calculate the standard deviation of an array of measurements. The device has been working completely fine until I added the sqrt function in the below code:

double standardDeviation (int average, int measurements[], int positions){     
    double deviation = 0;
    int i = 0;

    for(i = 0; i <= positions; i++){
        measurements[i] = measurements[i] - average;
        measurements[i] = measurements[i] * measurements[i];
        deviation += measurements[i];
    }

    deviation = deviation/positions;
    deviation = sqrt(deviation);

    return deviation;

}

Also, I have #include <math.h> at the header of my file.

When I comment out the line with sqrt, the device works as expected. The Inputs and outputs and array values are all working perfectly. The signalling LEDs are as they should be and I can see the array values while in debug mode are as they should be.

With the sqrt line included, firmware that is being debugged automatically starts running. When I pause the program, I get this error:

"Can't find a source file at "/tmp/TI_MKLIBSF5oIb/SRC/copy_decompress_rle.c" Locate the file or edit the source lookup path to include its location."

With sqrt included, the device no longer functions as expected, even with deviation variable completely disassociated from any input or output of the device. After the firmware is uploaded on different occasions, the device has had all of the outputs turn on at once, none of the outputs turn on, and outputs randomly coming on and off. I cannot measure any values of the inputs because I can't pause the program.

Things I have tested:

  • Commenting out measurements[]*measurements[] to make sure the value does not get too large, same failure described above
  • Commenting out the line with sqrt, the device worked as expected
  • Replaced the variable inside the sqrt function with 4, same failure described above
  • Set all of the positions of the measurements[] array equal to 1, same failure described above
  • Defined variable deviation in header to use static memory instead of dynmaic
Kyle G
  • 71
  • 10
  • 2
    Insure `measurements[i] = measurements[i] * measurements[i];` did not overflow. IOWs, insure `deviation >= 0` before calling `sqrt()`. – chux - Reinstate Monica Jan 09 '18 at 03:48
  • 1
    BTW, should `for(i = 0; i <= positions; i++){` use `<` instead of `<=`? (avoid access error) With `<=` I'd expect `deviation = deviation/(positions+1);` – chux - Reinstate Monica Jan 09 '18 at 04:04
  • @chux thanks for the reply. I thought that could be the problem so I commented that portion and ran dummy numbers but I'm still getting the same results. Without squaring the value the max is only 9999 and I replaced deviation with 4 to make sure it didn't end up negative but still had the same problems. I'll fix those other things up when I get the rest of the code working, thanks for the tips – Kyle G Jan 09 '18 at 05:16
  • 2
    Try a simple test program that only calls sqrt(). – CL. Jan 09 '18 at 06:01
  • Did the comments help you to solve the issue? In that case please make your own answer to get this out of the list of unanswered questions. – Yunnosch Jan 09 '18 at 07:42
  • @Yunnosch no luck with either of the suggestions. – Kyle G Jan 09 '18 at 09:15
  • Rather then _describe_ input with "and ran dummy numbers", post the input used, output seen and expected results. Further the code snippet needs more to show how this data is inputted and reported. Without that, this post is unclear. – chux - Reinstate Monica Jan 09 '18 at 14:39

0 Answers0