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.

how to test c code on MSP430 with data available on computer

Other Parts Discussed in Thread: MSP430F2013

Hi everybody,

I just started getting into this and am a total beginner, so please bear with me.

I have pieces of c code that I want to run on the MSP430 eZ430-F2013 and I am using the IAR Embedded Workbench IDE to download to the MSP430.  I am not utilizing the ADC right now, but I need a way to input data to test the c code.  Is it at all possible for the compiler to grab data from i.e. a text file located on my desktop to work on?  I imagine that the data needs to be downloaded to the MSP430 at one point in time..  Or will I just have to copy and paste the data into the code? 

Thanks for any advice.  I very much appreciate it.

  • Can you give a bit more information: how much test data do you want to use (data points and data sets)?  What is the context of its use (e.g. dummy input from the ADC?) ?  What format is the data in the text file?

     

    Chris.

  • I think there is no such possibility.  Better to make .h file and include it in source file.

  • Hi,

    add some of your data as 'const int data = 0xsomething;' to your application and use it for your calculations.

    What exactly do you intend to do? By the way: Setting up the ADC is quite simple! There a lot of demo applications in the TI sample code section: http://focus.ti.com/mcu/docs/mcuflashtools.tsp?sectionId=95&tabId=1538&familyId=342

    Rgds
    aBUGSworstnightmare

  • I want to use at least 4096 points of data (floating point, dummy input from ADC, from a simple .txt file) and do a test FFT on it.  I want to hold off actually doing the ADC, to test out the algorithm. Is it possible to link together this text file with the main code on the msp430?

    For Dmitrij and aBUGSworstnightmare, do you mean to copy and paste the data into the code?  Sorry, I am not very fluent at programming, but trying to dive into it.  Any pointers would be great!

    Thanks!

  • A FFT is a pretty tough first project!

     

    Probably the simple way to use dummy data is to declare an array of data points e.g.

    unsigned int a_uiTestData[8] = { 100, 200, 300, 400, 500, 600, 700, 800 };

     

    Then access it one element at a time in your code e.g.

    void myfunc(void)
    {
      unsigned int uiTemp;
     
      // some stuff

      // replace getting data from SD16MEM with getting data from user-created data
      uiTemp = a_uiTestData[index];    // get latest test data point
     

      // process data

    }

    (Remember you must be careful you don't try to access data outside of the array range: if you declare an array of n points (i.e. unsigned int myarray[n]) then you can only access it using array[0]...array[(n-1)] ).

     

    If you declare the array as I have done above it will be placed in RAM and you could even edit the values using the debugger as the program is running.  If you declare the array using the "const" keyword (e.g. "const unsigned int myarray[8] = {...};" ) the array will be placed in the ROM and you won't be able to edit it during debugging.

     

    Is the floating point data the raw analogue input values?  You would need to present the data as it would come out of the SD16.  If the data does not match you could create a script to parse the input data text file and generate a .c file containing the data in an array formatted as it would be presented from the SD16.  The script could be run as a pre-build action when compiling.  If you are new to programming this is probably far too over-complicated.

     

     

    Unfortunately having said all that it looks like you have a big problem as the MSP430F2013 has only 2kB flash and 128B RAM - you cannot include 4096 points inside the code!  You could make the MSP generate a few sample waveforms such as impulse, triangle or sqaure-wave as it runs...

    e.g. impulse:

    void myfunc(void)
    {
      static unsigned int s_uiCnt=0;
      unsigned int uiTemp;
     
      // get data
      if(s_uiCnt++ > 0)
        uiTemp=0;
      else
        uiTemp=0xFFFF;
     
      // process data...
     
    }

     

    e.g. ramp:

    void myfunc(void)
    {
      static unsigned int s_uiCnt=0;
      unsigned int uiTemp;
     
      // get data
      uiTemp = s_uiCnt++;
     
      // process data...
     
    }

     

    However if you want to fully test your algorithm I suggest you probably only have a few options:

    1. use a smaller FFT window for test purposes - it could prove the principle and operation of the algorithm and provide confidence to start full-system testing
    2. use Eclipse or something similar to create an exe to run on the PC that opens a .txt file of data and performs the same FFT algorithm as you have designed for the MSP.  Excluding the code for handling the text file most of the C code should be easy to port between the MSP and PC projects.
    3. use a different MSP with more space!!!

    You may find it is easiest to implement the ADC conversion, verify using fixed inputs that the conversion is operating correctly, and then just test the whole system.

     

    Regards

    Chris.

  • Chris,

    Thank you for taking the time out to respond to my question.  I think I need to sit down and revisit my purpose for this project.  I will probably attempt to use a much smaller dataset on this development tool and go from there...

    Much appreciated!!

  • There is a trick to make this inclusion of values more simple:

    export the data as comma separated value into a file (e.g. 'data.csv').

    In your source code, include code as follows:

     

    const unsigned int data[XYZ]={
    #include "data.csv"
    };

    where XYZ must be a number equal or larger than the number of datapoints in the CSV table (if it is larger, the table will be padded with zeroes).

    The data type may be signed int or any otehr type if necessary.
    This way you can easily swap the datasets by exporting a different table (e.g. Excel-generated) without need to touch your code. Only ensure that the code file containing this code is recompiled after changing the data file. (e.g. make a clean build)

**Attention** This is a public forum