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/TMS320F28379D: Sinus wave form generation using SGENT_1

Part Number: TMS320F28379D

Tool/software: Code Composer Studio

Dear TI Hello,

I am using the Signal Generator library for C28x DSP,

I couldn't find a clean sinus wave using the  SGENT_1 (look up table).

My interrupt is triggered every 50us (20Khz) as in the sgen_mdl pdf file.

C code:

typedef struct {   
        unsigned int freq;
        unsigned int step_max;
        unsigned int alpha;
        int gain;
        int offset;
        int out;
        void (*calc)(void *);
        }SGENT_1;

#define SGENT_1_DEFAULTS    { 5369,\
        1000,\
        0,\
        0x7fff,\
        0,\
        0,\
        (void (*)(void *))SGENT_1_calc}   


SGENT_1 sgen = SGENT_1_DEFAULTS;
int32   t_i32SinusBuf[SINUS_BUF_LEN];


interrupt void
Timer0_ISR(void)
{
    volatile static int32 s_i32Sinus;
    static int32 *s_pi32SinusBufPtr = t_i32SinusBuf;

    /* Acknowledge this interrupt to receive more interrupts from group 1 */
    PieCtrlRegs.PIEACK.all = PIEACK_GROUP1;

    /* Clear Timer interrupt flag */
    CpuTimer0Regs.TCR.bit.TIF = 0;

    /* Increment the timer0 interrupt counter */
    CpuTimer0.InterruptCount++;

    /* Update sgen macro */
    sgen.calc(&sgen);
    s_i32Sinus = sgen.out;

    /* Write sins to buffer */
    *s_pi32SinusBufPtr++ = s_i32Sinus;

    if( s_pi32SinusBufPtr == (t_i32SinusBuf + SINUS_BUF_LEN))
    {
        s_pi32SinusBufPtr = t_i32SinusBuf;
    }

}

I am using a 50 int32 buffer to display out using Single time scope.

Thank you in advance,

S.Tarik,

  • S.Tarik,

    Something fundamental is wrong.  I have not succeeded in reproducing it with these SGEN settings - I always see a clean sine wave.  

    I suggest you first check the frequency of your time interrupt.  You can do this by toggling an I/O pin inside the ISR and checking the frequency with an oscilloscope.  Try also increasing the buffer size to, say, 256, and then setting both the Acquisition Buffer Size and the Display Data Size to 256.  This may give you clues about where the problem is.

    The default settings give a maximum frequency of 305.17 Hz with a 20 kHz sample rate (see p.5 of the documentation), so if you really are sampling at this rate you should not be seeing multiple periods in the graph window.

    Please let me know what you find.

    Regards,

    Richard

  • Hello Richard

    I suggest you first check the frequency of your time interrupt....

    Considering the Covid19 period. I don't have any tool, so I use the clock in code composer studio to measure cycles.

    Clock=9999, CPU frequency is 200Mhz,

    20khz = 50us.

    10000 * 5ns = 50us.

    I believe that, the interrupt service routine is triggered every 50us => 20Khz.

    Try also increasing the buffer size to, say, 256,and then setting both the Acquisition Buffer Size and the Display Data Size to 256


    I changed the acquisition buffer to 256; and the display window to 1024pts.

    ======> so if you really are sampling at this rate you should not be seeing multiple periods in the graph window. GOOD

    Actually, the watch display was in the continues mode, so it displays a fragment of the sinusoidal wave. The sampling frequency is more higher than the sinus wave frequency.

    This issue is resolved and here a screen shot of my CCS.

    Thank you in advance.

    S.Tarik,