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: triangular wave generation using buffdac

Part Number: TMS320F28377S
Other Parts Discussed in Thread: C2000WARE, LAUNCHXL-F28379D

Tool/software: Code Composer Studio

1)how can we convert the presiding dac_sine example inorder to generate a triangular wave

  • I'm assuming that you're starting with the "buffdac_sine_dma_cpu01" example from C2000Ware.

    If you want to generate a triangular wave, you need to open the "buffdac_sine_dma_cpu01.c" file, and look at the "void configureWaveform(void)" function. As given, this function fills a Sine Table's values. You just modify this code such that the table contains your desired triangle wave. This is a 12-bit DAC, so the table values should be between 0 and 4095.

    Best regards,
    Ryan Voogjarv
  • i tried this , but didn't work out

    //
    // Fill Sine Table
    //
    for(j=0;j<SINE_TBL_SIZE;j++)
    {
    #if(j<SINE_TBL_SIZE/2)
    SINE_TBL[j] = (((j-SINE_TBL_SIZE/2)/(SINE_TBL_SIZE/2))+1.0)*2047.5;

    #elif
    SINE_TBL[j] = (((SINE_TBL_SIZE/2-j)/(SINE_TBL_SIZE/2))+1.0)*2047.5;

    #endif
    }
  • You cannot use the preprocessor directives `#if`, `#elif`in this context, as these conditions can only be based on compile-time information such as #define constants. You can simply use regular `if` and `else` conditions here.

    Your should also modify your code to avoid integer division, when calculating the values to fill the table with.

    Best regards,

    Ryan Voogjarv 

  • even then
    for(j=0;j<SINE_TBL_SIZE;j++)
    {
    if(j<SINE_TBL_SIZE/2)
    SINE_TBL[j] = (((j-180)/180)+1.0)*2047.5;


    else
    SINE_TBL[j] = (((180-j)/180)+1.0)*2047.5;


    }
    i'm not able to get a proper signal from pin 27
  • That code is still yielding incorrect values due to integer division.

    Specifically, over your range of values for `j`, `((j-180)/180)` will only ever equal -1 or 0. `((180-j)/180)` will only ever equal 0.

    You may also wish to read C2000 Fundamentals Workshop for CCSv7 to for a quick tutorial on how to use breakpoints to debug and inspect the behaviour of your code. This workshop is written for the F28379D LaunchPad (LAUNCHXL-F28379D), but the procedure should be nearly identical for your board.

    Best regards,
    Ryan Voogjarv

  • Hi Surya,

    It's been a few weeks since you've responded to this thread, so I assume that you were able to resolve this coding issue.

    If you still have any questions, please feel free to respond.

    Best regards,
    Ryan Voogjarv