• Resolved

tricky PWM 100% duty cycle problem in 28335

Hi,

I have configured my PWM timer initilization for inverter which are complementary and PWM outputs are gated (Init_Timer function below). I am using EPWM1 interrupt to process ADC data only.

InitPWMs-1/2/3()
{
// Allow synchronization            
TBCTL.bit.SYNCOSEL  = 0; 
TBCTL.bit.PHSEN     = 0; 
TBCTL.bit.CLKDIV    = 0; 
TBCTL.bit.HSPCLKDIV = 0; 
TBPHS.half.TBPHS    = 0; 
TBCTL.bit.FREE_SOFT = 2;  
                                    
TBPRD              = 5000;
CMPA.half.CMPA     = 2500;
                                    
TBCTL.bit.CTRMODE  = 2;  
TBCTR              = 0;   
                                    
CMPCTL.bit.SHDWAMODE = 0;
CMPCTL.bit.SHDWBMODE = 0;
                                    
// Next PWM is set zero when CTR      reaches zero and moved from Shadow to Active.                       
CMPCTL.bit.LOADAMODE = 0;
CMPCTL.bit.LOADBMODE = 0;
                                    
// Set actions: ACTIVE LOW-HIGH     
AQCTLA.bit.CAU = 0x1;    
AQCTLA.bit.CAD = 0x2;    
                                    
// Setup the deadband - Active high  complementary PWMs               
DBCTL.bit.OUT_MODE = 0x3;
DBCTL.bit.POLSEL   = 2;  
DBCTL.bit.IN_MODE  = 0x0;
DBRED              = 10; 
DBFED              = 10; 

}

With an interface I was able to change the duty cycle varying from 10% to 100% duty cycle and with fixed frequency and could able to see different PWM outputs. I was trying to configure a shorted PWM case which means

EPWM1A-> 12.5V or 100%  EPWM1B -> 0V or 0%
EPWM2A-> 12.5V or 100%. EPWM2B -> 0V or 0%
EPWM3A-> 12.5V or 100%. EPWM3B -> 0V or 0%

or vice versa.

Inorder to acheive this,as per the document. I have set my PWM registers as below. In this case, my PWM just stops and never starts. Only option is to reset the processor and run the PWM. Short()
{
  EPwm1Regs.TBPRD = PWM_PERIOD;
  EPwm2Regs.TBPRD = PWM_PERIOD;
  EPwm3Regs.TBPRD = PWM_PERIOD;

  EPwm1Regs.half.bit.CMPA = 0x0000
  EPwm2Regs.half.bit.CMPA = 0x0000
  EPwm3Regs.half.bit.CMPA = 0x0000
}

Can I acheive this with this configuration or Am I missing some thing or IS THERE ANY MAGIC?  I have referred EPWM document as well as SPRAA1 doc also. Replies greatly appreciated.

Thanks alot,

Regards,

Kuldeep

 

 


 

  • Hi Kuldeep,

    I assume you are running your PWMs in up-down count mode.  If you set the PWM TBPRD and CMPA registers as you described in the Short() function, it should result in either a 0% or 100% duty PWM signal.

    Can you explain what you mean by "my PWM just stops and never starts" in your post? 

    When do you activate those settings? 

    What is the relationship between PWM_PERIOD and 5000?

     

  • In reply to Daniel Chang:

    Hi Chang,

    Yes! you are right. I am running in Up-Down Mode.

    When do you activate those settings? 

    I call the interface RunPWM() and update the TBPRD and CMPA registers settings.

    What is the relationship between PWM_PERIOD and 5000?

    PWM_PERIOD  = 5000 ( My bad, they are the same).

    Can you explain what you mean by "my PWM just stops and never starts" in your post? 

    I mean, PWM stays at 0% . Even though if I call the RunPWM () with 50% duty cycle. I could not see the PWM outputs and always stays at 0%.

     

     

     

  • In reply to Kuldeep Kumar Mynampati:

    Kuldeep,

    In your first post, you said you were able to run PWM modules and observe changing Duty cycle waveforms.  What are you doing differently from that setup?

  • In reply to Daniel Chang:

    Daniel,

    Thanks for the reply. Yes ! you are right as stated from previous post and now also I am able to run PWM's.  Let me clarify, I have 3 function calls in my PWM interface.

    1. RUNPWM    (I can change my duty cycles and frequency in debugger and just update the registers and PWM runs fine).
    2. STOPPWM   (Set my TBPRD = 0. so, stops the PWM and runs fine.)
    3. SHORTEDPWM ( High and low side switches shall be commanded OFF & ON or vice versa). PROBLEM.

    As per EPWM guide for 28335 document. If I set to TBPRD = MAX_PERIOD (5000) & CMPA = 0 (I should expect either 0% or 100% duty). I did the same way.

    Case-1 : Tried setting the registers to

     TBPRD = MAX_PERIOD (5000) (EPWM-1/2/3)
     CMPA  = 0 (EPWM-1/2/3)

     DOES NOT DO anything. PWM OUTPUT STAYS AT 0%.

    case-2: tried setting the registers to see 100%

     TBPRD = MAX_PERIOD (5000) (EPWM-1/2/3)
     CMPA  = MAX_PERIOD (5000) (EPWM-1/2/3)   DOES NOT DO anything. PWM OUTPUT RUNS WITH DEFAULT SETTINGS (50% duty cycle).

    I hope this helps. Please advice.

    Regards,
    KK

     

  • In reply to Kuldeep Kumar Mynampati:

    KK,

    Is this the exact code you are using in your program?

      EPwm1Regs.half.bit.CMPA = 0x0000
      EPwm2Regs.half.bit.CMPA = 0x0000
      EPwm3Regs.half.bit.CMPA = 0x0000

    If that is the code you are using, that is incorrect.  You need to access the registers this way:

    EPwm1Regs.CMPA.half.CMPA = 0x0;
    EPwm2Regs.CMPA.half.CMPA = 0x0;
    EPwm3Regs.CMPA.half.CMPA = 0x0;

  • In reply to Daniel Chang:

    Daniel,

    I tried setting the registers as per your note.

    EPwm1Regs.CMPA.half.CMPA = 0x0;
    EPwm2Regs.CMPA.half.CMPA = 0x0;
    EPwm3Regs.CMPA.half.CMPA = 0x0;

    But I see the same problem (PWM stops).

    If I run with settings below it runs.

    EPwm1Regs.TBPRD = 0x2710;
    EPwm2Regs.TBPRD = 0x2710;
    EPwm3Regs.TBPRD = 0x2710;

    EPwm1Regs.CMPA.half.CMPA = 0x1388;
    EPwm2Regs.CMPA.half.CMPA = 0x1388;
    EPwm3Regs.CMPA.half.CMPA = 0x1388;

    Regards,

    KK

    Any suggestion

  • In reply to Kuldeep Kumar Mynampati:

    KK,

    When do you try to run at CMPA = 0x0?  Is it after you call the "STOPPWM" function?

     

  • In reply to Daniel Chang:

    Daniel,

    No! I tried running CMPA = 0x0 after RUNPWM() function call.

    KK

  • In reply to Kuldeep Kumar Mynampati:

    Have you verified in the debug watch window that the PWM timers are still running?

    After you set CMPA = 0x0, if you change it, does the PWM waveform return?

  • In reply to Daniel Chang:

    With CMPA = 0x0 setting, I observed that PWM timers are running that is TBCTR keeps changing for all the timers (EPWM-1/2/3) but NO PWM WAVEFORM. When I change the value from CMPA =0x0 to CMPA = 0x1388 with TBPRD = 0x2710, I see the PWM wave form.

    Thanks,

    KK