TIDA-010054: 参考设计中断1的代码理解

Part Number: TIDA-010054
Other Parts Discussed in Thread: SFRA

static inline void DAB_runISR1()
{
//
//
// Read Current and Voltage Measurements
//
DAB_readSensedSignals();

if(DAB_clearTrip == 1)
{
PWM_HAL_clearAllTripFlags(DAB_PRIM_LEG1_PWM_BASE);
PWM_HAL_clearAllTripFlags(DAB_PRIM_LEG2_PWM_BASE);
PWM_HAL_clearAllTripFlags(DAB_SEC_LEG1_PWM_BASE);
PWM_HAL_clearAllTripFlags(DAB_SEC_LEG2_PWM_BASE);

#if DAB_SEC_CONNECTED_IN_BATTERY_EMULATION_MODE == 1
DAB_closeGiLoop = 1;
#endif

DAB_clearTrip = 0;
}

if(DAB_closeGvLoop == 1)
{

//Run DF22 Compensator

#if DAB_SFRA_TYPE == DAB_SFRA_VOLTAGE
{
DAB_gvError = (DAB_SFRA_INJECT(DAB_vSecRefSlewed_pu) - \
DAB_vSecSensed_pu);
}
#else
{
DAB_gvError = (DAB_vSecRefSlewed_pu - DAB_vSecSensed_pu);
}

#endif
DAB_gvOut = DAB_GV_RUN(&DAB_gv, DAB_gvError);

//Limit the phase shift to under 0.07 as a safety precaution - need to be
// adjusted based on operating conditions
if (DAB_gvOut > 0.07f)
{
DAB_gvOut = 0.07f;
}
if (DAB_gvOut < 0.0f)
{
DAB_gvOut = 0.0f;
}
DAB_pwmPhaseShiftPrimSec_pu = DAB_gvOut;
}

else if(DAB_closeGiLoop == 1)
{
{

// Run PI Loop
if (DAB_SFRA_TYPE == DAB_SFRA_CURRENT)
{
DAB_giOut =
DAB_GI_RUN(&DAB_gi,DAB_SFRA_INJECT(DAB_iSecRefSlewed_pu),
DAB_iSecSensed_pu);
}
else
{
DAB_giOut =
DAB_GI_RUN(&DAB_gi,DAB_iSecRefSlewed_pu,
DAB_iSecSensed_pu);
}

//Limit the phase shift to under 0.07 as a safety precaution - -
// need to be adjusted based on operating conditions
if (DAB_giOut > 0.07f)
{
DAB_giOut = 0.07f;
}
if (DAB_giOut < 0.0f)
{
DAB_giOut = 0.0f;
}
DAB_pwmPhaseShiftPrimSec_pu = DAB_giOut;
}
}
else
{
DAB_gvPartialComputedValue = DAB_pwmPeriod_pu;

#if DAB_INCR_BUILD==1 && DAB_SFRA_TYPE != DAB_SFRA_DISABLED
DAB_pwmPeriod_pu = DAB_pwmPeriodRef_pu;
DAB_pwmPhaseShiftPrimSec_pu =
DAB_SFRA_INJECT(DAB_pwmPhaseShiftPrimSecRef_pu);
#else
DAB_pwmPeriod_pu = DAB_pwmPeriodRef_pu;
DAB_pwmPhaseShiftPrimSec_pu = DAB_pwmPhaseShiftPrimSecRef_pu;
#endif

if(DAB_pwmPeriod_pu < DAB_pwmPeriodMin_pu)
{
DAB_pwmPeriod_pu = DAB_pwmPeriodMin_pu;
}
else if(DAB_pwmPeriod_pu > 1.0f)
{
DAB_pwmPeriod_pu = 1.0f;
}
}

DAB_pwmFrequency_Hz = (DAB_PWMSYSCLOCK_FREQ_HZ /
(DAB_pwmPeriod_pu *
DAB_pwmPeriodMax_ticks));

DAB_pwmDutyPrim_pu = DAB_pwmDutyPrimRef_pu;
DAB_pwmDutySec_pu = DAB_pwmDutySecRef_pu;
DAB_calculatePWMDutyPeriodPhaseShiftTicks();

DAB_HAL_updatePWMDutyPeriodPhaseShift(DAB_pwmPeriod_ticks,
DAB_pwmDutyAPrim_ticks,
DAB_pwmDutyASec_ticks,
DAB_pwmPhaseShiftPrimSec_ticks,
DAB_phaseSyncPrimToSecCountDirection);

DAB_calculatePWMDeadBandPrimTicks();
DAB_calculatePWMDeadBandSecTicks();

DAB_HAL_updatePWMDeadBandPrim(DAB_pwmDeadBandREDPrim_ticks,
DAB_pwmDeadBandFEDPrim_ticks);
DAB_HAL_updatePWMDeadBandSec(DAB_pwmDeadBandREDSec_ticks,
DAB_pwmDeadBandFEDSec_ticks);

#if DAB_SFRA_TYPE != DAB_SFRA_DISABLED
#if DAB_SFRA_TYPE == DAB_SFRA_CURRENT
DAB_SFRA_COLLECT((float32_t *)&DAB_pwmPhaseShiftPrimSec_pu,
(float32_t *)&DAB_iSecSensed_pu);
#else
DAB_SFRA_COLLECT((float32_t *)&DAB_pwmPhaseShiftPrimSec_pu ,
(float32_t *)&DAB_vSecSensed_pu);
#endif
#endif
//
// Connect inputs of the Datalogger module / Not used
//
#ifndef __TMS320C28XX_CLA__
#if INCR_BUILD == 1

#elif INCR_BUILD == 2
DAB_dVal1 = DAB_closeGvLoop;
DAB_dVal2 = DAB_pwmPeriodWithInjection_pu;
DAB_dVal3 = DAB_vSecRef_pu;
DAB_dVal4 = DAB_vSecSensed_pu;
#else

#endif

#endif

DAB_HAL_clearISR1PeripheralInterruptFlag();

}

