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.

ePWM3 and ePWM4 sync

Other Parts Discussed in Thread: CONTROLSUITE

Hello, 

I'm trying to synchronize, at diferent frequencies, ePWM3 and ePWM4 modules on F28027 Piccolo without success.

I've been searching on the internet as well as on TI Forum for solutions, namely I was following an example from this post http://e2e.ti.com/support/microcontrollers/c2000/f/171/p/273846/985435.aspx

but I'm still not able to synchronize the PWM outputs.

I am running out of ideas to solve this issue.. I noticed that synchronization examples are always between ePWM1 and others, can I synchronize ePWM3 with ePWM4? (Being the ePWM3 the master, ePWM4 the slave and Switching freq3 > Switching freq4).

My code is as follows:

/************************************************************************
***** PWM Configuration *****
************************************************************************/
void InitEPwmx(){

CLK_disableTbClockSync(myClk);

// Enable PWM clocks
CLK_enablePwmClock(myClk, PWM_Number_3);
CLK_enablePwmClock(myClk, PWM_Number_4);

// Setup TBCLK
PWM_setPeriod(myPwm3, EPWM3_TIMER_TBPRD); // Set timer period PWM3
PWM_setPeriod(myPwm4, EPWM4_TIMER_TBPRD); // Set timer period PWM4

PWM_setPhase(myPwm3, 0x0000); // Phase is 0 PWM3
PWM_setPhase(myPwm4, 0x0000); // Phase is 0 PWM4

PWM_setCount(myPwm3, 0x0000); // Clear counter PWM3
PWM_setCount(myPwm4, 0x0000); // Clear counter PWM4

PWM_setCounterMode(myPwm3, PWM_CounterMode_Up); // Count up/down
PWM_setCounterMode(myPwm4, PWM_CounterMode_Up); // Count up/down

PWM_disableCounterLoad(myPwm3); // Disable phase loading
PWM_disableCounterLoad(myPwm4); // Disable phase loading

PWM_setHighSpeedClkDiv(myPwm3, PWM_HspClkDiv_by_1); // Clock ratio to SYSCLKOUT
PWM_setHighSpeedClkDiv(myPwm4, PWM_HspClkDiv_by_1); // Clock ratio to SYSCLKOUT
PWM_setClkDiv(myPwm3, PWM_ClkDiv_by_1);
PWM_setClkDiv(myPwm4, PWM_ClkDiv_by_1);

PWM_setSyncMode(myPwm3,PWM_SyncMode_CounterEqualZero); // Sets PWM3x as the Master
PWM_setSyncMode(myPwm4,PWM_SyncMode_EPWMxSYNC); // Sets PWM4x as the Slave

// Setup shadow register load on ZERO
PWM_setShadowMode_CmpA(myPwm3, PWM_ShadowMode_Shadow); // Load registers every zero
PWM_setShadowMode_CmpB(myPwm3, PWM_ShadowMode_Shadow);
PWM_setLoadMode_CmpA(myPwm3, PWM_LoadMode_Zero);
PWM_setLoadMode_CmpB(myPwm3, PWM_LoadMode_Zero);
PWM_setShadowMode_CmpA(myPwm4, PWM_ShadowMode_Shadow); // Load registers every zero
PWM_setShadowMode_CmpB(myPwm4, PWM_ShadowMode_Shadow);
PWM_setLoadMode_CmpA(myPwm4, PWM_LoadMode_Zero);
PWM_setLoadMode_CmpB(myPwm4, PWM_LoadMode_Zero);
// Set Actions
PWM_setActionQual_Zero_PwmA(myPwm3, PWM_ActionQual_Set); // Set PWM3A on period
PWM_setActionQual_CntUp_CmpA_PwmA(myPwm3, PWM_ActionQual_Clear); // Clear PWM3A on event A, up count
PWM_setActionQual_Zero_PwmB(myPwm3, PWM_ActionQual_Clear); // Clear PWM3B on period
PWM_setActionQual_CntUp_CmpA_PwmB(myPwm3, PWM_ActionQual_Set); // Set PWM3B on event B, up count
PWM_setActionQual_Zero_PwmA(myPwm4, PWM_ActionQual_Set); // Set PWM4A on period
PWM_setActionQual_CntUp_CmpA_PwmA(myPwm4, PWM_ActionQual_Clear); // Clear PWM4A on event A, up count

// Set Compare values
PWM_setCmpA(myPwm3, EPwm3MinCMPA); // Set compare A value PWM3
PWM_setCmpA(myPwm4, EPwm4CMPA); // Set compare A value PWM4

CLK_enableTbClockSync(myClk); // Re-Allow the timer clock to sync to system clock, start counting!

}

 

 

