PICurrentContrl

Module -- PICurrCntrl

High-Level Description

Non-AUTOSAR PI driver required to perform EPS motor control PWM profiles.

Figures

Diagram – Function Data Sharing

This diagram shows all data that is shared between functions within the module.

Module Inputs and Outputs

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

(Note: Full variable names required in table.)

(Note: All global variables including End Of Line data used should be shown here)

Module Inputs (Global Variable Name)Module Outputs (Global Variable Name)
MtrCurrQax_Amp_f32EstKe_VpRadpS_f32
MtrCurrDax_Amp_f32MtrCurrQaxFinalRef_Amp_f32
MtrCurrQaxRef_Amp_f32MtrDaxVoltage_Volt_f32
MtrCurrDaxRef_Amp_f32MtrQaxVoltage_Volt_f32
PIDaxIntegralGain_Uls_f32ModIdx_Uls_u16p16
PIDaxPropotionalGain_Uls_f32PhaseAdvanceFinal_Rev_u0p16
PIQaxIntegralGain_Uls_f32CommOffset_Cnt_u16
PIQaxPropotionalGain_Uls_f32MtrVolt_Volt_f32
ElecPosDelayComp_Rad_f32MtrCurrDaxIntg_Volt_f32
MtrVoltDaxFF_Volt_f32MtrCurrQaxIntg_Volt_f32
MtrVoltQaxFF_Volt_f32DervLambdaAlphaDiag_Volt_T_f32
Vecu_Volt_f32DervLambdaBetaDiag_Volt_T_f32
ModIdxSrlComSvcDft_Cnt_lgcSlowDataAccessBufIndex_Cnt_M_u16
SysState_Cnt_Enum
MtrCurrOffComOffset_Cnt_u16
MtrCurrQaxRpl_Amp_M_f32
MtrCurrQaxCog_Amp_M_f32
MRFMtrVel_MtrRadpS_f32
MtrVoltDaxFF_Volt_f32
MtrVoltQaxFF_Volt_f32
MtrCurrQaxRpl_Amp_f32
FastDataAccessBufIndex_Cnt_M_u16
EstKe_VpRadpS_f32
CorrMtrPosElec_Rev_f32
EstR_Ohm_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.

(Note: If no module specific variables are used by the design, place the text “None” in the first Variable Name cell in the table)

Variable NameResolution

Legal Range

(min)

Legal Range

(max)

Software Segment
MtrCurrQaxPrevIntg_Volt_M_f32single precision float-3131PICURRCNTRL_START_SEC_VAR_CLEARED_32
MtrCurrDaxPrevIntg_Volt_M_f32single precision float-3131PICURRCNTRL_START_SEC_VAR_CLEARED_32
MtrVoltQaxPrevFinalLimit_Volt_M_f32single precision float-3131PICURRCNTRL_START_SEC_VAR_CLEARED_32
MtrVoltPrevDaxFinal_Volt_M_f32single precision float-3131PICURRCNTRL_START_SEC_VAR_CLEARED_32
MtrCurrQaxError_Amp_D_f32single precision float-220220PICURRCNTRL_START_SEC_VAR_CLEARED_32
MtrCurrDaxError_Amp_D_f32single precision float-220220PICURRCNTRL_START_SEC_VAR_CLEARED_32
MtrVoltQaxFinal_Volt_D_f32single precision float-3131PICURRCNTRL_START_SEC_VAR_CLEARED_32
MtrVoltQaxFinalLimit_Volt_D_f32single precision float-3131PICURRCNTRL_START_SEC_VAR_CLEARED_32
MtrVoltDaxFinal_Volt_D_f32single precision float-3131PICURRCNTRL_START_SEC_VAR_CLEARED_32
MtrVoltQaxProp_Volt_D_f32single precision float-3131PICURRCNTRL_START_SEC_VAR_CLEARED_32
MtrVoltDaxProp_Volt_D_f32single precision float-3131PICURRCNTRL_START_SEC_VAR_CLEARED_32
MtrVoltQaxInt_Volt_D_f32single precision float-3131PICURRCNTRL_START_SEC_VAR_CLEARED_32
MtrVoltDaxInt_Volt_D_f32single precision float-3131PICURRCNTRL_START_SEC_VAR_CLEARED_32
PICurrCntrl_MtrCurrQax_Amp_D_f32single precision floatFULLFULLPICURRCNTRL_START_SEC_VAR_CLEARED_32
PICurrCntrl_MtrCurrDax_Amp_D_f32single precision floatFULLFULLPICURRCNTRL_START_SEC_VAR_CLEARED_32
MtrVoltDax_Volt_M_f32[2]single precision floatSee data DictionarySee data DictionaryPICURRCNTRL_START_SEC_VAR_CLEARED_32
MtrVoltQax_Volt_M_f32[2]single precision floatSee data DictionarySee data DictionaryPICURRCNTRL_START_SEC_VAR_CLEARED_32
MtrCurrQaxFinalRef_Amp_M_f32[2]single precision floatSee data DictionarySee data DictionaryPICURRCNTRL_START_SEC_VAR_CLEARED_32
PICurrCntrl_DervLambdaQax_Volt_D_f32single precision floatSee data DictionarySee data DictionaryPICURRCNTRL_START_SEC_VAR_CLEARED_32
PICurrCntrl_DervLambdaDax_Volt_D_f32single precision floatSee data DictionarySee data DictionaryPICURRCNTRL_START_SEC_VAR_CLEARED_32

