CurrCmd_MDD

Module -- CurrCmd

High-Level Description

This Module generates the current command and the voltage reference for the current control.

Diagram – Function Data Sharing

Diagram – Function (Name)

Variable Data Dictionary

For details on module input / output variable, refer to the Data Dictionary for the application. Input / output variable names are listed here for reference.

Module InputsModule Outputs
MRFTrqCmdScl_MtrNm_f32DaxIntegralGain_Uls_f32
MRFMtrVel_MtrRadpS_f32DaxPropotionalGain_Uls_f32
EstKe_VpRadpS_f32QaxIntegralGain_Uls_f32
EstR_Ohm_f32QaxPropotionalGain_Uls_f32
EstLd_Henry_f32MtrCurrDaxRef_Amp_f32
EstLq_Henry_f32MtrCurrQaxRef_Amp_f32
VehSpd_Kph_f32MtrVoltDaxFF_Volt_f32
MtrQuad_Cnt_u08MtrVoltQaxFF_Volt_f32
FastDataAccessBufIndex_Cnt_M_u16MtrCurrAngle_Rev_f32
CurrentGainSvc_Cnt_lgcMtrTrqCmdSign_Cnt_s16
MtrPosComputationDelay_Rad_f32

Module Internal Variables

This section identifies the name, range and resolutions for module specific data created by this module. If there are no range restrictions on the variable, the term “FULL” is placed into the table for legal range.

Variable NameResolution

Legal Range

(min)

Legal Range

(max)

Software Segment
MtrVelFiltFFSV_MtrRadpS_M_s11p200.00000095367431640625-11181118CURRCMD_START_SEC_VAR_CLEARED_32
MtrVelFiltPISV_MtrRadpS_M_s11p200.00000095367431640625-11181118CURRCMD_START_SEC_VAR_CLEARED_32
MtrVelFilt_RadpSec_D_f32Single Precision Float-11181118CURRCMD_START_SEC_VAR_CLEARED_32
MtrMaxCurrDaxRef_Amps_D_f32Single Precision Float0200CURRCMD_START_SEC_VAR_CLEARED_32
MtrCurrQaxRef_Amp_D_f32Single Precision Float-220220CURRCMD_START_SEC_VAR_CLEARED_32
MtrCurrDaxRef_Amp_D_f32Single Precision Float-220220CURRCMD_START_SEC_VAR_CLEARED_32
PeakTorque_MtrNm_D_f32Single Precision Float-8.88.8CURRCMD_START_SEC_VAR_CLEARED_32
MRFMtrVelFiltPI_MtrRadpS_D_f32Single Precision Float-11181118CURRCMD_START_SEC_VAR_CLEARED_32
ElecPosDelayComp_Rad_D_f32Single Precision Float-2*pi2*piCURRCMD_START_SEC_VAR_CLEARED_32
KpqGain_Uls_D_f32Single Precision Float0100CURRCMD_START_SEC_VAR_CLEARED_32
KiqGain_Uls_D_f32Single Precision Float0100CURRCMD_START_SEC_VAR_CLEARED_32
KpdGain_Uls_D_f32Single Precision Float0100CURRCMD_START_SEC_VAR_CLEARED_32
KidGain_Uls_D_f32Single Precision Float0100CURRCMD_START_SEC_VAR_CLEARED_32
IdMin_Amp_D_f32Single Precision Float-220220CURRCMD_START_SEC_VAR_CLEARED_32
IqMin_Amp_D_f32Single Precision Float-220220CURRCMD_START_SEC_VAR_CLEARED_32
IqMax_Amp_D_f32Single Precision Float-220220CURRCMD_START_SEC_VAR_CLEARED_32
IdMax_Amp_D_f32Single Precision Float-220220CURRCMD_START_SEC_VAR_CLEARED_32
ImSqMin_AmpSq_D_f32Single Precision Float0\96800CURRCMD_START_SEC_VAR_CLEARED_32
LimitedMRFMtrTrqCmd_MtrNm_D_f32Single Precision Float-8.88.8CURRCMD_START_SEC_VAR_CLEARED_32
PhsAdvPeak_Rad_D_f32Single Precision Float-2*pi2*piCURRCMD_START_SEC_VAR_CLEARED_32
CosDelta_Cnt_M_f32Single Precision Float-11CURRCMD_START_SEC_VAR_CLEARED_32
SinDelta_Cnt_M_f32Single Precision Float-11CURRCMD_START_SEC_VAR_CLEARED_32
EstKe_VpRadpS_M_f32Single Precision Float0.0250.075CURRCMD_START_SEC_VAR_CLEARED_32
TermXq_Uls_M_f32Single Precision Float-9090CURRCMD_START_SEC_VAR_CLEARED_32
TermXd_Uls_M_f32Single Precision Float-6060CURRCMD_START_SEC_VAR_CLEARED_32
TermEgR_Amp_M_f32Single Precision Float-40504050CURRCMD_START_SEC_VAR_CLEARED_32
TermVR2_AmpSq_M_f32Single Precision Float14400810000CURRCMD_START_SEC_VAR_CLEARED_32
TermEgRZ_Amp_M_f32Single Precision Float-55CURRCMD_START_SEC_VAR_CLEARED_32
TermVRZ_Amp_M_f32Single Precision Float0.02900CURRCMD_START_SEC_VAR_CLEARED_32
TermVR_Amp_M_f32Single Precision Float120900CURRCMD_START_SEC_VAR_CLEARED_32
Reluctance_Henry_M_f32Single Precision Float0.00020.0005CURRCMD_START_SEC_VAR_CLEARED_32
LocateMinImNIter_Cnt_D_u16105CURRCMD_START_SEC_VAR_CLEARED_16
LocateTrqExNIter_Cnt_D_u16105CURRCMD_START_SEC_VAR_CLEARED_16
CurrCmd_IdBoostAmount_Amp_D_f32Single Precision FloatSee Data DictionarySee Data DictionaryCURRCMD_START_SEC_VAR_CLEARED_32