对于上述代码有几处不解的地方

1、开环情况下为什么要对PWM的频率重新进行计算,而不是直接给定100k

else
{
DAB_gvPartialComputedValue = DAB_pwmPeriod_pu;

#if DAB_INCR_BUILD==1 && DAB_SFRA_TYPE != DAB_SFRA_DISABLED
DAB_pwmPeriod_pu = DAB_pwmPeriodRef_pu;
DAB_pwmPhaseShiftPrimSec_pu =
DAB_SFRA_INJECT(DAB_pwmPhaseShiftPrimSecRef_pu);
#else
DAB_pwmPeriod_pu = DAB_pwmPeriodRef_pu;
DAB_pwmPhaseShiftPrimSec_pu = DAB_pwmPhaseShiftPrimSecRef_pu;
#endif

if(DAB_pwmPeriod_pu < DAB_pwmPeriodMin_pu)
{
DAB_pwmPeriod_pu = DAB_pwmPeriodMin_pu;
}
else if(DAB_pwmPeriod_pu > 1.0f)
{
DAB_pwmPeriod_pu = 1.0f;
}
}

2、为什么频率要通过下式计算,不直接给定100k,

DAB_pwmFrequency_Hz = (DAB_PWMSYSCLOCK_FREQ_HZ /
(DAB_pwmPeriod_pu *
DAB_pwmPeriodMax_ticks));

3、DAB_pwmFrequencyRef_Hz,DAB_pwmFrequency_Hz,DAB_pwmFrequencyPrev_Hz,DAB_pwmPeriodRef_pu,DAB_pwmPeriod_pu,DAB_pwmPeriodMin_pu,DAB_pwmPeriodMax_pu,DAB_pwmPeriodMax_ticks,DAB_pwmPeriod_ticks这些变量的作用分别是啥