Any idea of the problem?

Thanks in advance.

Mário

  • Mario,

    I think your main issue is in:
    PWM_disableCounterLoad(myPwm4); // Disable phase loading

    If you change disable to enable I think you'll be closer (ie PWM4 should have phase loading enabled).

    Hopefully this helps.


    Thank you,
    Brett

  • Hi Brett,

    thank you for replying.. I tried your sugestion (without success) before I create a new post, in fact I've seen examples with the slave PWM counter enabled and I even tried to change the lines

    PWM_setSyncMode(myPwm3,PWM_SyncMode_CounterEqualZero);     // Sets PWM3x as the Master
    PWM_setSyncMode(myPwm4,PWM_SyncMode_EPWMxSYNC);              // Sets PWM4x as the Slave


    When I was running out of ideas I tried combinations of these lines to change ePWMs master and slave between ePWM3 and ePWM4 but the result wasn't good so far..

    I am not sure if this is the problem but, how does the micro knows that ePWM4 should follow ePWM3? 

    He knows that just by enabling the slave PWM counter and setting the SyncMode??

    Am I missing some comand to associate the Sync out put of ePWM3 to the Sync input of ePWM4??

    Best regards,

    Mário

  • Hi Mario,

    PWM_setSynchMode() is essentially a function to control the SYNCOSEL bit in the EPWM's TBCTL register (see the F2802x ePWM User's Guide - http://www.ti.com/lit/ug/spruge9e/spruge9e.pdf  - currently page 107).

    You must also configure the PHSEN bit to get loading to work.  This is essentially what the two calls of PWM_disableCounterLoad() are doing in your current code.  To do what you wish to do, disable phase loading on PWM3 and enable it on PWM4 (PWM_enableCounterLoad(myPwm4).

    ---

    You may find the following handy (however, note that this file doesn't use the API function calls that you are using, so you may need to do some translation between the 'bit-field' style and the 'API-style' to get what you want)
    \controlSUITE\libs\app_libs\digital_power\f2802x_v3.4\CNF\


    Thank you,
    Brett

  • Hi Brett,

    I followed your advice, but I couldn't see the PWMs synchronized on the scope..

    How does the PWM_setSynchMode() should be initialized for this case?

    I'm starting to think that the code might be ok, I just can't see it on the scope.

    I there any other initialization needed for this purpose? I've seen examples with initializations on the GPIO to set pins SYNC_in and SYNC_out, I don't think that's the problem but...

    Thanks in advance.

    Regards,

    Mário

  • Hi Brett, 

    we haven't talk for a while, I moved forward with the project but the synchronization problem remains..

    I am facing some problems stabilizing the controller due to the unstable current value that I'm acquiring, and I think the problem is that the ADC SOC is not being triggered where I want it to be.

    I am still trying to synchronize ePWM3 and ePWM4, where ePWM3 Freq.=20kHz and ePWM4 Freq.=5kHz.

    I can't see the two square waves synchronized even with a fixed duty-cycle.

    The code that I'm using is as below:

    // Initalize PWMs
    GPIO_setPullUp(myGpio, GPIO_Number_4, GPIO_PullUp_Disable);
    GPIO_setPullUp(myGpio, GPIO_Number_5, GPIO_PullUp_Disable);
    GPIO_setMode(myGpio, GPIO_Number_4, GPIO_4_Mode_EPWM3A);
    GPIO_setMode(myGpio, GPIO_Number_5, GPIO_5_Mode_EPWM3B);
    GPIO_setPullUp(myGpio, GPIO_Number_6, GPIO_PullUp_Disable);
    GPIO_setPullUp(myGpio, GPIO_Number_7, GPIO_PullUp_Disable);
    GPIO_setMode(myGpio, GPIO_Number_6, GPIO_6_Mode_EPWM4A);
    GPIO_setMode(myGpio, GPIO_Number_7, GPIO_7_Mode_EPWM4B);

    /************************************************************************
    ***** PWM Configuration *****
    ************************************************************************/
    void InitEPwm(){

    CLK_disableTbClockSync(myClk);

    // Enable PWM clocks
    CLK_enablePwmClock(myClk, PWM_Number_3);
    CLK_enablePwmClock(myClk, PWM_Number_4);

    // Setup TBCLK
    PWM_setPeriod(myPwm3, EPWM3_TIMER_TBPRD); // Set timer period PWM3
    PWM_setPeriod(myPwm4, EPWM4_TIMER_TBPRD); // Set timer period PWM4

    PWM_setPhase(myPwm3, 0x0000); // Phase is 0 PWM3
    PWM_setPhase(myPwm4, 0x0000); // Phase is 0 PWM4

    PWM_setCount(myPwm3, 0x0000); // Clear counter PWM3
    PWM_setCount(myPwm4, 0x0000); // Clear counter PWM4

    PWM_setCounterMode(myPwm3, PWM_CounterMode_Up); // Count up/down
    PWM_setCounterMode(myPwm4, PWM_CounterMode_Up); // Count up/down

    PWM_disableCounterLoad(myPwm3); // Disable phase loading
    PWM_enableCounterLoad(myPwm4); // Enable phase loading

    PWM_setHighSpeedClkDiv(myPwm3, PWM_HspClkDiv_by_1); // Clock ratio to SYSCLKOUT
    PWM_setHighSpeedClkDiv(myPwm4, PWM_HspClkDiv_by_1); // Clock ratio to SYSCLKOUT
    PWM_setClkDiv(myPwm3, PWM_ClkDiv_by_1);
    PWM_setClkDiv(myPwm4, PWM_ClkDiv_by_1);

    PWM_setSyncMode(myPwm3,PWM_SyncMode_Disable);
    PWM_setSyncMode(myPwm4,PWM_SyncMode_EPWMxSYNC);

    // Setup shadow register load on ZERO
    PWM_setShadowMode_CmpA(myPwm3, PWM_ShadowMode_Shadow); // Load registers every zero
    PWM_setShadowMode_CmpB(myPwm3, PWM_ShadowMode_Shadow);
    PWM_setLoadMode_CmpA(myPwm3, PWM_LoadMode_Zero);
    PWM_setLoadMode_CmpB(myPwm3, PWM_LoadMode_Zero);
    PWM_setShadowMode_CmpA(myPwm4, PWM_ShadowMode_Shadow); // Load registers every zero
    PWM_setShadowMode_CmpB(myPwm4, PWM_ShadowMode_Shadow);
    PWM_setLoadMode_CmpA(myPwm4, PWM_LoadMode_Zero);
    PWM_setLoadMode_CmpB(myPwm4, PWM_LoadMode_Zero);
    // Set Actions
    PWM_setActionQual_Zero_PwmA(myPwm3, PWM_ActionQual_Set); // Set PWM3A on period
    PWM_setActionQual_CntUp_CmpA_PwmA(myPwm3, PWM_ActionQual_Clear); // Clear PWM3A on event A, up count
    PWM_setActionQual_Zero_PwmB(myPwm3, PWM_ActionQual_Clear); // Clear PWM3B on period
    PWM_setActionQual_CntUp_CmpA_PwmB(myPwm3, PWM_ActionQual_Set); // Set PWM3B on event B, up count
    PWM_setActionQual_Zero_PwmA(myPwm4, PWM_ActionQual_Clear); // Clear PWM4A on period
    PWM_setActionQual_CntUp_CmpA_PwmA(myPwm4, PWM_ActionQual_Set); // Set PWM4A on event A, up count

    PWM_enableSocAPulse(myPwm4); // Enable SOC on A group
    PWM_setSocAPulseSrc(myPwm4, PWM_SocPulseSrc_CounterEqualCmpAIncr); // Select SOC from from CPMA on upcount
    PWM_setSocAPeriod(myPwm4, PWM_SocPeriod_FirstEvent); // Generate pulse on 1st event

    // TRIP ZONE event settings
    PWM_enableTripZoneSrc(myPwm3,PWM_TripZoneSrc_OneShot_TZ1_NOT);
    PWM_setTripZoneState_TZA(myPwm3, PWM_TripZoneState_EPWM_Low);
    PWM_setTripZoneState_TZB(myPwm3, PWM_TripZoneState_EPWM_Low);
    PWM_enableTripZoneInt(myPwm3, PWM_TripZoneFlag_OST);

    // Set Compare values
    PWM_setCmpA(myPwm3, 1000); // Set compare A value PWM3
    PWM_setCmpA(myPwm4, 5500); // Set compare A value PWM4

    CLK_enableTbClockSync(myClk); // Re-Allow the timer clock to sync to system clock, start counting!

    }

    I hope you can help me with this issue..

    I look forward to hearing from you soon.

    Regards,

    Mário

  • Mário Silva said:

    PWM_disableCounterLoad(myPwm3); // Disable phase loading
    PWM_enableCounterLoad(myPwm4); // Enable phase loading

    PWM_setHighSpeedClkDiv(myPwm3, PWM_HspClkDiv_by_1); // Clock ratio to SYSCLKOUT
    PWM_setHighSpeedClkDiv(myPwm4, PWM_HspClkDiv_by_1); // Clock ratio to SYSCLKOUT
    PWM_setClkDiv(myPwm3, PWM_ClkDiv_by_1);
    PWM_setClkDiv(myPwm4, PWM_ClkDiv_by_1);

    PWM_setSyncMode(myPwm3,PWM_SyncMode_Disable);
    PWM_setSyncMode(myPwm4,PWM_SyncMode_EPWMxSYNC);



    Perhaps:

    PWM_disableCounterLoad(myPwm3); // Disable phase loading
    PWM_enableCounterLoad(myPwm4); // Enable phase loading

    PWM_setHighSpeedClkDiv(myPwm3, PWM_HspClkDiv_by_1); // Clock ratio to SYSCLKOUT
    PWM_setHighSpeedClkDiv(myPwm4, PWM_HspClkDiv_by_1); // Clock ratio to SYSCLKOUT
    PWM_setClkDiv(myPwm3, PWM_ClkDiv_by_1);
    PWM_setClkDiv(myPwm4, PWM_ClkDiv_by_1);

    PWM_setSyncMode(myPwm3,PWM_SyncMode_CounterEqualZero);
    PWM_setSyncMode(myPwm4,PWM_SyncMode_EPWMxSYNC);



    Thank you,
    Brett

  • Brett,

    Thank you for the reply..

    I've tried that before and it doesn't work, with that configuration the ePWM4 stays low..

    I'm starting to run out of ideas to solve this..

    Is there any other configuration that I should up to?

    Thanks a lot.

    Mário

  • Mario,

    I'd recommend removing the deadband configuration code for the time being and work on getting synchronization working first.  Once that's settled retry adding in the dead-band.

    (I feel like the deadband is currently making it more difficult to evaluate whether synchronization is occurring or not)

    I hope this helps!


    Thank you,
    Brett

  • Hi Mario,

    I have not tried to sync 4 PWM signals but had success synchronising PWM2 with PWM1, if you see the image below extracted from page 24 of the ePWM guide, it should shed some light on your issue.

    I also posted some code which worked, but this could probably be used and modified for your purpose and have PWM2 sync'ed to PWM1 and PWM4 sync'ed to PWM3.

    http://e2e.ti.com/support/microcontrollers/c2000/f/171/p/323487/1127109.aspx#1127109

    Hope this helps,

    Ant