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.

TMS320F28379D: Adding two sine waves

Part Number: TMS320F28379D
Other Parts Discussed in Thread: C2000WARE

Hi everyone,

Have anyone tried to add two sine waves using F28379D? Is there any example from the control suite?

I was thinking this could be the first move to simulate a reading from a sensor to analyse the FFT of its sine wave.

Any help will be helpful. Thanks a lot.

  • Hi Ellen,

    I'm sorry for the delay in responding to your post. It should be a straightforward thing to do, but I don't recall any code example where two sine waves are being added together. There is a dual channel (fixed point) sine wave generator in the SGEN library in C2000Ware which may help. Sorry not to have more to offer at this time.

    Regards,

    Richard
  • Hi Richard,

    I've found an example wich displays two sine waves with differents frequencies however I'm afraid it's not sutable to a F283779D board. Here it's a screenshot of it.

    Thanks a lot :)

  • I'm sorry, the two sine waves have the same frequency but different phases. It's a little different of what I want, but it could be helpful. However, I imagine it's not applicable to the board I'm using. Is that right?
    Thank you very much =)
  • Hi Ellen,

    Yes, it's unfortunate that's all we have at present. A floating-point version of the SGEN library is on our backlog but I can't give you an indication of when it will be ready.

    If you are prepared to set up and compute the angles you need you could always just call sin(). The device you are using has a TMU which supports sine in hardware so the cycle overhead is very small. Make sure the TMU is enabled in your CCS project settings (CCS Build - C2000 Compiler - Processor Options).

    Again, sorry not to have more.

    Regards,

    Richard
  • Hi Richard,

    thank you for your support, I have used a tmu example to generate a sine wave from control suite and it worked well. Next point is generate two sine waves. My question is: Is that possible using the tmu?

    One more time thank you so much!

  • Hi Ellen,

    Yes; to do this you would configure and maintain a second software angle counter for the other phase, calling sin() in the same way.  Your code would have to compute any phase offset or modulation required.  Unfortunately there isn't an example I can point you towards.  I hope it works out.

    Regards,

    Richard

  • Hi again Richard,

    I'm trying to implement two sine waves on tmu example as you said, but i'm having trouble. I'm thinking it's something about the RAM size or something about link. As you can see in the code below I just have created variables with an "a" in the end of their names for the the second sine wave, wich I changed the frequency to 250 MHz. I took a screenshot of those problems.

    Would you help me please? 

     

    Thank you so much again Richard, you're being an excellent mentor.

    //-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

    #include <math.h>

    #include <stdio.h>

    #include "F28x_Project.h"

    #define     VECTOR_SIZE      1024

    #define     VECTOR_SIZEa     1024

    #define     MAX_ARG          1.0

    #define     MIN_ARG          -1.0

    #define     PROFILE_FREQ     200     // Specified in MHz

    #define     PROFILE_FREQa    250     // Specified in MHz

    #define     PROFILE_PER      1000    //Specified in microseconds

    #define     TWO_PI           6.283185307179586476925286766559

    #define     TOLERANCE        1.0e-6

    #define     START_TIMER(x) {                                    \

                                 x = CpuTimer1Regs.TIM.all;        \

                                 CpuTimer1Regs.TCR.bit.TSS = 0;    \

                              }

    #define     START_TIMERa(y) {                                    \

                                 y = CpuTimer2Regs.TIM.all;        \

                                 CpuTimer2Regs.TCR.bit.TSS = 0;    \

                                  }

    #define     STOP_TIMER(x)  {                                    \

                                 CpuTimer1Regs.TCR.bit.TSS = 1;    \

                                 x = CpuTimer1Regs.TIM.all;        \

                                 CpuTimer1Regs.TCR.bit.TRB = 1;  \

                               }

    #define     STOP_TIMERa(y)  {                                    \

                                 CpuTimer2Regs.TCR.bit.TSS = 1;    \

                                 y = CpuTimer2Regs.TIM.all;        \

                                 CpuTimer2Regs.TCR.bit.TRB = 1;  \

                               }

    uint16_t pass=0;

    uint16_t fail=0;

    float inputVector[VECTOR_SIZE];

    float inputVectora[VECTOR_SIZEa];

    float rtsOutput[VECTOR_SIZE];

    float rtsOutputa[VECTOR_SIZEa];

    float tmuOutput[VECTOR_SIZE];

    float tmuOutputa[VECTOR_SIZEa];

    float errorVector[VECTOR_SIZE];

    float errorVectora[VECTOR_SIZEa];

    float ticksRTS, ticksTMU, timeRTS,  timeTMU;

    float ticksRTSa, ticksTMUa, timeRTSa,  timeTMUa;

    float maxError;

    float maxErrora;

    void genInputVector(float *inputVector, int16_t size);

    void genInputVectora(float *inputVectora, int16_t size);

    float genErrorVector(float *rtsOutput, float *tmuOutput,

                       float *errorVector, int16_t size);

    float genErrorVectora(float *rtsOutputa, float *tmuOutputa,

                        float *errorVectora, int16_t size);

    float RTS_runTest(float *inputVector,float *rtsOutput,

                     int16_t size);

    float RTS_runTesta(float *inputVectora,float *rtsOutputa,

                     int16_t size);

    float TMU_runTest(float *inputVector,float *tmuOutput,

                    int16_t size);

    float TMU_runTesta(float *inputVectora,float *tmuOutputa,

                     int16_t size);

    void main(void)

    {

       InitSysCtrl();

       DINT;

       InitPieCtrl();

       IER = 0x0000;

       IFR = 0x0000;

       InitPieVectTable();

       InitCpuTimers();

       ConfigCpuTimer(&CpuTimer1, PROFILE_FREQ, PROFILE_PER);

       ConfigCpuTimer(&CpuTimer2, PROFILE_FREQa, PROFILE_PER);

       EINT;  // Enable Global interrupt INTM

       ERTM;  // Enable Global realtime interrupt DBGM

       genInputVector(inputVector, VECTOR_SIZE);

       genInputVectora(inputVectora, VECTOR_SIZEa);

       ticksRTS = RTS_runTest(inputVector, rtsOutput, VECTOR_SIZE);

       ticksRTSa = RTS_runTesta(inputVectora, rtsOutputa, VECTOR_SIZEa);

       ticksTMU = TMU_runTest(inputVector, tmuOutput, VECTOR_SIZE);

       ticksTMUa = TMU_runTesta(inputVectora, tmuOutputa, VECTOR_SIZEa);

       maxError = genErrorVector(rtsOutput, tmuOutput, errorVector, VECTOR_SIZE);

       maxErrora = genErrorVectora(rtsOutputa, tmuOutputa, errorVectora, VECTOR_SIZEa);

       timeRTS = ticksRTS * (1.0/PROFILE_FREQ);

       timeRTSa = ticksRTSa * (1.0/PROFILE_FREQa);

       timeTMU = ticksTMU * (1.0/PROFILE_FREQ);

       timeTMUa = ticksTMUa * (1.0/PROFILE_FREQa);

       printf("Execution Results \n");

       printf("RTS Time : %10.6f us\n", timeRTS);

       printf("TMU Time : %10.6f us\n", timeTMU);

       printf("RTS Time : %10.6f us\n", timeRTSa);

       printf("TMU Time : %10.6f us\n", timeTMUa);

    }

    void genInputVector(float *inputVector, int16_t size)

    {

       int16_t i;

       float step = (MAX_ARG - MIN_ARG)/size;

       inputVector[0] = MIN_ARG;

       for(i = 1; i < size ; i++)

       {

           inputVector[i] = inputVector[i-1] + step;

       }

    }

    void genInputVectora(float *inputVectora, int16_t size)

    {

       int16_t i;

       float step = (MAX_ARG - MIN_ARG)/size;

       inputVectora[0] = MIN_ARG;

       for(i = 1; i < size ; i++)

       {

           inputVectora[i] = inputVectora[i-1] + step;

       }

    }

    float genErrorVector(float *rtsOutput, float *tmuOutput,

                        float *errorVector, int16_t size)

    {

       int16_t i;

       float maxError = -1.0;

       for(i = 0; i < size ; i++)

       {

           errorVector[i] = fabs(rtsOutput[i] - tmuOutput[i]);

           if(errorVector[i] > maxError)

           {

               maxError = errorVector[i];

           }

           if(errorVector[i] < TOLERANCE)

           {

               pass++;

           }

           else

           {

               fail++;

           }

       }

       return(maxError);

    }

    float genErrorVectora(float *rtsOutputa, float *tmuOutputa,

                        float *errorVectora, int16_t size)

    {

       int16_t j;

       float maxErrora = -1.0;

       for(j = 0; j < size ; j++)

       {

           errorVectora[j] = fabs(rtsOutputa[j] - tmuOutputa[j]);

           if(errorVectora[j] > maxErrora)

           {

               maxErrora = errorVectora[j];

           }

           if(errorVectora[j] < TOLERANCE)

           {

               pass++;

           }

           else

           {

               fail++;

           }

       }

       return(maxErrora);

    }

    float RTS_runTest(float *inputVector,float *rtsOutput,

                     int16_t size)

    {

       int16_t i;

       float start_time = 0.0;

       float stop_time = 0.0;

       START_TIMER(start_time);

       for(i = 0; i < size ; i++)

       {

           rtsOutput[i] = sin(inputVector[i] * TWO_PI);

       }

       STOP_TIMER(stop_time);

       return(start_time - stop_time);

    }

    float RTS_runTesta(float *inputVectora,float *rtsOutputa,

                     int16_t size)

    {

       int16_t i;

       float start_time = 0.0;

       float stop_time = 0.0;

       START_TIMERa(start_time);

       for(i = 0; i < size ; i++)

       {

           rtsOutputa[i] = sin(inputVectora[i] * TWO_PI);

       }

       STOP_TIMERa(stop_time);

       return(start_time - stop_time);

    }

    float TMU_runTest(float *inputVector,float *tmuOutput,

                     int16_t size)

    {

       int16_t i;

       float start_time = 0.0;

       float stop_time = 0.0;

       START_TIMER(start_time);

       for(i = 0; i < size ; i++)

       {

           tmuOutput[i] = __sinpuf32(inputVector[i]);

       }

       STOP_TIMER(stop_time);

       return(start_time - stop_time);

    }

    float TMU_runTesta(float *inputVector1,float *tmuOutputa,

                     int16_t size)

    {

       int16_t j;

       float start_time = 0.0;

       float stop_time = 0.0;

       START_TIMERa(start_time);

       for(j = 0; j < size ; j++)

       {

           tmuOutputa[j] = __sinpuf32(inputVectora[j]);

       }

       STOP_TIMERa(stop_time);

       return(start_time - stop_time);

    }

  • Richard,

    I changed the VECTOR size to 512 and it resolved my issue.

    Regards
  • Ellen,

    Glad to know you found and resolved the issue.  Thanks for letting us know. 

    You will by now know that the 8 float vectors consume 16 K words when you had them at 1024 length (each float variable consumes two 16-bit words), but the GS2 - GS4 RAM blocks only contain a total of 12 K words.  Halving the vector length reduced your total requirement to 8 K words, so now the vectors fit comfortably.  If you later need more resolution, another solution would be to go back to 1024 length vectors and allocate more memory to .ebss by adding GS5 and possibly GS6.

    Regards,

    Richard

  • Richard,

    Is this the correct way to allocate more memory to .bss as you suggested? Also, is there any problem using the CpuTimer0

    Accomplishments: I implemented a third variable wich is a result of two sine waves.

    Problem: I had to decrease the amount of memory to 256, because now I've 24 vectors floats.

    Any suggestions to maybe use less memory?

    Thanks again!

  • Ellen,

    Yes, what you're doing will work providing you have not allocated GS5 & GS6 to anything else. Alternatively, you could have created a single named section (say "RAMGS2_GS6") in the MEMORY part of the linker file and referred to that by name - it's effectively the same thing.

    The .ebss section is used for all global variable storage, so in addition to your vectors is it being used for things like maxError, pass, fail, ...etc. and will always be a little larger than the sum of your vector sizes.  If you want to, you can allocate your vectors to a specific named memory section using the DATA_SECTION pragma (see the C compiler user's guide for details).  You have plenty of memory on this device, so you could keep adding 4K GS blocks all the way up to GS15 and get back to your 1024 length vectors.

    You should not have any issues with the CPU timers - are you seeing a problem?

    Regards,

    Richard

  • Hi Richard,

    I've tried to add 15 GS blocks, but it seems to me that they don't fit 24 float vectors up to 256 lenght. I read about the DATA_SECTION as you had mentioned but it didn't have much information on how to implement it.

    Could you give me a clue of it and/or how to named section in the MEMORY?

    Thank you again!
  • Hi Ellen,

    You should be able to allocate all 24 vectors into these GS memory blocks. I think the cleanest way is to combine them into a single named memory section and use that to hold just the vectors. Your linker command file might look something like this:

    MEMORY
    {
    ...

    PAGE 1 :
    RAMGS2_GS4 : origin = 0x00E000, length = 0x003000
    RAMGS5_GS15 : origin = 0x011000, length = 0x00B000
    ...
    }

    SECTIONS
    {
    ...
    .ebss : > RAMGS2_GS4, PAGE = 1
    SineVecsSection : > RAMGS5_GS15, PAGE = 1
    ...
    }

    This choice leaves three GS section for .ebbs, and 11 others to hold your vectors.  Then in your code, you use the following #pragma to connect each of your vectors to the same named section:

    #define VECTOR_LENGTH 256

    #pragma DATA_SECTION(vector1, "SineVecsSection")
    float vector1[VECTOR_LENGTH];

    #pragma DATA_SECTION(vector2, "SineVecsSection")
    float vector2[VECTOR_LENGTH];

    ...and so on for the other vectors. You have to use a separate pragma for each vector.  

    I hope this helps.

    Regards,

    Richard

  • Hi again Richard,

    I've been trying to understand how the ccs graph works on time and frequency domain. As part of this project I plot the result of the sum of two sine waves with 60Hz and 300Hz, but I don't understand what horizontal and vetical axis means. Coud you please give me a hand please? 

    Hope to hear from you soon. 

     

     

    Thank you again Richard.

  • Hi Ellen,

    Yes, you can certainly allocate the .ebss section as you have done.  You still have a lot of unused GS memory available.

    What is the error you're getting (I can't see all the text in the screen capture)?  Are you having a problem with CPU timer 0?

    Regards,

    Richard

  • Hi Ellen,
    Sorry, I got confused with the forum interface and responded to the wrong post! Let me look at your CCS question and get back to you. Thanks.
    Regards,
    Richard
  • Hello Richard,

    That’s ok. I was wondering to know what units the axis x and y are using. For the time domain, I set the x to display in seconds, but in the frequency domain i have no clue. I just set in the frequency domain to display in Khz, that’s all I have. Any clue? Thanks again for your attention.
  • Hi Ellen,
    The graphs look about right to me. In the graph properties window you have the sample rate set to 1Hz. So whatever the actual frequency of the sine waves, CCS sees them in the time window as if they are sampled at that rate. In the "Single Time -2" window the period of one wave is about 500 seconds, and that of the other about 210 seconds. These correspond to the peaks we see in the FFT Magnitude graph at about 2e-3Hz and 4.8e-3Hz respectively. Is the issue just that the sample rate hasn't been entered?
    Regards,
    Richard
  • Yes Richard,

    I tried to set the sample rate to 60 Hz and didn't see much difference. Is there a way to set those  graphs to exhibit them in a better way to understand?

    Thanks

  • Hi Ellen,
    Sorry, I think I'm not following. What rate were the signals sampled at?
    Regards,
    Richard
  • Richard,

    I set up the vectors as the picture bellow:

    The sample rate that I tried was 60 Hz, after you alert me about the rate that was set to 1Hz. Do you have any advice in how to display those signals? 

  • Hi Ellen,
    I think the key is the sample rate. Can you describe what the signals we see in the time graph are? I know they're the sum of two sine waves, at 60Hz and 300Hz, but are they samples in a data file in memory? The information we need is how many samples are there per period of the 60Hz sine wave. Once we have that we multiply the number by 60 and we have the sample rate in Hz.
    For example, it doesn't make sense to sample a 60Hz sine wave at 60Hz - there would be one sample per period so we'd just see a DC level. I think this is why the CCS graphs are not making sense.
    Regards,
    Richard
  • Richard,

    you're right, It doesn't make sense sample  a 60Hz sine wave at 60Hz.

    What we are seeing is a vector which has 1024 values that has been feeded by two vectors with different frequencies. See the screenshot bellow and see if it makes sense. We are using different frequencies to feed our cpu timers, tmu and rts routines.

  • Hi Ellen,

    Thanks for sending the code.  Having a little difficulty following, but the line...

    tmuOutputr[k] = tmuOutput[k]+tmuOutputa[k];

    ...seems to sum the two sine vectors, each of which is 1024 data points in length.  I guess the genInputVectorX() functions at the top are where the vectors get initialized?  So, how do you load those?  I'm looking for how the frequencies are tied to the number of data points.  Thanks.

    Regards,

    Richard

  • Richard,

    I'm sorry for the pieces of informations, I'm new on CCS and I'm using a code that was developed earlier by Texas Instruments. I'm studying it as well. 

    Well, I think while the vectors become ready the tmu and rts execute, as you can see bellow the function that uses tmuOutputr is ticksTMUr and then timeTMUr uses ticksTMUr with the frequency that has been set in the begin of the code.

    Hope that helps. Thanks!

     

  • Hi Ellen,
    Well, "ticksTMUr" is the measured time in clock cycles taken to run through the vector sum. It's returned by TMU_runTestr() in the last line:
    return (start_time - stop_time);
    The variable "timeTMUr" is the physical time to do that operation in seconds. There is another piece of information somewhere in the code which decides what data goes into the "tmuOutput" and "tmuOutputa" arrays. That's what we need.
    Could you take a look through the code to see if there is something obvious? My guess would be it's in the "genInputVector()" and "genInputVectora()" functions. Many thanks.
    Regards,
    Richard
  • Richard,

    you are right. What is into tmuOutputr is genInputVectorr().

  • Thanks, Ellen.

    Could you send the "RTS_runTesta" and "RTS_runTestr" functions please? Sorry for the many posts - I think I'm following it now.

    Regards,

    Ruchard
  • Hi Richard,

    For sure. Thank you again!

    That's all of the code bellow:

    P.s.: What you want is bold.

    //
    // Included Files
    //
    #include <math.h>
    #include <stdio.h>
    #include "F28x_Project.h"

    //
    // Defines
    //


    #define VECTOR_SIZE 1024
    #define MAX_ARG 1.0
    #define MIN_ARG -1.0
    #define PROFILE_FREQ 0.00006 // Specified in MHz
    #define PROFILE_FREQa 0.0003 // Specified in MHz
    #define PROFILE_FREQr 0.00006 // Specified in MHz
    #define PROFILE_PER 1000000 //Specified in microseconds
    #define TWO_PI 6.283185307179586476925286766559
    #define TOLERANCE 1.0e-6

    #define START_TIMER(x) { \
    x = CpuTimer1Regs.TIM.all; \
    CpuTimer1Regs.TCR.bit.TSS = 0; \
    }

    #define START_TIMERa(y) { \
    y = CpuTimer0Regs.TIM.all; \
    CpuTimer0Regs.TCR.bit.TSS = 0; \
    }

    #define START_TIMERr(r) { \
    r = CpuTimer2Regs.TIM.all; \
    CpuTimer2Regs.TCR.bit.TSS = 0; \
    }

    #define STOP_TIMER(x) { \
    CpuTimer1Regs.TCR.bit.TSS = 1; \
    x = CpuTimer1Regs.TIM.all; \
    CpuTimer1Regs.TCR.bit.TRB = 1; \
    }

    #define STOP_TIMERa(y) { \
    CpuTimer0Regs.TCR.bit.TSS = 1; \
    y = CpuTimer0Regs.TIM.all; \
    CpuTimer0Regs.TCR.bit.TRB = 1; \
    }

    #define STOP_TIMERr(r) { \
    CpuTimer2Regs.TCR.bit.TSS = 1; \
    r = CpuTimer2Regs.TIM.all; \
    CpuTimer2Regs.TCR.bit.TRB = 1; \
    }
    //
    // Globals
    //
    uint16_t pass=0;
    uint16_t fail=0;

    float inputVector[VECTOR_SIZE];
    float inputVectora[VECTOR_SIZE];
    float inputVectorb[VECTOR_SIZE];
    float inputVectorr[VECTOR_SIZE];
    float rtsOutput[VECTOR_SIZE];
    float rtsOutputa[VECTOR_SIZE];
    float rtsOutputb[VECTOR_SIZE];
    float rtsOutputr[VECTOR_SIZE];
    float tmuOutput[VECTOR_SIZE];
    float tmuOutputa[VECTOR_SIZE];
    float tmuOutputr[VECTOR_SIZE];
    float errorVector[VECTOR_SIZE];
    float errorVectora[VECTOR_SIZE];
    float errorVectorr[VECTOR_SIZE];
    float ticksRTS, ticksTMU, timeRTS, timeTMU;
    float ticksRTSa, ticksTMUa, timeRTSa, timeTMUa;
    float ticksRTSr, ticksTMUr, timeRTSr, timeTMUr;
    float maxError;
    float maxErrora;
    float maxErrorr;

    //
    // Function Prototypes
    //
    void genInputVector(float *inputVector, int16_t size);
    void genInputVectorr(float *inputVectorr, int16_t size);
    void genInputVectora(float *inputVectora, int16_t size);
    float genErrorVector(float *rtsOutput, float *tmuOutput,
    float *errorVector, int16_t size);
    float genErrorVectora(float *rtsOutputa, float *tmuOutputa,
    float *errorVectora, int16_t size);
    float genErrorVectorr(float *rtsOutputr, float *tmuOutputr,
    float *errorVectorr, int16_t size);
    float RTS_runTest(float *inputVector,float *rtsOutput,
    int16_t size);
    float RTS_runTesta(float *inputVectora,float *rtsOutputa,
    int16_t size);
    float RTS_runTestr(float *inputVectorr,float *rtsOutputr,
    int16_t size);
    float TMU_runTest(float *inputVector,float *tmuOutput,
    int16_t size);
    float TMU_runTesta(float *inputVectora,float *tmuOutputa,
    int16_t size);
    float TMU_runTestr(float *inputVectorr,float *tmuOutputr,
    int16_t size);
    //
    // Main
    //
    void main(void)
    {
    //
    // Step 1. Initialize System Control:
    // PLL, WatchDog, enable Peripheral Clocks
    // This example function is found in the F2837xD_SysCtrl.c file.
    //
    InitSysCtrl();

    //
    // Step 2. 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 F2837xD_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 F2837xD_DefaultIsr.c.
    // This function is found in F2837xD_PieVect.c.
    //
    InitPieVectTable();

    //
    // Step 3. Configure the timer used to profile the TMU and RTS routines
    //
    InitCpuTimers();
    ConfigCpuTimer(&CpuTimer1, PROFILE_FREQ, PROFILE_PER);
    ConfigCpuTimer(&CpuTimer0, PROFILE_FREQa, PROFILE_PER);
    ConfigCpuTimer(&CpuTimer2, PROFILE_FREQr, PROFILE_PER);
    //
    // Step 4. Enable global Interrupts and higher priority real-time debug events:
    //
    EINT; // Enable Global interrupt INTM
    ERTM; // Enable Global realtime interrupt DBGM

    //
    // Step 5. Run the test, generate the input vector, call the RTS/TMU
    // routines, get the error vector and, finally, print the execution time.
    //
    genInputVector(inputVector, VECTOR_SIZE);
    genInputVectora(inputVectora, VECTOR_SIZE);
    genInputVectorr(inputVectorr, VECTOR_SIZE);
    ticksRTS = RTS_runTest(inputVector, rtsOutput, VECTOR_SIZE);
    ticksRTSa = RTS_runTesta(inputVectora, rtsOutputa, VECTOR_SIZE);
    ticksRTSr = RTS_runTestr(inputVectorr, rtsOutputr, VECTOR_SIZE);
    ticksTMU = TMU_runTest(inputVector, tmuOutput, VECTOR_SIZE);
    ticksTMUa = TMU_runTesta(inputVectora, tmuOutputa, VECTOR_SIZE);
    ticksTMUr = TMU_runTestr(inputVectorr, tmuOutputr, VECTOR_SIZE);
    maxError = genErrorVector(rtsOutput, tmuOutput, errorVector, VECTOR_SIZE);
    maxErrora = genErrorVectora(rtsOutputa, tmuOutputa, errorVectora, VECTOR_SIZE);
    maxErrorr = genErrorVectorr(rtsOutputr, tmuOutputr, errorVectorr, VECTOR_SIZE);
    timeRTS = ticksRTS * (1.0/PROFILE_FREQ);
    timeRTSa = ticksRTSa * (1.0/PROFILE_FREQa);
    timeRTSr = ticksRTSr * (1.0/PROFILE_FREQr);
    timeTMU = ticksTMU * (1.0/PROFILE_FREQ);
    timeTMUa = ticksTMUa * (1.0/PROFILE_FREQa);
    timeTMUr = ticksTMUr * (1.0/PROFILE_FREQr);
    //
    // To use the printf statement, allocate space for the .cio, .sysmem section,
    // increase allotment for the .text, stack and heap sections in the properties
    // and linker command file.
    //
    printf("Execution Results \n");
    printf("RTS Time : %10.6f us\n", timeRTS);
    printf("TMU Time : %10.6f us\n", timeTMU);
    printf("RTS Time : %10.6f us\n", timeRTSa);
    printf("TMU Time : %10.6f us\n", timeTMUa);
    printf("RTS Time : %10.6f us\n", timeRTSr);
    printf("TMU Time : %10.6f us\n", timeTMUr);
    }

    //
    // genInputVector - Generate the input vector array
    //

    void genInputVector(float *inputVector, int16_t size)
    {
    int16_t i;
    float step = (MAX_ARG - MIN_ARG)/size;

    inputVector[0] = MIN_ARG;
    for(i = 1; i < size ; i++)
    {
    inputVector[i] = inputVector[i-1] + step;
    }
    }
    void genInputVectora(float *inputVectora, int16_t size)
    {
    int16_t i;
    float step = (MAX_ARG - MIN_ARG)/size;

    inputVectora[0] = MIN_ARG;
    for(i = 1; i < size ; i++)
    {
    inputVectora[i] = inputVectora[i-1] + step;
    }
    }


    void genInputVectorr(float *inputVectorr, int16_t size)
    {
    int16_t i;
    float step = (MAX_ARG - MIN_ARG)/size;

    inputVectorr[0] = MIN_ARG;
    for(i = 1; i < size ; i++)
    {
    inputVectorr[i] = inputVectorr[i-1] + step;
    }
    }

    //
    // genErrorVector - Generate error vector array
    //

    float genErrorVector(float *rtsOutput, float *tmuOutput,
    float *errorVector, int16_t size)
    {
    int16_t i;
    float maxError = -1.0;

    for(i = 0; i < size ; i++)
    {
    errorVector[i] = fabs(rtsOutput[i] - tmuOutput[i]);
    if(errorVector[i] > maxError)
    {
    maxError = errorVector[i];
    }
    if(errorVector[i] < TOLERANCE)
    {
    pass++;
    }
    else
    {
    fail++;
    }
    }

    return(maxError);
    }

    float genErrorVectora(float *rtsOutputa, float *tmuOutputa,
    float *errorVectora, int16_t size)
    {
    int16_t j;
    float maxErrora = -1.0;

    for(j = 0; j < size ; j++)
    {
    errorVectora[j] = fabs(rtsOutputa[j] - tmuOutputa[j]);
    if(errorVectora[j] > maxErrora)
    {
    maxErrora = errorVectora[j];
    }
    if(errorVectora[j] < TOLERANCE)
    {
    pass++;
    }
    else
    {
    fail++;
    }
    }

    return(maxErrora);
    }

    float genErrorVectorr(float *rtsOutputr, float *tmuOutputr,
    float *errorVectorr, int16_t size)
    {
    int16_t i;
    float maxErrorr = -1.0;

    for(i = 0; i < size ; i++)
    {
    errorVectorr[i] = fabs(rtsOutputr[i] - tmuOutputr[i]);
    if(errorVectorr[i] > maxErrorr)
    {
    maxErrorr = errorVectorr[i];
    }
    if(errorVectorr[i] < TOLERANCE)
    {
    pass++;
    }
    else
    {
    fail++;
    }
    }

    return(maxErrorr);
    }
    //
    // RTS_runTest - Execute SIN generation test (C28)
    //

    float RTS_runTest(float *inputVector,float *rtsOutput,
    int16_t size)
    {
    int16_t i;
    float start_time = 0.0;
    float stop_time = 0.0;

    START_TIMER(start_time);
    for(i = 0; i < size ; i++)
    {
    rtsOutput[i] = sin(inputVector[i] * TWO_PI);
    }
    STOP_TIMER(stop_time);

    return(start_time - stop_time);
    }

    float RTS_runTesta(float *inputVectora,float *rtsOutputa,
    int16_t size)
    {
    int16_t i;
    float start_time = 0.0;
    float stop_time = 0.0;

    START_TIMERa(start_time);
    for(i = 0; i < size ; i++)
    {
    rtsOutputa[i] = sin(inputVectora[i] * TWO_PI);
    }
    STOP_TIMERa(stop_time);

    return(start_time - stop_time);
    }

    float RTS_runTestr(float *inputVectorr,float *rtsOutputr,
    int16_t size)
    {
    int16_t i;
    float start_time = 0.0;
    float stop_time = 0.0;

    START_TIMERr(start_time);
    for(i = 0; i < size ; i++)
    {
    rtsOutputr[i] = sin(inputVectorr[i] * TWO_PI);
    }
    STOP_TIMERr(stop_time);

    return(start_time - stop_time);
    }
    //
    // TMU_runTest - Execute SIN generation test (TMU)
    //

    float TMU_runTest(float *inputVector,float *tmuOutput,
    int16_t size)
    {
    int16_t i;
    float start_time = 0.0;
    float stop_time = 0.0;

    START_TIMER(start_time);
    for(i = 0; i < size ; i++)
    {
    tmuOutput[i] = __sinpuf32(inputVector[i]);
    }

    STOP_TIMER(stop_time);

    return(start_time - stop_time);
    }

    float TMU_runTesta(float *inputVectora,float *tmuOutputa,
    int16_t size)
    {
    int16_t j;
    float start_time = 0.0;
    float stop_time = 0.0;

    START_TIMERa(start_time);
    for(j = 0; j < size ; j++)
    {
    tmuOutputa[j] = __sinpuf32(inputVectora[j]+inputVectora[j]);
    }

    STOP_TIMERa(stop_time);

    return(start_time - stop_time);
    }

    float TMU_runTestr(float *inputVectorr,float *tmuOutputr,
    int16_t size)
    {
    int16_t k;
    float start_time = 0.0;
    float stop_time = 0.0;

    START_TIMERr(start_time);
    for(k = 0; k < size ; k++)
    {
    tmuOutputr[k] = tmuOutput[k]+tmuOutputa[k];
    }

    STOP_TIMERr(stop_time);

    return(start_time - stop_time);
    }
    //
    // End of file
    //

  • Hi Ellen,

    Sorry for the delay and multiple posts.

    The program generates two arrays of size 1024 containing sinusoidal data. One array contains exactly two periods of data (tmuOutput), while the other contains four periods (tmuOutputa). These arrays get summed together in the function "TMU_runTestr()". What you are seeing in the time graph you posted previously is the sum of these two waveforms (tmuOutputr), and you can see the relationship between their frequencies is 2:1, as expected. Therefore they cannot represent waveforms of 60Hz and 300Hz.

    The program is not physically sampling anything, so the data has no explicit relationship with time or frequency, but if we assume that the lower frequency represents 60Hz, we have two periods of data in our 1024 array, or 512 samples in 1/60th of a second, so our sample period would be about 32.55 us, and our sample rate is 30.72 kHz. This is the number we want in the CCS graph window. Could you try this and let me know if the FFT magnitude graph makes more sense please? We should be seeing peaks at 60Hz and 120Hz. Thanks.

    Regards,

    Richard