User defined typedef definition/declaration

This section documents any user types uniquely used for the module.

Typedef NameElement NameUser Defined Type

Legal Range

(min)

Legal Range

(max)

None

Constant Data Dictionary

Calibration Constants

This section lists the calibrations used by the module. For details on calibration constants, refer to the Data Dictionary for the application.

Constant Name
k_a0IdSlope_Uls_f32
k_a1IdSlope_Uls_f32
k_a2IdSlope_Uls_f32
k_MtrVelFiltFFKn_Cnt_u16
k_MtrVelFiltPIKn_Cnt_u16
k_MtrMaxCurr_AmpsSq_f32
k_IdrefMtrVelOffset_RadpSec_f32
k_K2Slope_RadpSecpNm_f32
k_K3VelIntercep_RadpSec_f32
k_NoofPoles_Uls_f32
k_PIGainVspdCutoff_kph_f32
t_KpqGainX_MtrRadpSec_u12p4[8]
t_KpqGainY_Uls_u6p10[8]
t_KiqGainX_MtrRadpSec_u12p4[8]
t_KpdGainX_MtrRadpSec_u12p4[8]
t_KpdGainY_Uls_u6p10[8]
t_KidGainX_MtrRadpSec_u12p4[8]
t_KidGainY_Uls_u10p6[8]
t_RefDeltaPoints_Rad_f32[8]
t_Q13VltgSchedXTbl_MtrRadpS_u12p4[10]
t_Q13VltgSchedYTbl_Volt_u5p11[10]
t_Q24VltgSchedXTbl_MtrRadpS_u12p4[10]
t_Q24VltgSchedYTbl_Volt_u5p11[10]
k_IdqRefTrqTol_Rad_f32
k_IdqRefTrqNIter_Cnt_u16
k_IdqRefIminTol_Amp_f32
k_IdqRefLocateRefNIter_Cnt_u16
k_deadtimeVScale_Uls_f32
k_IdBoostGain_Uls_f32
k_IdBoostVRThreshScl_Uls_f32
t_IdBoostTrqCmdX_MtrNm_u4p12
t_IdBoostTrqCharSclY_Uls_u1p15

Program(fixed) Constants

Embedded Constants

All embedded constants whose values are provided in Eng units will be evaluated to the equivalent counts by using the FPM_InitFixedPoint_m() macro within the #define statement.

Local