User defined typedef definition/declaration

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

Variable NameTypedef NameStorage TypeSafety Critical Classification
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.

(Note: If no calibrations are used by the design, place the text “None” in the first location in the table)

Constant Name
k_PiSamplingTs_Sec_f32
t_CommOffsetTblX_Uls_u3p13[2]
t_CommOffsetTblY_Cnt_u16[2]
k_NoofPoles_Uls_f32

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_SCALERADTOCNTS_ULS_F32Single Precision FloatUnitless10430.3783505F
D_REVWITHROUND_ULS_F32Single Precision FloatUnitless65536.5F
D_ROUND_ULS_F32Single Precision FloatUnitless0.5F
D_DEG2RAD_ULS_F32Single Precision FloatUnitless0.0174532925199F
D_GAIN_ULS_F32Single Precision FloatUnitless0.5
D_VECUMAX_VOLTS_F32Single Precision FloatVolts31
D_SQRT3OVR2_ULS_F32Single Precision FloatUnitless0.866025403784

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_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 functions / Macros that are called by the various sub modules are identified below,

  1. IntplVarXY_u16_u16Xu16Y_Cnt_m()

  2. FPM_FloatToFixed_m

  3. Sign_f32_m

  4. Sqrtf

  5. Sinf

  6. Cosf

Data Hiding Functions

The data hiding functions / macros used in this module are identified below,

Rte_ModeType_StaMd_Mode

MtrCntrl_Read_MtrCurrQax_Amp_f32

MtrCntrl_Read_MtrCurrDax_Amp_f32

MtrCntrl_Read_Vecu_Volt_f32

MtrCntrl_Read_ModIdxSrlComSvcDft_Cnt_lgc

MtrCntrl_Read_SysState_Cnt_Enum

MtrCntrl_Read_MtrCurrOffComOffset_Cnt_u16

MtrCntrl_Read_MtrElecPol_Cnt_s8

MtrCntrl_Read_MtrPosElec_Rev_u0p16

MtrCntrl_Write_MtrCurrQaxFinalRef_Amp_f32

MtrCntrl_Write_MtrDaxVoltage_Volt_f32

MtrCntrl_Write_MtrQaxVoltage_Volt_f32

MtrCntrl_Write_ModIdx_Uls_u16p16

MtrCntrl_Write_PhaseAdvanceFinal_Rev_u0p16

MtrCntrl_Write_CommOffset_Cnt_u16

Local Functions/Macros Used by this MDD only

Header file: Ap_MtrCntrl_Cfg.h

Software Module Implementation

Initialization Functions

None.

Periodic Functions

Per: PICurrCntrl_Per1

Design Rationale

This function is responsible for calculating the amount of current to be supplied to the motor. To control the PWM profiles generated for the motor. FastDataAccessBufIndex allows the buffer synchronization between data calculated on slower periodic loop time(2 milli seconds) and are read by faster periodic run time (ie 0.125ms)

