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.

TMS320F28388D: PWM Module: Changing TBPRD value

Part Number: TMS320F28388D
Other Parts Discussed in Thread: C2000WARE, SYSCONFIG

Hi Ti,

I have a question on changing TBPRD for variable frequency in PWM module.

In spruiid, (section 26.4.5 Simultaneous Writes to TBPRD and CMPx Registers Between ePWM Modules) It is mentioned that EPWMXLINK can be used to change simultaneously the values of TBPRB and CMPx values.

I am trying to change the value of TBPRD inside ADCA1 ISR before computing the CMP values using some algorithm. ADC A1 ISR time is 25 microsec and the PWM module TBPRD range is 2500-5000.

My question is after how much time the updated value of TBPRD will be implemented?

Below piece of code i used to change the TBPRD value. Is it correct?

EPwm1Regs.TBPRD = 5000u ;

EPwm1Regs.EPWMXLINK.bit.TBPRDLINK = 0;

Thanks,

Saikumar.

  • Hello Saikumar,

    1. There is no need to use the XLINK function if you're only utilizing ePWM1.
      1. If you do use it, EPWMXLINK is set just one time during startup configuration to lock values between different ePWM modules for the lifetime of the code- for instance, if ePWM1 and ePWM2 need to always have the same TBPRD value, ePWM2 can be linked to ePWM1. Any time the TBPRD value for ePWM1 is changed, the TBPRD value for ePWM2 will be changed to the same value as well.

    2. By default, TBCTL[PRDLD] = 0. This means that TBPRD uses the shadow loading functionality. The TBCTL2[PRDLDSYNC] bits define when the new TBPRD value takes effect. By default, this is at CTR=ZRO (Counter = Zero)

    For ease of calculation and readability, I would typically recommend storing the TBPRD value in the code to use with your calculations so that you don't need to access the register every time. I hope this explanation helps!

    Regards,
    Jason Osborn
    Note: Key takeaways from this post are bolded.

  • Hi Jason Osborn,

    Thank you for quick response.

    Regarding point 1, I want to link EPWM2 and EPWM 3 to EPWM1, such that the TBPRD value of EPWM1 will be same for EPWM 2 and EPWM3.

    What lines of code i need to use to utilize EPWMXLINK feature to have same TBPRD value.

    Thanks,

    Saikumar.

  • Saikumar,

    Take a look at the C2000Ware ePWM example 'epwm_ex14_global_load_use_case'. This example describes how to use both the linking and global load features!

    For linking specifically, it is this driverlib function;

    EPWM_setupEPWMLinks();

    To specifically set it to tie ePWM2 & 3 TBPRD to ePWM1 TBPRD, the following code does what you're looking for and sets the TBPRD of all 3 ePWM modules first to 'your_TBPRD_value' and then later to 'new_value'.

    void epwm_setup(void)

    {

    EPWM_setupEPWMLinks(your_epwm_2_base, EPWM_LINK_WITH_EPWM_1, EPWM_LINK_TBPRD);

    EPWM_setupEPWMLinks(your_epwm_3_base, EPWM_LINK_WITH_EPWM_1EPWM_LINK_TBPRD);

    return;

    }

    main()

    {

    epwm_setup();

    EPWM_setTimeBasePeriod(your_epwm_1_base, your_TBPRD_value);

    ... (later) ...

    EPWM_setTimeBasePeriod(your_epwm_1_base, new_value);

    }

    Alternatively, this configuration can be done through the SysConfig tool- I highly recommend doing it this way! The SysConfig tool is a very intuitive interface to the relatively complicated ePWM peripheral- as well as the rest of the C2000 device! It makes both initial setup and any later updates much easier.

    Regards,
    Jason Osborn
    Note: Key takeaways from this post are bolded.

  • Hi Jason Osborn,

    Thank you,I will check the example project.