Constant NameResolutionUnitsValue
D_SQRT3OVR2_ULS_F32Single Precision FloatUls0.866025403784
D_MTRPOLESDIV2_CNT_F32Single Precision FloatCnt3.0
D_2OVRSQRT3_ULS_F32Single Precision FloatUls1.15470053837925
D_NEG2OVRSQRT3_ULS_F32Single Precision FloatUls-1.15470053837925F
D_ROUND_ULS_F32Single Precision FloatUls0.5
D_NEGROUND_ULS_F32Single Precision FloatUls-0.5
D_NEG_ULS_F32Single Precision FloatUls- 1
D_MAXCURRENT_AMP_F32Single Precision FloatAmp220
D_SIZERDLTAPOINTS_CNT_U161CntTableSize_m(t_RefDeltaPoints_Rad_f32)
D_MAXDELTAPOINTSSIZE_CNT_U161CntD_SIZERDLTAPOINTS_CNT_U16 – 1U)
D_PIPLUSPIOVER4_ULS_F32Single Precision FloatULSD_PI_ULS_F32+( D_2PI_ULS_F32/4)
D_VECUMAX_VOLTS_F32Single Precision FloatVolts31.0F

Global

This section lists the global constants used by the module. For details on global constants, refer to the Data Dictionary for the application.

Constant Name
D_ZERO_ULS_F32
D_180OVRPI_ULS_F32
D_ONE_ULS_F32
D_QUADRANT3_CNT_U8
D_QUADRANT1_CNT_U8
D_2PI_ULS_F32
D_ZERO_CNT_U16
D_VECUMIN_VOLTS_F32

Module specific Lookup Tables Constants

(This is for lookup tables (arrays) with fixed values, same name as other tables)

Constant NameResolutionValueSoftware Segment
None

Functions/Macros used by the Sub-Modules

Library Functions / Macros

The library and functions / Macros that are called by the various sub modules are identified below,

  1. FPM_FloatToFixed_m

  2. LPF_SvUpdate_s16InFixKTrunc_m

  3. LPF_OpUpdate_s16InFixKTrunc_m

  4. FPM_FixedToFloat_m

  5. Sqrtf

  6. Abs_f32_m

  7. atan2f

  8. IntplVarXY_u16_u16Xu16Y_Cnt

  9. Sinf

  10. Cosf

Data Hiding Functions

Global Functions/Macros Defined by this Module

None

Local Functions/Macros Used by this MDD only

Local Function #1

Function NameParabolicInterpolationTypeMinMaxUTP Tol.
Arguments PassedIntpolPoints_Uls_T_f32[6]Float32--
Return ValueParaIntpol_Uls_T_f32Float32N/AN/A

Description

Local Function #2

Function NameCalculateImVSIdqTypeMinMaxUTP Tol.
Arguments PassedIdRef_Amp_T_f32Float32-220+220-
IqRef_Amp_T_f32Float32-220+220-
Return ValueImVSIdq_AmpSq_T_f32Float32096800

Description

Local Function #3

Function NameCalculateIqTypeMinMaxUTP Tol.
Arguments PassedTorquecmd_MtrNm_T_f32Float32-8.88.8
IdRef_Amp_T_f32Float32-220220
Return ValueIqRefTmp_Amp_T_f32Float32-220220

Description

Local Function #4

Function NameCurrtoVoltTestTypeMinMaxUTP Tol.
Arguments PassedIqRef_Amp_T_f32Float32-220220
IdRef_Amp_T_f32Float32-220220
*VqR_Amp_T_f32Float32-220220
*VdR_Amp_T_f32Float32-220220
Return ValueVoltTest_Uls_T_lgcBooleanFalseTrue

Description

Local Function #5

Function NameCalcTorqueTypeMinMaxUTP Tol.
Arguments PassedCosDelta_Cnt_T_f32Float3201
SinDelta_Cnt_T_f32Float3201
*IdMax_Amp_T_f32Float32-220220
Return ValueTorqueCalc_MtrNm_T_f32Float32-8.88.8

Description

Local Function #6

Function NameLocateTrqExtremeseTypeMinMaxUTP Tol.
Arguments PassedMtrTrqCmd_MtrNm_T_f32Float32-8.88.8
*IdMax_Amp_T_f32Float32-220220
*PhsAdvPeak_Rad_T_f32Float32-2*pi+2*pi
Return ValueTorqueState_MtrNm_T_f32Float32-8.88.8

Description

Local Function #7