Store Module Inputs to Local copies

MtrCntrl_Read_MtrCurrQax_Amp_f32(&MtrCurrQax_Amp_T_f32);

MtrCntrl_Read_MtrCurrDax_Amp_f32(&MtrCurrDax_Amp_T_f32);

MtrCntrl_Read_Vecu_Volt_f32(&Vecu_Volt_T_f32);

MtrCntrl_Read_ModIdxSrlComSvcDft_Cnt_lgc(&ModIdxSrlComSvcDft_Cnt_T_lgc);

MtrCntrl_Read_SysState_Cnt_Enum(&SysState_Cnt_T_Enum);

FwdDataAcessBuffer_Cnt_T_u16= (ActWriteAccBufIndex_Cnt_T_u16)

MtrCurrQaxRef_Amp_T_f32=MtrCurrQaxRef_Amp_M_f32[FwdDataAcessBuffer_Cnt_T_u16];

MtrCurrDaxRef_Amp_T_f32=MtrCurrDaxRef_Amp_M_f32[FwdDataAcessBuffer_Cnt_T_u16];

PIDaxIntegralGain_Uls_T_f32=MtrDaxIntegralGain_Uls_M_f32[FwdDataAcessBuffer_Cnt_T_u16];

PIDaxPropotionalGain_Uls_T_f32=MtrDaxPropotionalGain_Uls_M_f32[FwdDataAcessBuffer_Cnt_T_u16]

PIQaxIntegralGain_Uls_T_f32=MtrQaxIntegralGain_Uls_M_f32[FwdDataAcessBuffer_Cnt_T_u16];

PIQaxPropotionalGain_Uls_T_f32=MtrQaxPropotionalGain_Uls_M_f32[FwdDataAcessBuffer_Cnt_T_u16]

ElecPosDelayComp_Rad_T_f32=MtrPosComputationDelay_Rad_M_f32[FwdDataAcessBuffer_Cnt_T_u16]

MtrVoltDaxFF_Volt_T_f32=MtrVoltDaxFF_Volt_M_f32[FwdDataAcessBuffer_Cnt_T_u16]MtrVoltQaxFF_Volt_T_f32=MtrVoltQaxFF_Volt_M_f32[FwdDataAcessBuffer_Cnt_T_u16];

Vecu_Volt_T_f32 = Limit_m(Vecu_Volt_T_f32, D_VECUMIN_VOLTS_F32, D_VECUMAX_VOLTS_F32)

Program Flow Start

Store Local copy of outputs into Module Outputs

MtrCntrl_Write_MtrCurrQaxFinalRef_Amp_f32(MtrCurrQaxFinalRef_Amp_T_f32)

MtrCntrl_Write_MtrDaxVoltage_Volt_f32(MtrDaxVoltage_Volt_T_f32)

MtrCntrl_Write_MtrQaxVoltage_Volt_f32(MtrQaxVoltage_Volt_T_f32)

MtrCntrl_Write_ModIdx_Uls_u16p16(FPM_FloatToFixed_m(ModIdx_Uls_T_u16p16))

MtrCntrl_Write_PhaseAdvanceFinal_Rev_u0p16(PhaseAdvanceFinal_Rev_T_u0p16)

MtrCntrl_Write_CommOffset_Cnt_u16(CommOffset_Cnt_T_u16)

MtrCntrl_Write_MtrVolt_Volt_f32(MtrVoltCmdFinal_Volt_T_f32)

MtrCntrl_Write_MtrCurrDaxIntg_Volt_f32(MtrCurrDaxIntg_Volt_T_f32)

MtrCntrl_Write_MtrCurrQaxIntg_Volt_f32(MtrCurrQaxIntg_Volt_T_f32)

MtrCurrQaxFinalRef_Amp_M_f32[SlowDataAccessBufIndex_Cnt_M_u16]= MtrCurrQaxFinalRef_Amp_T_f32;

MtrVoltDax_Volt_M_f32[SlowDataAccessBufIndex_Cnt_M_u16] = MtrDaxVoltage_Volt_T_f32;

MtrVoltQax_Volt_M_f32[SlowDataAccessBufIndex_Cnt_M_u16] = MtrQaxVoltage_Volt_T_f32

