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.

TMS320F28379D: How to sweep between two PWM waveforms using ePWM block in Simulink?

Part Number: TMS320F28379D

Hi all,

Information about what I am trying to do:

I am trying to sweep the shaft of my servo motor (Hitec HS-422) back and forth across 180 degrees. I am using Simulink (and Embedded Coder) to program my TI's TMS320F28379D LaunchPad XL.

Figure 1 (below) shows my Simulink model. 

Let's begin with verifying my calculations.

TBCLK = PWM Clock / (HSPCLKDIV * CLKDIV)

PWM Clock = SYSCLKOUT * EPWMCLKDIV, where CPU Clock (SYSCLKOUT) = 200 MHz.

By default EPWMCLKDIV = 1/2

Then PWM Clock = 100 MHz and hence,

TBCLK = 100 MHz / (HSPCLKDIV * CLKDIV)   (Eq 1)

The "counting mode" is configured to be Up-Down, then

TBPRD = (1/2) * (f_TBCLK / f_PWM)                 (Eq 2)

Substituting Eq 1 into Eq 2,

TBPRD = (1/2) * 100 MHz / (f_PWM * HSPCLKDIV * CLKDIV)       (Eq 3)

According to the datasheet of my servo motor the f_PWM of the motor is 50 Hz.

Now, we need to choose HSPCLKDIV and CLKDIV such that TBPRD <= 2^16.

Let HSPCLKDIV = 2, and CLKDIV = 8, then TBPRD = 62500.

Again, in the datasheet the pulse duration is given as "from 0.9 ms to 2.1 ms" and T_PWM = 20 ms (or 50 Hz).

So what is the range of duty cycle? It is from 4.5% to 10.5%. (This seems too low.)

Now we can calculate CMPA Clock Cycles.

For 4.5% duty cycle, 

CPMA = (100% - 4.5%) * TBPRD = (95.5/100) * 62500 = 59687.5

For 10.5% duty cycle, 

CMPA = (100% - 10.5%) * TMPRD = (89.5/100) * 62500 = 55937.5

Then the WA signal (Specifies CMPA via the input port) should be:

Amplitude: (59687.5 - 55937.5) / 2 = 1875, Offset: 1875 + 55937.5 = 57812.5, Frequency: 1 Hz (Arbitrary), Type: Square

                            

Result: This didn't work as I expected. The motor vibrates with a buzz sound and doesn't move.

Then (based on my experience) I changed CMPA Units from "Clock cycle" to "Percentage" and applied a sinusoidal signal with the following features:

Amplitude: 15, Offset: 15, Frequency: 1 Hz (Arbitrary), Type: Sine

                                   

Result: It does sweep but this was just an educated guess. Please see the video below and notice that there is a tiny amount of buzz noise.


Can you explain what am I doing wrong with my calculations? I have a meeting with my supervisor tomorrow I need to get this working before then. Thanks!

  • Hi Canberk,

    What the CMPA value should be to get a given duty cycle depends on what action CMPA takes.  If I assume that CMPA match on up-count forces the ePWM pin high and PRD match forces the ePWM pin low, then you might get something like this:

    The fact that your square wave did not work but your sine input did seems to indicate that your twp values are incorrect (and both produce invalid servo timings) but that some intermediate value of CMPA is producing a valid set of timings.  

    In the past, to get a servo working, I did something along the lines of:

    • Use a function generator and a scope to understand the servo timings
    • Use a scope and the ePWM to understand the ePWM timings
    • (Once both are understood and working, it is easy to combine them to get the desired control)