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: Sine Wave Generation & its comparison with Epwm

Part Number: TMS320F28379D


Tool/software: Code Composer Studio

  • Not sure if we have the entire text related to your post, since the entire post appears as a large image. In future, please type your questions and not attach it as an image. Also, if you insert a code snippet in your post, always paste it using the “Syntax Highlighter” option. That makes the code easier to read. I have requested a PWM expert to look into your issue.

  • When you generate you some wave out of the epwm signals and a low pass filter, you set the amplitude of your sine by using an op amp.

    If I’m missing something please comment.
  • I don't want to generate Sine Wave from ePWM, I am generating Sine wave using SIN function of Math.h Library

    I just want to compare that generated sine wave to ePWM module.

    My Sine wave is of 50 Hz & ePWM TBPRD is set to have 2kHZ, So I want to compare them & generate pulses.


    ----------------CODE-------------------

    #include <math.h>
    #define PI 3.14159265359
    int i;
    float j;
    float value[360];

    for ( i=1; i<360; i++)
    {
    j = 2*PI*i;
    value[i]= sin (j);
    }
    -------------------------------------------------
    After writing this, I have configured EPwm1 Reg & its CMPA is set by following line:
    *EPwm1Regs.CMPA.bit.CMPA = value[i];*

    Please suggest me, if there is any mistake & provide solution to this issue
  • Your issue is likely because you are writing a 32-bit floating point variable into a register which expects a 16-bit fixed point value.

    Firstly, since you have assigned value[] as float you need to be using sinf(), not sin(). Then in the line which writes the result to the register make sure you cast it to uint16_t first:
    EPwm1Regs.CMPA.bit.CMPA = (uint16_t) value[i];

    An even better way would be to declare value as uint16_t and typecast when you load it: that way you don't have to do it when you write to the register.

    I have not tested your code so I don't know if it works, but intuitively I would expect you to have to offset value[] to avoid negative numbers. You should also ensure the TBPRD is set up so the range of what you're writing into CMPA makes sense.

    I hope this helps.

    Regards,

    Richard
  • Sir, I made changes as per your suggestions. I also tried to match range of TBPRD & CMPA. Still I'm not getting results.

    Would you please suggest me values of registers for 2 kHz frequency in TBPRD & 50 Hz frequency Sine Wave in CMPA....

  • If you are clocking the PWM at the maximum speed on this device (100 MHz), and you are using up-count mode, the TBPRD register setting to achieve 2 kHz PWM frequency is:
    100e6 / 2e3 = 50000

    Presumably the duty register would be written from within an ISR, with values depending on the ISR frequency and desired amplitude.

    I think it may help you to review this video which described the function of the PWM:
    training.ti.com/getting-started-c2000-epwm-module

    Regards,

    Richard