Program Flow End

N/A

Periodic Functions

Per: PICurrCntrl_Per2

Design Rationale

This function is responsible for calculating the amount of current to be supplied to the motor. To control the PWM profiles generated for the motor.

SlowDataAccessBufIndex allows the buffer synchronization between data calculated on faster periodic loop time(125 micro seconds) and are read by slower periodic run time (ie 2ms)

Store Module Inputs to Local copies

ReadBuffer_Cnt_T_u16 = SlowDataAccessBufIndex_Cnt_M_u16

WriteBuffer_Cnt_T_u16 = (ReadBuffer_Cnt_T_u16 & 1U) ^ 1U

SlowDataAccessBufIndex_Cnt_M_u16 = WriteBuffer_Cnt_T_u16

EstKe_VpRadpS_T_f32= Rte_IRead_PICurrCntrl_Per2_EstKe_VpRadpS_f32();

EstR_Ohm_T_f32 = Rte_IRead_PICurrCntrl_Per2_EstR_Ohm_f32();

MRFMtrVel_MtrRadpS_T_f32 = Rte_IRead_PICurrCntrl_Per2_MRFMtrVel_MtrRadpS_f32();

CorrMtrPosElec_Rev_T_f32 = Rte_IRead_PICurrCntrl_Per2_CorrMtrPosElec_Rev_f32();

MtrCurrDaxRef_Amp_T_f32 = Rte_IRead_PICurrCntrl_Per2_MtrCurrDaxRef_Amp_f32();

MtrVoltDax_Volt_T_f32 = MtrVoltDax_Volt_M_f32[ReadBuffer_Cnt_T_u16];

MtrVoltQax_Volt_T_f32 = MtrVoltQax_Volt_M_f32[ReadBuffer_Cnt_T_u16];

MtrCurrQaxFinalRef_Amp_T_f32 = MtrCurrQaxFinalRef_Amp_M_f32[ReadBuffer_Cnt_T_u16]; Program Flow Start

Rte_Call_PICurrCntrl_Per2_CP0_CheckpointReached()

Processing

Store Local copy of outputs into Module Outputs

Rte_IWrite_PICurrCntrl_Per2_DervLambdaAlphaDiag_Volt_f32(DervLambdaAlphaDiag_Volt_T_f32);

Rte_IWrite_PICurrCntrl_Per2_DervLambdaBetaDiag_Volt_f32(DervLambdaBetaDiag_Volt_T_f32);

Program Flow End

Rte_Call_PICurrCntrl_Per2_CP1_CheckpointReached()

Execution Requirements

Execution Sequence of the Module

N/A

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

PICurrCntrl_Per1

0.125msAll

PICurrCntrl_Per2

2msAll

Execution Requirements for Serial Communication Functions

Function NameSub-Module called by (Serial Comm Function Name)
N/A


Memory Map Definition Requirements

Sub Modules (Functions)

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

Name of Sub ModuleSoftware Segment
PICurrCntrl_Per1PICurrCntrl_CODE
PICurrCntrl_Per2RTE_START_SEC_AP_PICURRCNTRL_APPL_CODE

Local Functions

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

  1. - Denotes functions that are vector call-backs only included to avoid compiler errors.

Name of Sub ModuleSoftware Segment
N/A


Known Issues / Limitations With Design

The computation of commoffset and ModIndex service defeat part of FDD15D is implemented in this component inaddition to 99B requirements

The reason for the implementation is to keep the sine voltage driver common across components

Revision Control Log

Item #Rev #Change DescriptionDateAuthor Initials
11.0Initial release with changes for IPM6/12/2012AD/KPIT
21.0Changes for memap statements added11/20/2012Selva
32.0

Updated for SF99B –v8 with only changes needed for voltage command

integrity check for torque reasonableness

02/24/2013Selva
43.0,Updated for SF99B –v803/21/2013Selva
54.0Corrected for SF99B –v804/19/2013Selva
65.0Updated for SF99B –v1021-Oct-13Selva
76.0Updated for SF99B –v107-Nov-13Selva
87.0Updated for V12 of FDD SF9927-Nov-13Selva
Last modified October 12, 2025: Initial commit (0347a62)