Function NameLocateMinimumImTypeMinMaxUTP Tol.
Arguments PassedMtrTrqCmd_MtrNm_T_f32Float32-8.88.8
* IdMin_Amp_T_f32Float32-220220
* IqMin_Amp_T_f32Float32-220220
Return ValueImSqrMin_AmpSq_T_f32Float32096800

Description

Software Module Implementation

Runtime Environment (RTE) Initial Values

This section lists the initial values of data written by this module but controlled by the RTE. After RTE initialization, the data in this table will contain these values.

DataValue
Rte_InitValue_DaxIntegralGain_Uls_f320
Rte_InitValue_DaxPropotionalGain_Uls_f320
Rte_InitValue_EstKe_VpRadpS_f320
Rte_InitValue_EstLd_Henry_f320
Rte_InitValue_EstLq_Henry_f320
Rte_InitValue_EstR_Ohm_f320
Rte_InitValue_MRFMtrVel_MtrRadpS_f320
Rte_InitValue_MRFTrqCmdScl_MtrNm_f320
Rte_InitValue_MtrCurrAngle_Rev_f320
Rte_InitValue_MtrCurrDaxRef_Amp_f320
Rte_InitValue_MtrCurrQaxRef_Amp_f320
Rte_InitValue_MtrPosComputationDelay_Deg_f320
Rte_InitValue_MtrTrqCmdSign_Cnt_s160
Rte_InitValue_MtrVoltDaxFF_Volt_f320
Rte_InitValue_MtrVoltQaxFF_Volt_f320
Rte_InitValue_QaxIntegralGain_Uls_f320
Rte_InitValue_QaxPropotionalGain_Uls_f320
Rte_InitValue_VehSpd_Kph_f320
FastDataAccessBufIndex0

Initialization Functions

CurrCmd_Init

Program Flow Start

Rte_Call_CurrCmd_Per1_CP0_CheckpointReached()

Processing


Periodic Functions

Per: CurrCmd_Per1

Design Rationale

None

Program Flow Start

Rte_Call_CurrCmd_Per1_CP0_CheckpointReached()

Store Module Inputs to Local copies

WriteAccessBufIndex_Cnt_T_u16= (FastDataAccessBufIndex_Cnt_M_u16&1)^1;

MRFMtrTrqCmd_MtrNm_T_f32=Rte_Iread_CurrCmd_Per1_MRFTrqCmdScl_MtrNm_f32

MRFMtrVel_MtrRadpS_T_f32=Rte_Iread_CurrCmd_Per1_MRFMtrVel_MtrRadpS_f32

EstKe_VpRadpS_T_f32=Rte_Iread_CurrCmd_Per1_EstKe_VpRadpS_f32

EstR_Ohm_T_f32=Rte_Iread_CurrCmd_Per1_EstR_Ohm_f32

EstLd_Henry_T_f32=Rte_Iread_CurrCmd_Per1_EstLd_Henry_f32

EstLq_Henry_T_f32=Rte_Iread_CurrCmd_Per1_EstLq_Henry_f32

VehSpd_Kph_T_f32=Rte_Iread_CurrCmd_Per1_VehSpd_Kph_f32

MtrQuad_Cnt_T_u8 = Rte_Iread_CurrCmd_Per1_MtrQuad_Cnt_u08

CurrentGainSvc_Cnt_T_lgc = Rte_IRead_CurrCmd_Per1_CurrentGainSvc_Cnt_lgc()

Vecu_Volt_T_f32 = Limit_m(Vecu_Volt_T_f32, D_VECUMIN_VOLTS_F32, D_VECUMAX_VOLTS_F32)

Store Local copy of outputs into Module Outputs

MtrDaxIntegralGain_Uls_M_f32[WriteAccessBufIndex_Cnt_T_u16] = KidGain_Uls_T_f32

MtrDaxPropotionalGain_Uls_M_f32[WriteAccessBufIndex_Cnt_T_u16] = KpdGain_Uls_T_f32

MtrQaxIntegralGain_Uls_M_f32[WriteAccessBufIndex_Cnt_T_u16] = KiqGain_Uls_T_f32

MtrQaxPropotionalGain_Uls_M_f32[WriteAccessBufIndex_Cnt_T_u16] = KpqGain_Uls_T_f32

MtrCurrQaxRef_Amp_M_f32[WriteAccessBufIndex_Cnt_T_u16] = MtrCurrQaxRef_Amp_T_f32

