This routine drives the micro-edge positioner (MEP) calibration module to run SFO diagnostics and determine the appropriate MEP scale factor (number of MEP steps per coarse EPWMCLK step) for a device at any given time.
If EPWMCLK = TBCLK = 100MHz and assuming the MEP
step size is 150ps, the typical scale factor value at 100MHz = 66 MEP steps per
TBCLK unit (10ns)
The function returns a MEP scale factor value:
MEP_ScaleFactor = Number of MEP steps per
EPWMCLK
Constraints when using this function:
- SFO() can be used with a minimum EPWMCLK = TBCLK
= 50MHz. MEP diagnostics logic uses EPWMCLK and not TBCLK, so the EPWMCLK
restriction is an important constraint. Below 50MHz with device process
variation, the MEP step size can decrease under cold temperature and high core
voltage conditions to such a point that 255 MEP steps do not span an entire
EPWMCLK cycle.
- At any time, SFO() can be called to run SFO
diagnostics on the MEP calibration module.
Usage:
- SFO() can be called at any time in the background while the ePWM channels are running in HRPWM mode. The scale factor result obtained can be applied to all ePWM channels running in HRPWM mode because the function makes use of the diagnostics logic in the MEP calibration module (which runs independently of ePWM channels).
- This routine returns a 1 when calibration is
finished and a new scale factor has been calculated or returns a 0 if
calibration is still running. The routine returns a 2 if there is an error, and
the MEP_ScaleFactor is greater than the maximum 255 fine steps per coarse
EPWMCLK cycle. In this case, the HRMSTEP register maintains the last MEP scale
factor value less than 256 for auto conversion.
- All ePWM modules operating in HRPWM incur only a
3 EPWMCLK cycle minimum duty cycle limitation when high-resolution period
control is not used. If high-resolution period control is enabled, there is an
additional duty cycle limitation 3-EPWMCLK cycles before the end of the PWM
period (see Section 14.14.1.5.3).
- The SFO() function also updates the HRMSTEP
register with the scale factor result. If the HRCNFG[AUTOCONV] bit is set, the
application software is responsible only for setting CMPAHR =
fraction(PWMduty*PWMperiod) << 8 or CMPBHR = fraction(PWMduty*PWMperiod)
<< 8 or TBPRDHR = fraction (PWMperiod) while running SFO() in the
background. The MEP Calibration Module then uses the values in the HRMSTEP and
CMPAHR/CMPBHR/TBPRDHR register to automatically calculate the appropriate number
of MEP steps represented by the fractional duty cycle or period and move the
high-resolution ePWM signal edge accordingly.
- If the HRCNFG[AUTOCONV] bit is clear, the HRMSTEP
register is ignored. The application software needs to perform the necessary
calculations manually so that:
- CMPAHR =
(fraction(PWMduty * PWMperiod) * MEP Scale Factor) << 8 +
0x080.
- Similar behavior applies
for TBPHSHR, CMPBHR, DBREDHR, and DBFEDHR. Auto-conversion must be
enabled when using TBPRDHR.
The following code
snippet shows how to use the HRPWM DUTY using driverlib functions.
float32_t dutyFine = 85.62;
float32_t count = (dutyFine * (float32_t)(EPWM_TIMER_TBPRD << 8))/100;
uint32_t compCount = (count);
HRPWM_setCounterCompareValue(EPWM1_BASE, HRPWM_COUNTER_COMPARE_A, compCount);
HRPWM_setCounterCompareValue(EPWM1_BASE, HRPWM_COUNTER_COMPARE_B, compCount);
The routine can be run as a background task in a
slow loop requiring negligible CPU cycles. The repetition rate at which an SFO
function needs to be executed depends on the application's operating environment. As
with all digital CMOS devices, temperature and supply voltage variations have an
effect on MEP operation. However, in most applications these parameters vary slowly
and therefore is often sufficient to execute the SFO function once every 5 to 10
seconds. If more rapid variations are expected, then execution can be performed more
frequently to match the application. Note there is no high limit restriction on the
SFO function repetition rate; hence, the SFO function can execute as quickly as the
background loop is capable.
While using the HRPWM feature, HRPWM logic is not
active for the first 3 EPWMCLK cycles of the PWM period (and the last 3 EPWMCLK
cycles of the PWM period if TBPRDHR is used). While running the application in this
configuration, if high-resolution period control is disabled (HRPCTL[HRPE=0]) and
the CMPA/CMPB register value is less than three cycles, then the CMPAHR/CMPBHR
register must be cleared to zero. If high-resolution period control is enabled
(HRPCTL[HRPE=1]), the CMPA register value must not fall below 3 or above
TBPRD-3.This can avoid any unexpected transitions on the PWM signal.