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.

AM2634: Synchronize two EPWM with different frequency

Part Number: AM2634

Hi TI ream!

1. I want to start two PWM simultaneously, but for PWM1 it will be (a) HZ, and for PWM2 it will be (a x 4) HZ. It means every 4th pulse of PWM2 will by synced with PWM1. 

    Is it possible? Could you please help with config?

2. I want to start the second PWM with shift 200us, with the same configuration of frequency.

    Is it possible? Could you please help with config?

Regards!

  • Hello Oleg,

    1. Please use EPWM_CLKSYNC register to start the clock(Time Base clock TBCLK) of multiple EPWM instances simultaneously.

    Address is 0x502F 0010 which can be obtained from CSL_CONTROLSS_CTRL_U_BASE + CSL_CONTROLSS_CTRL_EPWM_CLKSYNC

    Please refer to SOC_setEpwmTbClk API for programming this register. 

    \mcu_plus_sdk\source\drivers\soc\am263x\soc.c (Note that SOC_setEpwmTbClk API starts the clock of EPWM instances one by one, not multiple instances simultaneously)

    For example:

    If PWM1 freq required is a=25KHz (40us period) and PWM2 freq required is 100KHz (10us period)

    then program PWMs as follows,

    • Make  EPWM_CLKSYNC as 0. This disables TBCLK for all EPWMs
    • Make TBCTL[CTRMODE]= 3 in PWM1 and PWM2. This freezes the TBCTR (time base counters)
    • Write TBCTR=0 in PWM1 and PWM2. This initializes counters to 0
    • Configure PWM parameters, specifically the period as follows:
      • TBPRD for PWM1 is 7999 ((7999+1)*5ns=40us).
      • TBPRD for PWM2 is 1999 ((1999+1)*5ns=10us).
    • Make TBCTL[CTRMODE]= 0 or 1 or 2 (depending on your use case) in PWM1 and PWM2. This starts the TBCTR (time base counters), and waits till clocks are enabled
    • Write EPWM_CLKSYNC with bit mask to enable required PWMs (2 bits in your use case).  This enables TBCLK for the chosen EPWMs

    Observe the PWMs

    Please note that this is a one time synchronization of PWMs

    2. Please use same steps above, but configure the initial TBCTR value as 40000 (40000*5ns = 200000ns) for a delay of 200us in one PWM

    If the period (PWM frequency) is constant for the use case (no frequency modulation is required), then use above method of one-time synchronization of PWMs. If frequency modulation is required, the use EPWMxSYNCI, EPWMxSYNCO and TBPHS (sync in, sync out and phase shift) feature of EPWM.

    Thanks

    K.Sanjeev

  • Hi Sanjeev Karaiyan!

    \mcu_plus_sdk\source\drivers\soc\am263x\soc.c (Note that SOC_setEpwmTbClk API starts the clock of EPWM instances one by one, not multiple instances simultaneously)

    As I understand correctly, I can disable/enable more than one PWM instantly via access directly to `CSL_CONTROLSS_CTRL_U_BASE + CSL_CONTROLSS_CTRL_EPWM_CLKSYNC`, instead of using SOC_setEpwmTbClk() ?

    Please note that this is a one time synchronization of PWMs

    These two PWM should work continuously for a long time, I suppose no one will not drift in time. Correct?

  • Hello Oleg,

    As I understand correctly, I can disable/enable more than one PWM instantly via access directly to `CSL_CONTROLSS_CTRL_U_BASE + CSL_CONTROLSS_CTRL_EPWM_CLKSYNC`, instead of using SOC_setEpwmTbClk() ?

    Yes. More than one PWM clocks can be instantly enabled/disabled by writing to CSL_CONTROLSS_CTRL_U_BASE + CSL_CONTROLSS_CTRL_EPWM_CLKSYNC

    (Ensure to unlock the CONTROLSS_CTRL registers before writing. Call SOC_controlModuleUnlockMMR(SOC_DOMAIN_ID_MAIN, CONTROLSS_CTRL_PARTITION0);)

    These two PWM should work continuously for a long time, I suppose no one will not drift in time. Correct?

    Yes

    Thanks

    K.Sanjeev

  • Thanks!
    It helped me!