MtrCurrDaxRef_Amp_M_f32[WriteAccessBufIndex_Cnt_T_u16] = MtrCurrDaxRef_Amp_T_f32

Rte_Iwrite_CurrCmd_Per1_MtrCurrDaxRef_Amp_f32(MtrCurrDaxRef_Amp_T_f32)

Rte_Iwrite_CurrCmd_Per1_MtrCurrQaxRef_Amp_f32(MtrCurrQaxRef_Amp_T_f32)

MtrVoltDaxFF_Volt_M_f32[WriteAccessBufIndex_Cnt_T_u16]=MtrVoltDaxFF_Volt_T_f32

MtrVoltQaxFF_Volt_M_f32[WriteAccessBufIndex_Cnt_T_u16]=MtrVoltQaxFF_Volt_T_f32

Rte_Iwrite_CurrCmd_Per1_MtrVoltDaxFF_Volt_f32(MtrVoltDaxFF_Volt_T_f32)

Rte_Iwrite_CurrCmd_Per1_MtrVoltQaxFF_Volt_f32(MtrVoltQaxFF_Volt_T_f32)

Rte_Iwrite_CurrCmd_Per1_MtrCurrAngle_Rev_f32(MtrCurrElecAngle_Rev_T_f32)

Rte_Iwrite_CurrCmd_Per1_MtrTrqCmdSign_Cnt_s16(Sign_f32_m(MRFMtrTrqCmd_MtrNm_T_f32))

MtrPosComputationDelay_Rad_M_f32[WriteAccessBufIndex_Cnt_T_u16] = ElecPosDelayComp_Rad_T_f32

Program Flow End

Rte_Call_CurrCmd_Per1_CP1_CheckpointReached()

Fault Recovery Functions

None

Shutdown Functions

None

Interrupt Functions

None

Serial Communication Functions

None

Execution Requirements

Execution Sequence of the Module

(Describe in words relevant details about the execution sequence of the different sub modules.)

Execution Rates for sub-modules called by the Scheduler

This table serves as reference for the Scheduler design

Function NameCalling FrequencySystem State(s) in which the function is called
CurrCmd_Per12msALL
CurrCmd_InitAt initALL

Execution Requirements for Serial Communication Functions

Function NameSub-Module called by (Serial Comm Function Name)
None


Memory Map Definition Requirements

Sub Modules (Functions)

This table identifies the software segments for functions identified in this module.

Name of Sub ModuleSoftware Segment
CurrCmd_Per1RTE_START_SEC_AP_CURRCMD_APPL_CODE
CurrCmd_InitRTE_START_SEC_AP_CURRCMD_APPL_CODE

Local Functions

This table identifies the software segments for local functions identified in this module.

Name of Sub ModuleSoftware Segment
ParabolicInterpolationRTE_START_SEC_AP_CURRCMD_APPL_CODE
CalculateIqRTE_START_SEC_AP_CURRCMD_APPL_CODE
CalculateImVSIdqRTE_START_SEC_AP_CURRCMD_APPL_CODE
CurrtoVoltTestRTE_START_SEC_AP_CURRCMD_APPL_CODE
CalcTorqueRTE_START_SEC_AP_CURRCMD_APPL_CODE
LocateTrqExtremesRTE_START_SEC_AP_CURRCMD_APPL_CODE
LocateMinimumImRTE_START_SEC_AP_CURRCMD_APPL_CODE

Known Issues / Limitations With Design

  1. Global Macro’s are not unit tested.

Revision Control Log

Item #Rev #Change DescriptionDateAuthor Initials
11.0Initial version15th-May-12KPIT-RT
22.0Partial implementation of SF-99B v00420-Sep-12OT
33.0Checkpoints and memmap statements added20-Nov-12Selva
44.0,5.0Implementation of SF99 v8

23-Mar-13

19-Apr-13

Selva
66.0Corrected for A5883. Corrected LocateMinimumIm21-Oct-13Selva
77.0Updated for v11 FDD99B6-Nov-13Selva
88,0Corrected for NewDelta calculation / Updated for v11 FDD99B UTP fixes8-Nov-13Selva
99.0Updated for V12 of FDD SF9926-Nov-13Selva
Last modified October 12, 2025: Initial commit (0347a62)