Enhanced PWM (ePWM) Module
15.2.2.10.5.2 Scaling Considerations
The mechanics of how to position an edge precisely in time has been demonstrated using the resources
of the standard (CMPA) and MEP (CMPAHR) registers. In a practical application, however, it is necessary
to seamlessly provide the CPU a mapping function from a per-unit (fractional) duty cycle to a final integer
(non-fractional) representation that is written to the [CMPA:CMPAHR] register combination.
To do this, first examine the scaling or mapping steps involved. It is common in control software to
express duty cycle in a per-unit or percentage basis. This has the advantage of performing all needed
math calculations without concern for the final absolute duty cycle, expressed in clock counts or high time
in ns. Furthermore, it makes the code more transportable across multiple converter types running different
PWM frequencies.
To implement the mapping scheme, a two-step scaling procedure is required.
Assumptions for this example:
System clock, SYSCLKOUT
= 10 ns (100 MHz)
PWM frequency
= 1.25 MHz (1/800 ns)
Required PWM duty cycle, PWMDuty
= 0.405 (40.5%)
PWM period in terms of coarse steps,
= 80
PWMperiod (800 ns/10 ns)
Number of MEP steps per coarse step at
= 55
180 ps (10 ns/180 ps), MEP_SF
Value to keep CMPAHR within the range
of 1-255 and fractional rounding constant
(default value)
= 180h
Step 1: Percentage Integer Duty value conversion for CMPA register
CMPA register value
= int(PWMDuty × PWMperiod); int means integer part
= int(0.405 × 80)
= int(32.4)
CMPA register value
= 32 (20h)
Step 2: Fractional value conversion for CMPAHR register
CMPAHR register value
= (frac(PWMDuty × PWMperiod) × MEP_SF) << 8) +
180h; frac means fractional part
= (frac(32.4) × 55 <<8) + 180h; Shift is to move the
value as CMPAHR high byte
= ((0.4 × 55) <<8) + 180h
= (22 <<8) + 180h
= 22 × 256 + 180h ; Shifting left by 8 is the same
multiplying by 256.
= 5632 + 180h
= 1600h + 180h
CMPAHR value
= 1780h; CMPAHR value = 1700h, lower 8 bits will be
ignored by hardware.
1555
SPRUH73H – October 2011 – Revised April 2013
Pulse-Width Modulation Subsystem (PWMSS)
Copyright © 2011–2013, Texas Instruments Incorporated