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.

Compiler/UCD3138064EVM-166: UCD3138064EVM-166

Part Number: UCD3138064EVM-166

Tool/software: TI C/C++ Compiler

Can you please tell me whether following initialization for four PWMs are ok or not.

void init_dpwm0(void)
{
Dpwm0Regs.DPWMCTRL0.bit.PWM_EN = 0; //disable locally for init
Dpwm0Regs.DPWMCTRL0.bit.CLA_EN = 1; //default is 1 - use cla
Dpwm0Regs.DPWMCTRL0.bit.PWM_MODE = 0; //normal mode
Dpwm0Regs.DPWMPRD.all = PERIOD; //use .all for all values, make sure scaling matches.

Dpwm0Regs.DPWMEV1.all = (PERIOD * 3)/5; //Put event 1 at start of period
Dpwm0Regs.DPWMEV2.all = PERIOD; //1/4 of period - divide is OK because it's all constants.
Dpwm0Regs.DPWMEV3.all = (PERIOD)/5;//1/2 of period
Dpwm0Regs.DPWMEV4.all = PERIOD/2; //3/4 of period
Dpwm0Regs.DPWMSAMPTRIG1.all = PERIOD; //3/4 of period

Dpwm0Regs.DPWMCTRL2.bit.SAMPLE_TRIG_1_EN = 1; //enable 1 sample trigger
Dpwm0Regs.DPWMCTRL1.bit.EVENT_UP_SEL = 1; //update at end of period

Dpwm0Regs.DPWMCTRL0.bit.PWM_EN = 1; //enable locally
Dpwm0Regs.DPWMCTRL2.bit.RESON_DEADTIME_COMP_EN = 1;

}

void init_dpwm1(void)
{
Dpwm1Regs.DPWMCTRL0.bit.PWM_EN = 0; //disable locally for init
Dpwm1Regs.DPWMCTRL0.bit.CLA_EN = 1; //default is 1 - use cla
Dpwm1Regs.DPWMCTRL0.bit.PWM_MODE = 0; //normal mode
Dpwm1Regs.DPWMPRD.all = PERIOD; //use .all for all values, make sure scaling matches.

Dpwm1Regs.DPWMEV1.all = (PERIOD*3)/5; //Put event 1 at start of period
Dpwm1Regs.DPWMEV2.all = PERIOD; //1/4 of period - divide is OK because it's all constants.
Dpwm1Regs.DPWMEV3.all = (PERIOD)/5;//1/2 of period
Dpwm1Regs.DPWMEV4.all = PERIOD/2; //3/4 of period
Dpwm1Regs.DPWMSAMPTRIG1.all = PERIOD; //3/4 of period

Dpwm1Regs.DPWMCTRL2.bit.SAMPLE_TRIG_1_EN = 1; //enable 1 sample trigger
Dpwm1Regs.DPWMCTRL1.bit.EVENT_UP_SEL = 1; //update at end of period
Dpwm1Regs.DPWMCTRL0.bit.PWM_EN = 1; //enable locally
Dpwm1Regs.DPWMCTRL2.bit.RESON_DEADTIME_COMP_EN = 1;
}

void init_dpwm2(void)
{

Dpwm2Regs.DPWMCTRL0.bit.PWM_EN = 0; //disable locally for init
Dpwm2Regs.DPWMCTRL0.bit.CLA_EN = 1; //default is 1 - use cla
Dpwm2Regs.DPWMCTRL0.bit.PWM_MODE = 0; //normal mode
Dpwm2Regs.DPWMPRD.all = PERIOD; //use .all for all values, make sure scaling matches.

Dpwm2Regs.DPWMEV1.all = (PERIOD * 3)/5; //Put event 1 at start of period
Dpwm2Regs.DPWMEV2.all = PERIOD; //1/4 of period - divide is OK because it's all constants.
Dpwm2Regs.DPWMEV3.all = PERIOD/5;//1/2 of period
Dpwm2Regs.DPWMEV4.all = PERIOD/2; //3/4 of period
Dpwm2Regs.DPWMSAMPTRIG1.all = PERIOD; //3/4 of period

Dpwm2Regs.DPWMCTRL2.bit.SAMPLE_TRIG_1_EN = 1; //enable 1 sample trigger
Dpwm2Regs.DPWMCTRL1.bit.EVENT_UP_SEL = 1; //update at end of period

Dpwm2Regs.DPWMCTRL0.bit.PWM_EN = 1; //enable locally
Dpwm2Regs.DPWMCTRL2.bit.RESON_DEADTIME_COMP_EN = 1;

}

