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.

CCS/TMS320F28379S: How to sync PWMs?

Part Number: TMS320F28379S
Other Parts Discussed in Thread: C2000WARE

Tool/software: Code Composer Studio

Hi,

I am using four PWMs, PWM1~4

Three of them are for motor control, 3-DC motors by H-bridge, PWM4 is for measuring current consumption of motors.

When PWM1.2.or/and 3 are ON, the related motor are working, and at that ON time I have to measure the current subsumption.

How can I set the all the PWM;s time base zero position at same time?

BR

Paul

  • Hi,

    If you set all counters (TBCTR) to 0, all the PWMs are synchronized and the counters all start at the same time.

    Regards,
    Gautam

  • There are some delay between start points. This different is OK for me.

    Thank you.

    BR

    Paul

  • Hi Paul,

    Please follow this init methodology:

    void InitEPwm() {
      
      EALLOW;
      SysCtrlRegs.PCLKCR0.bit.TBCLKSYNC = 0;  // This bit reset to 0 - Stops all PWM clocks.
    
      InitEPwm1();  
      InitEPwm2();  
      InitEPwm3();  
      InitEPwm4();  
      InitEPwm5();  
      InitEPwm6();  
    
    
      SysCtrlRegs.PCLKCR0.bit.TBCLKSYNC = 1; // This bit set to 1 - Turns ON all pwm clocks at the same time
      EDIS;
    }

    Regards,
    Gautam

  • I did like this, but same result, about 20nsec time-difference between each PWM.

    BR

    Paul

  • One more question,
    PWM4 is for ADC,

    I call follow code after initialized all PWMs.

    EALLOW;
    SysCtl_disablePeripheral(SYSCTL_PERIPH_CLK_TBCLKSYNC);

    EPWM_setTimeBaseCounter(EPWM1_BASE, 0U);
    EPWM_setTimeBaseCounter(EPWM2_BASE, 0U);
    EPWM_setTimeBaseCounter(EPWM3_BASE, 0U);
    EPWM_setTimeBaseCounter(EPWM4_BASE, 0U);

    SysCtl_enablePeripheral(SYSCTL_PERIPH_CLK_TBCLKSYNC);
    EDIS;

    ----------
    This is for PWM4 initial part

    //
    // Enable ADC interrupt
    //
    Interrupt_enable(INT_ADCA1);

    //
    // Start ePWM4, enabling SOCA and putting the counter in up-count mode
    //
    EPWM_enableADCTrigger(EPWM4_BASE, EPWM_SOC_A);
    EPWM_setTimeBaseCounterMode(EPWM4_BASE, EPWM_COUNTER_MODE_UP);

    .....

    ------
    This is ADC interrupt

    __interrupt void adcA1ISR(void)
    {
    isr_cnt ++;
    #ifdef ADCPWM_TEST // for test
    GPIO_writePin(6U, 1);
    #endif

    //
    // Add the latest result to the buffer
    //
    mc[0].current_ADC = ADC_readResult(ADCARESULT_BASE, ADC_SOC_NUMBER0);
    mc[1].current_ADC = ADC_readResult(ADCARESULT_BASE, ADC_SOC_NUMBER1);
    mc[2].current_ADC = ADC_readResult(ADCARESULT_BASE, ADC_SOC_NUMBER2);

    #ifdef ADCPWM_TEST // for test
    GPIO_writePin(6U, 0);
    #endif
    //
    // Clear the interrupt flag and issue ACK
    //
    ADC_clearInterruptStatus(ADCA_BASE, ADC_INT_NUMBER1);
    Interrupt_clearACKGroup(INTERRUPT_ACK_GROUP1);
    }

    I set and clear some gpio to recognize the adc timing.
    But, timing is different from PWM1~3 's timing.
    I expected the ADC_ISR is called near by PWM1/2/3' start point.

    How can I convert the ADC at just after PWM1/2/3 start point?

    Last timing is for ADC


    BR
    Paul

  • Sangdo Lee said:
    I did like this, but same result, about 20nsec time-difference between each PWM.

    I'm not sure about the above API calls. Please refer:

    C:\ti\c2000\C2000Ware_1_00_06_00\device_support\f2837xs\examples\cpu1\epwm_up_aq\cpu01

    Complete ePWM initialization should be within TBCLKSYNC statements.

    Regards,
    Gautam

  • You also have the option to use the sync chain. Enable the syncout from EPWM1 to be on CTR=ZERO, the enable phase shift on PWM2, enable syncout from EPWM2 to be SYNCIN signal. and so on.

  • Can TI update their examples to include one that has 3 PWM outputs, two which are synchronized and the third PWM not synchronized?
  • Yes I can request this or if I get some time I can post an example here.