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.

TMS570LC43xx asymmetic PWM settings

Hi,

I am generating an asymmetric pwm (better frequency adjustment resolution) waveform using the ePWM module. I use the following steps to configure my ePWM module (TRCTR counts up):

1. set TBPRD

2. set TBCTL_CTRMODE = 0 (up count mode)

3. set CMPA

4. set AQCTL_CAU = 2 (set output high) so that when TBCTR > CMPA, output is high

5. set AQCTL_PRD = 1 (set output low) so that the output is set to low

6. CMPA varies between 0 to TBPRD to accomplish 0% to 100% duty cycle

However, I found when I set duty cycle to 100%, it generates periodic glitches at the exact PWM frequency. Further looking into it shows that I need to clear AQCTL_PRD when my duty cycle is 100% since it sets output to low when TBCTR == TBPRD, so I have to add extra logic in duty cycle setting:

6.1. if ( duty == 100 ) AQCTL_PRD = 2;  // set output high

Is this what's expected or is there a better solution to deal with it?

Thank you very much!

Shuozhi

  • Hi Shuozhi,

      I think your observation is an expected behavior. If you refer to the TRM where it talks about what happens when several events happen at the same time. In your case, a compare match as well as a TPPRD match at the same time. In this case, the module follows a defined priority. For up count mode the counter equal to period will be higher priority than a CMPA match. See below table. With a 100% duty cycle the hardware will first try to reset the pin due to the  matching period with the higher priority  then immediately followed by setting the pin again for a compare match. Your workaround is what I would also do to avoid the glitch. 

    Below is the excerpt from the TRM. 

    It is possible for the ePWM action qualifier to receive more than one event at the same time. In this case events are assigned a priority by the hardware. The general rule is events occurring later in time have a higher priority and software forced events always have the highest priority.

     


  • Thank you, Charles!

    I just noticed another glitch occurs when I change the duty cycle from 100% to a different value, which was caused by the asynchronized CMPA update (shadowed) and AQCTL_PRD (immediate), given that we want to keep the CMPA register shadow mode.

    The configuration and steps are as follows (duty cycle 100% -> 50%, same ePWM configuration as my previous question),

    1. set AQCTL_PRD = 1 (set output to low when TBCTR == TBPRD)

    2. set CMPA = 1/2 * TBPRD (50% duty cycle)

    AQCTL_PRD is effective immediately while CMPA need another complete cycle to be effective (or the CAU event occurs in the next cycle), which results in a glitch at TBCTR == TBPRD before the actual 50% duty cycle takes place.

    I have tried changing the order of step 1 and step 2 above but it does not make any difference. Changing CMPA register from shadow mode to immediate mode solves the problem; however, I do want to keep CMPA shadow mode during during other duty cycle value settings, thus I need to add another extra logic in step 2:

    2.1 if ( previous duty cycle == 100% )

          {

               set CMPCTL_SHDWAMODE = 1;  // disable shadow mode

               set CMPA = 1/2 * TBPRD;              // 50% duty cycle

               set CMPCTL_SHDWAMODE = 0;  // enable shadow mode

          }

    Can you please confirm if above is the expected configuration for my situation?

    Thank you very much!

  • Hi Shuozhi,
    There is an app note that describes how to achieve 0-100% duty cycle. Please take a look and see if it is helpful to avoid the glitches.

    www.ti.com/.../spraai1
  • Hi Charles,

    Thank you for the app note! It definitely accomplishes what I want. However, the implementation uses ISR which increases the CPU usage especially we have multiple ePWM modules running at 100kHz switch cycle. I probably will stay with my workaround with CMPA shadow mode disabled when duty cycle equals 0% or 100%.

    I modified my implementation a little. Basically, when I change duty cycle to 0% or 100% I disable CMPA shadow mode, since there is no synchronization issue when switching from 0% or 100% to other value; while when I change duty cycle to non-0/-100% I enable shadow mode, since at this time I do care how PWM duty cycles are synchronized from cycle to cycle.

    Do you foresee any issue with this workaround?
  • Hi Shuozhi,
    I don't think there is issue with the workaround.