void init_dpwm3(void)
{

Dpwm3Regs.DPWMCTRL0.bit.PWM_EN = 0; //disable locally for init
Dpwm3Regs.DPWMCTRL0.bit.CLA_EN = 1; //default is 1 - use cla
Dpwm3Regs.DPWMCTRL0.bit.PWM_MODE = 0; //normal mode
Dpwm3Regs.DPWMPRD.all = PERIOD; //use .all for all values, make sure scaling matches.

Dpwm3Regs.DPWMEV1.all = (PERIOD * 3)/5; //Put event 1 at start of period
Dpwm3Regs.DPWMEV2.all = PERIOD; //1/4 of period - divide is OK because it's all constants.
Dpwm3Regs.DPWMEV3.all = (PERIOD)/5;//1/2 of period
Dpwm3Regs.DPWMEV4.all = PERIOD/2; //3/4 of period
Dpwm3Regs.DPWMSAMPTRIG1.all = PERIOD; //3/4 of period

Dpwm3Regs.DPWMCTRL2.bit.SAMPLE_TRIG_1_EN = 1; //enable 1 sample trigger
Dpwm3Regs.DPWMCTRL1.bit.EVENT_UP_SEL = 1; //update at end of period

Dpwm3Regs.DPWMCTRL0.bit.PWM_EN = 1; //enable locally
Dpwm3Regs.DPWMCTRL2.bit.RESON_DEADTIME_COMP_EN = 1;

}

  • Setting of:

    Dpwm3Regs.DPWMEV2.all = PERIOD;
    Dpwm3Regs.DPWMEV3.all = (PERIOD)/5;

    Means that you have a negative dead time and also means that DPWM3A stays high all the way through the end of period!
    Is this what you meant to do? What is the topology?

    Dpwm3Regs.DPWMSAMPTRIG1.all = PERIOD;

    Does not make sense. This should be set at least 500 nS before the end of period.

    Is this what you meant to do? What is the topology?

    Can you send me a drawing of the waveforms required? So we can support you better?

    Regards,

  • I have attached desired switching signal with this comment, please hep me to build the program.Switching signal.docx

  • I am looking forward to hear back from you.
  • What is the duty cycle?  Is it open loop 50% or the duty cycle dictated by the loop?

    I will send you a response by the end of my day.

    Regards,

  • Dou you have any dead-times beween DPWM0A, DPWM1A, DPWM2A and DPWM3A that need to be kept?
    Are any of these phase shifted to ward each other? Or the allignment between these signal does not matter?
    There are not much details in this regards in the drawing. Plaese advise.
  • The following is a configuration that I have came up with based on your drawing.
    But more details in the drawing are required. I have aksed for those details in the previous relpies.
    Please provide those answers, so I can assist you further.

    void init_dpwm0(void)
    {
    Dpwm0Regs.DPWMCTRL0.bit.PWM_EN = 0; //disable locally for init
    Dpwm0Regs.DPWMCTRL0.bit.CLA_EN = 1; //default is 1 - use cla
    Dpwm0Regs.DPWMCTRL0.bit.PWM_MODE = 0; //normal mode
    Dpwm0Regs.DPWMPRD.all = PERIOD; //use .all for all values, make sure scaling matches.

    Dpwm0Regs.DPWMEV1.all = 528; // Place EV1 at 132 nS, just out of event update window
    Dpwm0Regs.DPWMEV2.all = PERIOD/2; // Does not really matter if you do not use B output
    Dpwm0Regs.DPWMEV3.all = PERIOD/2; // Does not really matter if you do not use B output
    Dpwm0Regs.DPWMEV4.all = 0 ; // Does not really matter if you do not use B output
    Dpwm0Regs.DPWMSAMPTRIG1.all = PERIOD -2000; //500 nS before the end of period

    Dpwm0Regs.DPWMCTRL2.bit.SAMPLE_TRIG_1_EN = 1; //enable 1 sample trigger
    Dpwm0Regs.DPWMCTRL1.bit.EVENT_UP_SEL = 1; //update at end of period
    Dpwm0Regs.DPWMCTRL0.bit.MSYNC_SLAVE_EN =0; // DPWm0 is master

    Dpwm0Regs.DPWMCTRL0.bit.PWM_EN = 1; //enable locally

    }

    void init_dpwm1(void)
    {
    Dpwm1Regs.DPWMCTRL0.bit.PWM_EN = 0; //disable locally for init
    Dpwm1Regs.DPWMCTRL0.bit.CLA_EN = 1; //default is 1 - use cla
    Dpwm1Regs.DPWMCTRL0.bit.PWM_MODE = 0; //normal mode
    Dpwm1Regs.DPWMPRD.all = PERIOD; //use .all for all values, make sure scaling matches.

    Dpwm1Regs.DPWMEV1.all = 528; // Place EV1 at 132 nS, just out of event update window
    Dpwm1Regs.DPWMEV2.all = PERIOD/2; // Does not really matter if you do not use B output
    Dpwm1Regs.DPWMEV3.all = PERIOD/2; // Does not really matter if you do not use B output
    Dpwm1Regs.DPWMEV4.all = 0 ; // Does not really matter if you do not use B output
    Dpwm1Regs.DPWMCTRL1.bit.EVENT_UP_SEL = 1; //update at end of period
    Dpwm1Regs.DPWMCTRL0.bit.MSYNC_SLAVE_EN =0; // DPWm1 is slave
    LoopMuxRegs.DPWMMUX.bit.DPWM1_SYNC_SEL =0;//DPWm1 is a slave, sync with DPWM0
    Dpwm1Regs.DPWMCTRL0.bit.PWM_EN = 1; //enable locally
    }

    void init_dpwm2(void)
    {
    Dpwm2Regs.DPWMCTRL0.bit.PWM_EN = 0; //disable locally for init
    Dpwm2Regs.DPWMCTRL0.bit.CLA_EN = 1; //default is 1 - use cla
    Dpwm2Regs.DPWMCTRL0.bit.PWM_MODE = 0; //normal mode
    Dpwm2Regs.DPWMPRD.all = PERIOD; //use .all for all values, make sure scaling matches.

    Dpwm2Regs.DPWMEV1.all = 528; // Place EV1 at 132 nS, just out of event update window
    Dpwm2Regs.DPWMEV2.all = PERIOD/2; // Does not really matter if you do not use B output
    Dpwm2Regs.DPWMEV3.all = PERIOD/2; // Does not really matter if you do not use B output
    Dpwm2Regs.DPWMEV4.all = 0 ; // Does not really matter if you do not use B output
    Dpwm1Regs.DPWMCTRL1.bit.EVENT_UP_SEL = 1; //update at end of period
    Dpwm2Regs.DPWMCTRL0.bit.MSYNC_SLAVE_EN =0; // DPWm2 is slave
    LoopMuxRegs.DPWMMUX.bit.DPWM2_SYNC_SEL =0;//DPWm2 is a slave, sync with DPWM0
    Dpwm2Regs.DPWMCTRL0.bit.PWM_EN = 1; //enable locally
    }

    void init_dpwm3(void)
    {
    Dpwm3Regs.DPWMCTRL0.bit.PWM_EN = 0; //disable locally for init
    Dpwm3Regs.DPWMCTRL0.bit.CLA_EN = 1; //default is 1 - use cla
    Dpwm3Regs.DPWMCTRL0.bit.PWM_MODE = 0; //normal mode
    Dpwm3Regs.DPWMPRD.all = PERIOD; //use .all for all values, make sure scaling matches.

    Dpwm3Regs.DPWMEV1.all = 528; // Place EV1 at 132 nS, just out of event update window
    Dpwm3Regs.DPWMEV2.all = PERIOD/2; // Does not really matter if you do not use B output
    Dpwm3Regs.DPWMEV3.all = PERIOD/2; // Does not really matter if you do not use B output
    Dpwm3Regs.DPWMEV4.all = 0 ; // Does not really matter if you do not use B output
    Dpwm3Regs.DPWMCTRL1.bit.EVENT_UP_SEL = 1; //update at end of period
    Dpwm3Regs.DPWMCTRL0.bit.MSYNC_SLAVE_EN =0; // DPWm1 is slave
    LoopMuxRegs.DPWMMUX.bit.DPWM3_SYNC_SEL =0;//DPWm1 is a slave, sync with DPWM0
    Dpwm3Regs.DPWMCTRL0.bit.PWM_EN = 1; //enable locally
    }

    Regards,

  • Thank you for your reply, sorry for the delay in response. Yes duty cycle for  PWM0A and PWM1A pins are 50% and for PWM2A and PWM3A pins are 40%. Also, I need 5% dead gap between the pins PWM2A and PWM3A.  

  • You mean the duty cycle is fixed at 50% or 40% like in open loop?

    Please note, CLA_EN = 1 means that the duty cycle is dictated by the digital filter, and not by the DPWM configuration.

    Acheiving the 5% dead time between DPWM2A and DPWM3A is very easy. Just add PERIOD/20 to Dpwm3Regs.DPWMEV1.all and Dpwm3Regs.DPWMEV2.all

    Regards,

  • But I want my system to operate in closed loop.

  • No problem.

    I just was not sure what you meant by "duty cycle for  PWM0A and PWM1A pins are 50% and for PWM2A and PWM3A pins are 40%".

    Since in closed loop the duty changes based on the conditions of input, output and load.

    I guess you meant under certain conditions these are the duty cycles. Then you should keep CLA_EN = 1 (Enabled).

  • I want to multiply one sensed parameter with the same parameter and then want to compare with a constant value, can I implement this using following code:

    Ic= AdcRegs.ADCRESULT[5].bit.RESULT;
    t1=Ic;
    Vdc2=t1;
    Vdc=(Vdc2*Vdc2*2.5)/0xfff;
    Vdc1=(0.25/2.5)*0xfff;

    if(Vdc<Vdc1)
    {
    Dpwm0Regs.DPWMCTRL1.bit.GPIO_A_EN =0; //now turn on neutral PWM
    Dpwm1Regs.DPWMCTRL1.bit.GPIO_A_EN =1;
    }
    else
    {
    Dpwm1Regs.DPWMCTRL1.bit.GPIO_A_EN =0;
    Dpwm0Regs.DPWMCTRL1.bit.GPIO_A_EN =1;
    }


    Please help me to find error in this as this is not giving me expected result. Thanks a lot in advance.
  • You are mixing fixed point and floating point arithmetic and the results may vary, depending on What type of variables you declared Ic, t1, vdc2, vdc and vdc1 as .
    In C language if you mix these variable you have to cast the variables explicitly in order to be sure of the results.

    I would suggest to replace "Vdc=(Vdc2*Vdc2*2.5)/0xfff;" with Vdc=Vdc2*Vdc2, as the mutilication or devision factor do not matter. The mutiplication by 2.5 and division by 0xfff is just a scaler, it is good for us as human being requiring to have a measurement in engineering units. But ARM7 does not need to see a measurement in EU in order to be able to compare it with a contstant.
    Change the Vdc1 accordingly to scale well against Vdc. In other words, calculate the constant to be in level with Vdc without the 2.5 and 0xfff mult/div.

    You should also use the memory debugger in the device GUI to debug and watch your parameters. Have you tried to watch the value of your Ic, t1, vdc2, vdc and vdc1?

    Regards,