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.

TMS320F28069M: Setting HRPWM Duty Cycle

Part Number: TMS320F28069M

Hi, 

I am using the 2806xHRPWM example code from dev.ti.com. I am trying to understand the example code in order to set a duty cycle through a variable in the while loop instead of shifting bits.

The code is included in the bottom and attached is the link to the example code.


Thank you.

https://dev.ti.com/tirex/explore/node?devices=F28069M&devtools=F28069M&node=A__AC9UwFyMyNzT.8M6MowG1A__c2000ware_software_package__gYkahfz__LATEST

 

Fullscreen
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
//###########################################################################
//
// FILE: Example_2806xHRPWM.c
//
// TITLE: High Resolution PWM Example
//
//! \addtogroup f2806x_example_list
//! <h1>High Resolution PWM (hrpwm)</h1>
//!
//! This example modifies the MEP control registers to show edge displacement
//! due to the HRPWM control extension of the respective EPwm module
//! All EPwm1A,2A,3A,4A channels (GPIO0, GPIO2, GPIO4, GPIO6) will have fine
//! edge movement due to HRPWM logic
//!
//! -# \f$ PWM\ Freq = \frac{SYSCLK}{period=10} \f$,
//! - ePWM1A toggle low/high with MEP control on rising edge
//! - ePWM1B toggle low/high with NO HRPWM control
//!
//! -# \f$ PWM\ Freq = \frac{SYSCLK}{period=20} \f$,
//! - ePWM2A toggle low/high with MEP control on rising edge
//! - ePWM2B toggle low/high with NO HRPWM control
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

  • Hi Raymond,

    The CMPAHR register is 16bits, and it can be finely tuned choosing MEP step sizes of an integer between 0-255. Writing a floating point of 0.3 will just set the CMPAHR to zero. In order to write safely to CMPAHR, we recommend following the examples to bit shift left 8 bits so that the HRPWM registers get filled correctly.

    For this device the MEP step size is 150 ps. So once you configure your EPWM without HRPWM, and decide on how accurate you want your duty cycle you can choose any integer value between 0-255, and each increment within this range is +150ps. (when DutyFine = 1, your final duty cycle will be your current duty cycle(without HRPWM) + 150ps)

    If you want a duty cycle of 0.55, and your TBPRD is 30, EPWMCLK is 100Mhz, you can set the MEP step size to be (DutyFine) = equal to 33.

    You can verify this with that example.

    Hope this helps,

    Ryan Ma

  • Thank you for the explanation. I am trying to build a digitally controlled buck converter, so I would need to control the duty cycle compared to an ADC input. 

    Would you know how to control the duty cycle in this scenario? I'm not sure how manage it by shifting the bits. 
    Apologies, I am not very familiar with digital devices.

    Thank you

  • How are you comparing the duty cycle with the ADC input? 

    Best,

    Ryan Ma

  • Hi Ryan,

    I have not set up the ADC to read an input yet. I was planning on trying to implement the ADC functionality in PLECS and add that to the code that controls the duty cycle. Would you recommend this approach? I have not looked at the ADC example code yet either.

    Thank you

  • Hi Raymond,

    Unfortunately I am unfamiliar with PLECS so I cannot tell you whether or not I would recommend the approach.

    I would suggest to look into our ADC examples, training videos, and our academy page which I will link here.

    1. Training Videos

    2. Academy page

    These should help steer you in the right direction. If you have any questions related to ADC, you will have to create a new thread so we can provide the expert to help you with that peripheral.

    Best regards,

    Ryan Ma

  • Hi Ryan,

    Thanks for the resources, I'll take a look at them. 

    Just a final question, do you know if there is another way to set the duty cycle without shifting bits? 

  • Are you talking about setting duty cycle without HRPWM? 

    If so, then yes! All you have to do is write to the CMPA register. Here is a quick video introduction on how you could do that.

    In the video it will discuss on how to calculate your duty cycle and translate that to a value you can write to the CMPA /B register.

    training.ti.com/c2000-enhanced-pulse-width-modulator-epwm-time-base-submodule

    Best,

    Ryan Ma