Step 4: Application Code Calibration
While the application is running, fluctuations in both device temperature and supply voltage may be expected.
To be sure that optimal HRCAP step size is used for each HRCAP module, the HRCAP_Cal function should be
re-run periodically as part of a slower back-ground loop. Some examples of this are shown here.
Note
NOTE:
See the hrcap_capture_hrpwm example in the device-specific C/C++ header files and
peripheral examples available in C2000ware from the TI website
Example 4: HRCAP_Cal Function Calls
main ()
{
int status;
// User code
// HRCAP 1, 3, and 4 are running in high-resolution mode
// The status variable returns 2 once calibration has been
// completed by the HCCal Calibration Module running
// diagnostics.
status = HRCAP_Cal(2,HCCAPCLK_PLLCLK, &EPwm8Regs);
// The function returns a 2 if HCCAPCLK is not within the
// appropriate frequency range.
if(status==HCCAL_ERROR) {ESTOP0;}
}
Step 5: Application Code Pulse Width Measurement
While the application is running, when a RISE or FALL event occurs, pulse and period widths can be measured
using the high resolution pulse width functions as shown below.
Example 5: LowPulseWidth, HighPulseWidth, and PeriodWidth Function Calls
interrupt void HRCAP1_Isr (void)
{
EALLOW;
if (HRCap1Regs.HCIFR.bit.RISEOVF == 1) {
ESTOP0; // Another rising edge detected
}
if (first < 1) {
first++; // Discard first data (because first interrupt
// after reset/clk enable measures time from
// clock start to edge - invalid pulse width)
} else {
periodwidth = PeriodWidthRise0((Uint16 *)&HRCap1Regs);
pulsewidthlow = LowPulseWidth0((Uint16 *)&HRCap1Regs);
pulsewidthhigh = HighPulseWidth0((Uint16 *)&HRCap1Regs);
}
HRCap1Regs.HCICLR.bit.RISE=1;
HRCap1Regs.HCICLR.bit.INT=1;
PieCtrlRegs.PIEACK.bit.ACK4=1;
EDIS;
}
High-Resolution Capture (HRCAP) Module
420
TMS320x2806x Microcontrollers
SPRUH18I – JANUARY 2011 – REVISED JUNE 2022
Copyright © 2022 Texas Instruments Incorporated
Содержание TMS320 2806 Series
Страница 2: ......