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.

Negative phase shift with ePWMSYNCI



Hi,

I'm trying to synchronize my ePWM with an incoming square-wave signal on an f28335. However, I want to have a negative phase shift on my output because there is a small delay on my synchronization signal.

So, what I try to do is this (sorry for the bad drawing):

But the output I get is this (the yellow is ePWM1a, the green is ePWM1b and the blue is the synchronization signal):

The relevant code I use for the ePWM:

EPwm1Regs.TBCTL.bit.CTRMODE = TB_COUNT_UPDOWN; // Count up/down
EPwm1Regs.TBCTL.bit.PHSEN = TB_ENABLE; // Enable phase loading
EPwm1Regs.TBCTL.bit.SYNCOSEL = TB_SYNC_IN; // Synchronize with EPWMSYNCI
EPwm1Regs.TBPHS.half.TBPHS = 0x0100; // Phase is 0
EPwm1Regs.TBCTL.bit.PHSDIR = 1; // Count up after sync
EPwm1Regs.TBCTR = 0x0000; // Clear counter

When I change PHSDIR to 0 it works, as shown in the picture below:

So it must have something to do with the phase direction. The TBPRD I use is 0x03A9.

Thanks in advance!

Christian

EDIT: Oops. Forgot the action settings for the ePWM. It is:

EPwm1Regs.AQCTLA.bit.ZRO = AQ_SET; // Set ePWM1A at zero
EPwm1Regs.AQCTLA.bit.PRD = AQ_CLEAR; // Clear ePWM1A TBPRD
EPwm1Regs.AQCTLB.bit.ZRO = AQ_SET; // Set ePWM1B at zero
EPwm1Regs.AQCTLB.bit.PRD = AQ_CLEAR; // Clear ePWM1A at TBPRD

  • I went around the problem by changing the action qualifier settings to these:

    EPwm1Regs.AQCTLA.bit.PRD = AQ_SET; // Clear ePWM1A on event A, down count
    EPwm1Regs.AQCTLA.bit.ZRO = AQ_CLEAR; // Set ePWM1A on event A, up count
    EPwm1Regs.AQCTLB.bit.PRD = AQ_SET; // Clear ePWM1B on event B, down count
    EPwm1Regs.AQCTLB.bit.ZRO = AQ_CLEAR; // Set ePWM1A on event B, up count

    which in effect phase shifts the PWM output 180 degrees, and then I chose a very large phase shift using TBPHS and a phase direction counting downwards like this:

    EPwm1Regs.TBPHS.half.TBPHS = 0x0300;
    EPwm1Regs.TBCTL.bit.PHSDIR = 0; // Count down after sync

    so now my signals look like this:

    However, this is more abstract and it's harder to intuitively understand what to set TBPHS to in order to have the correct phase shift. So if anyone knows any way of getting my first code to work I would be happy to hear it.

  • Hi Christian,

    How are you configuring the EPwm1Regs.CMPCTL.bit.SHDWAMODE & SDWBMODE bits?  I could potentially see these settings getting in the way of your synchronization pulse depending on the difference between the period of the synch pulse and your PWM's configured period.

    I must be missing something too though.  I don't understand why PWMA and PWMB don't have the exact same phase (unless you're using the deadband module - in this case your AQCTLB settings would be irrelevant).


    Thank you,
    Brett

  • Oh, sorry. I didn't realize that the shadow and deadband settings were relevant to my particular problem. Anyway, here's my shadow settings:

    EPwm1Regs.CMPCTL.bit.SHDWAMODE = CC_SHADOW; // Enable shadow register of CMPA
    EPwm1Regs.CMPCTL.bit.SHDWBMODE = CC_SHADOW; // Enable shadow register of CMPB
    EPwm1Regs.CMPCTL.bit.LOADAMODE = CC_CTR_ZERO; // Load CMPA into shadow register at CTR = zero
    EPwm1Regs.CMPCTL.bit.LOADBMODE = CC_CTR_ZERO; // Load CMPB into shadow register at CTR = zero

    and my deadband settings:

    #define deadband 76;

    EPwm1Regs.DBCTL.bit.OUT_MODE = DB_FULL_ENABLE; // Both rising and falling edge deadband enabled

    EPwm1Regs.DBCTL.bit.POLSEL = DB_ACTV_HIC; // Active Hi Complementary
    EPwm1Regs.DBCTL.bit.IN_MODE = DBA_RED_DBB_FED; // ePWM1a rising edge, ePWM1b falling edge
    EPwm1Regs.DBRED = deadband; // rising edge time = deadband
    EPwm1Regs.DBFED = deadband; // falling edge time = deadband

    Does it have anything to do with me loading the shadow registers at TBCTR = ZRO? It feels strange that it works when the phase direction is downwards but not upwards because of that.

    EDIT: I just tried my original settings and changed the shadow registers to load at TBCTR = PRD instead. I got the same result as when it loaded on TBCTR = ZRO, unfortunately.

  • Christian,

    After thinking about it a bit more, I don't think my last bit of advice regarding the shadow registers was not as valid as I thought at the time.  This is because you are currently keeping the CMPA and TBPRD values constant.

    A few things I'd try:
    1) Monitor ePWM1's TBCTR via the watch-window as your code is executing.  Ideally, it should always be between 0 and TBPRD.
    2) Can you try without the deadband configuration and see if you get the PWM waveforms that you expect?

    (
    note: according to your previous post your code for EPWMA events and EPWMB events (the outputs from the AQ submodule) are identical.  Because of this, why not configure DBCTL.bit.IN_MODE so that you always work off of the AQ's PWMA output (which would then make configuring PWMB in the AQ submodule unnecessary)?
    )


    Thank you,
    Brett