131 uint_least8_t estNumber = 0;
137 USER_setParams_priv(&gUserParams);
140 halHandle =
HAL_init(&hal,
sizeof(hal));
146 calHandle =
CAL_init(&cal,
sizeof(cal));
152 clarkeHandle_I =
CLARKE_init(&clarke_I,
sizeof(clarke_I));
153 clarkeHandle_V =
CLARKE_init(&clarke_V,
sizeof(clarke_V));
168 iparkHandle =
IPARK_init(&ipark,
sizeof(ipark));
171 parkHandle =
PARK_init(&park,
sizeof(park));
174 piHandle_Id =
PI_init(&pi_Id,
sizeof(pi_Id));
175 piHandle_Iq =
PI_init(&pi_Iq,
sizeof(pi_Iq));
176 piHandle_spd =
PI_init(&pi_spd,
sizeof(pi_spd));
182 svgenHandle =
SVGEN_init(&svgen,
sizeof(svgen));
185 trajHandle_Id =
TRAJ_init(&traj_Id,
sizeof(traj_Id));
195 trajHandle_spd =
TRAJ_init(&traj_spd,
sizeof(traj_spd));
318 if(calState == CAL_State_Done)
388 CAL_run(calHandle,&AdcDataWithOffset);
454 IPARK_run(iparkHandle,&Vdq_out_V,&Vab_out_V);
489 if(numCurrentSensors == 3)
494 else if(numCurrentSensors == 2)
518 if(numVoltageSensors == 3)
543 float_t RdoverLd_rps = Rs_d_Ohm / Ls_d_H;
544 float_t RqoverLq_rps = Rs_q_Ohm / Ls_q_H;
549 float_t Kp_Id = Ls_d_H * BWc_rps;
550 float_t Ki_Id = RdoverLd_rps * currentCtrlPeriod_sec;
552 float_t Kp_Iq = Ls_q_H * BWc_rps;
553 float_t Ki_Iq = RqoverLq_rps * currentCtrlPeriod_sec;
#define USER_SYSTEM_FREQ_MHz
CLOCKS & TIMERS.
EST_State_e gEstState
Global variable for the estimator state.
float_t angleDelayed_sf_sec
void EST_setFlag_enableForceAngle(EST_Handle handle, const bool state)
static void CAL_enable(CAL_Handle handle)
IPARK_Handle IPARK_init(void *pMemory, const size_t numBytes)
#define MATH_ONE_OVER_TWO_PI
CLARKE_Handle clarkeHandle_V
the handle for the voltage Clarke transform
PI_Obj pi_Iq
the Iq PI controller object
TRAJ_Obj traj_spd
the speed trajectory object
static void TRAJ_setTargetValue(TRAJ_Handle handle, const _iq targetValue)
PI_Obj pi_spd
the speed PI controller object
volatile bool gFlag_enableRsRecalc
SVGEN_Obj svgen
the space vector generator object
void HAL_enableGlobalInts(HAL_Handle handle)
void HAL_enableAdcInts(HAL_Handle handle)
float_t EST_getFlux_Wb(EST_Handle handle)
void updateGlobalVariables_motor(EST_Handle estHandle)
Updates the global motor variables.
static void PI_setFfwdValue(PI_Handle handle, const _iq ffwdValue)
float_t gCpuUsagePercentageAvg
static void HAL_readAdcDataWithOffsets(HAL_Handle handle, HAL_AdcData_t *pAdcData)
static void CAL_run(CAL_Handle handle, const HAL_AdcData_t *pAdcData)
static void TRAJ_setMaxDelta(TRAJ_Handle handle, const _iq maxDelta)
float_t gLs_d_H
Global variable for the stator inductance in the direct coordinate direction, Henry.
static _iq TRAJ_getIntValue(TRAJ_Handle handle)
static void HAL_writePwmData(HAL_Handle handle, HAL_PwmData_t *pPwmData)
struct _EST_Obj_ * EST_Handle
void HAL_writeDrvData(HAL_Handle handle, DRV_SPI_8301_Vars_t *Spi_8301_Vars)
PI_Handle piHandle_spd
the handle for the speed PI controller
static void PI_setUi(PI_Handle handle, const _iq Ui)
static void HAL_acqAdcInt(HAL_Handle handle, const ADC_IntNumber_e intNumber)
static void CAL_setFlag_enableAdcOffset(CAL_Handle handle, const bool value)
uint_least8_t numCurrentSensors
bool EST_isEnabled(EST_Handle handle)
volatile float_t gSpeed_Kp
void CAL_setParams(CAL_Handle handle, const USER_Params *pUserParams)
void EST_setParams(EST_Handle handle, USER_Params *pUserParams)
static void SVGEN_run(SVGEN_Handle handle, const MATH_vec2 *pVab, MATH_vec3 *pT)
static uint32_t CPU_USAGE_getAvgDeltaCntObserved(CPU_USAGE_Handle handle)
uint_least16_t numCtrlTicksPerCurrentTick
float_t gId_rs_recalc_ref_A
#define MATH_ONE_OVER_THREE
void USER_setParams(USER_Params *pUserParams)
Sets the user parameter values.
void setupClarke_V(CLARKE_Handle handle, const uint_least8_t numVoltageSensors)
Sets the number of voltage sensors.
float_t EST_computeTorque_Nm(EST_Handle handle)
IPARK_Handle iparkHandle
the handle for the inverse Park transform
static void CLARKE_setScaleFactors(CLARKE_Handle handle, const _iq alpha_sf, const _iq beta_sf)
TRAJ_Handle TRAJ_init(void *pMemory, const size_t numBytes)
void EST_enable(EST_Handle handle)
PI_Obj pi_Id
the Id PI controller object
void HAL_setupFaults(HAL_Handle handle)
float_t EST_getLs_d_H(EST_Handle handle)
void EST_setFlag_enableRsRecalc(EST_Handle handle, const bool state)
static void TRAJ_setIntValue(TRAJ_Handle handle, const _iq intValue)
USER_Params gUserParams
The user parameters.
void EST_getIdq_A(EST_Handle handle, MATH_vec2 *pIdq_A)
static void HAL_enablePwm(HAL_Handle handle)
volatile bool gFlag_runOnLine
void HAL_enableDrv(HAL_Handle handle)
CLARKE_Obj clarke_I
the current Clarke transform object
CPU_USAGE_Handle cpu_usageHandle
EST_Handle EST_initEst(const uint_least8_t estNumber)
TRAJ_Obj traj_Id
the Id trajectory object
PI_Handle PI_init(void *pMemory, const size_t numBytes)
void HAL_setupDrvSpi(HAL_Handle handle, DRV_SPI_8301_Vars_t *Spi_8301_Vars)
uint_least8_t numVoltageSensors
float_t EST_getLs_q_H(EST_Handle handle)
void HAL_enableDebugInt(HAL_Handle handle)
CLARKE_Handle CLARKE_init(void *pMemory, const size_t numBytes)
float_t oneOverDcBus_invV
void sincos_fastRTS(float_t angle_rad, float_t *pSin, float_t *pCos)
Calculates sine and cosine in a single function call, using callable assembly, fast RTS...
volatile bool gFlag_runCal
PARK_Handle parkHandle
the handle for the Park object
IPARK_Obj ipark
the inverse Park transform object
static void IPARK_run(IPARK_Handle handle, const MATH_vec2 *pInVec, MATH_vec2 *pOutVec)
EST_State_e EST_getState(EST_Handle handle)
static void CAL_disable(CAL_Handle handle)
void setupClarke_I(CLARKE_Handle handle, const uint_least8_t numCurrentSensors)
Sets the number of current sensors.
HAL_DacData_t gDacData
Defines the DAC data.
PI_Handle piHandle_Id
the handle for the Id PI controller
PI_Handle piHandle_Iq
the handle for the Iq PI controller
float_t gLs_q_H
Global variable for the stator inductance in the quadrature coordinate direction, Henry...
interrupt void mainISR(void)
The main interrupt service (ISR) routine.
static uint32_t HAL_readTimerCnt(HAL_Handle handle, const uint_least8_t timerNumber)
static _iq CAL_getOffsetValue_V(CAL_Handle handle, const uint_least8_t sensorNumber)
static void CLARKE_setNumSensors(CLARKE_Handle handle, const uint_least8_t numSensors)
float_t EST_getRs_Ohm(EST_Handle handle)
uint_least16_t numCtrlTicksPerSpeedTick
void CPU_USAGE_setParams(CPU_USAGE_Handle handle, const uint32_t timerPeriod_cnts, const uint32_t numDeltaCntsAvg)
#define USER_ISR_FREQ_Hz
Defines the Interrupt Service Routine (ISR) frequency, Hz.
static void IPARK_setPhasor(IPARK_Handle handle, const MATH_vec2 *pPhasor)
CPU_USAGE_Handle CPU_USAGE_init(void *pMemory, const size_t numBytes)
static void HAL_disablePwm(HAL_Handle handle)
static void TRAJ_setMaxValue(TRAJ_Handle handle, const _iq maxValue)
HAL_Obj hal
the hardware abstraction layer object
HAL_Handle HAL_init(void *pMemory, const size_t numBytes)
CAL_Obj cal
the calibrator object
static void CLARKE_run(CLARKE_Handle handle, const MATH_vec3 *pInVec, MATH_vec2 *pOutVec)
static uint32_t CPU_USAGE_getMaxDeltaCntObserved(CPU_USAGE_Handle handle)
HAL_Handle halHandle
the handle for the hardware abstraction layer
float_t gCpuUsagePercentageMin
void updateCPUusage(void)
Updates CPU usage.
static CAL_State_e CAL_getState(CAL_Handle handle)
float_t gFlux_Wb
Global variable for the rotor flux estimate, Wb.
PARK_Obj park
the Park transform object
uint_least32_t ctrlFreq_Hz
CAL_Handle CAL_init(void *pMemory, const size_t numBytes)
void SVGEN_setup(SVGEN_Handle svgenHandle)
static void PI_setMinMax(PI_Handle handle, const _iq outMin, const _iq outMax)
static void PI_setRefValue(PI_Handle handle, const _iq refValue)
CLARKE_Obj clarke_V
the voltage Clarke transform object
static void CPU_USAGE_updateCnts(CPU_USAGE_Handle handle, const uint32_t cnt)
void setupControllers(void)
Setups the controllers.
float_t sqrt_fastRTS(float_t x)
Calculates square root using callable assembly, fast RTS.
volatile bool gFlag_enableSys
Global flag to enable/disable the system.
static uint32_t CPU_USAGE_getMinDeltaCntObserved(CPU_USAGE_Handle handle)
#define MATH_ONE_OVER_SQRT_THREE
volatile bool gFlag_enableForceAngle
TRAJ_Handle trajHandle_spd
the handle for the speed trajectory
static void HAL_initIntVectorTable(HAL_Handle handle)
static float_t MATH_incrAngle(const float_t angle_rad, const float_t angleDelta_rad)
SVGEN_Handle svgenHandle
the handle for the space vector generator
PARK_Handle PARK_init(void *pMemory, const size_t numBytes)
static void PI_setFbackValue(PI_Handle handle, const _iq fbackValue)
EST_OutputData_t gEstOutputData
static uint16_t HAL_readPwmPeriod(HAL_Handle handle, const PWM_Number_e pwmNumber)
HAL_PwmData_t gPwmData
Defines the PWM data.
bool EST_updateState(EST_Handle handle, const _iq Id_target_pu)
CAL_Handle calHandle
the handle for the calibrator
uint_least32_t estFreq_Hz
void EST_disable(EST_Handle handle)
static _iq CAL_getOffsetValue_I(CAL_Handle handle, const uint_least8_t sensorNumber)
void HAL_setParams(HAL_Handle handle, const USER_Params *pUserParams)
static void CPU_USAGE_run(CPU_USAGE_Handle handle)
bool CAL_updateState(CAL_Handle handle)
HAL_AdcData_t gAdcData
Defines the ADC data.
float_t EST_getFe_Hz(EST_Handle handle)
void HAL_readDrvData(HAL_Handle handle, DRV_SPI_8301_Vars_t *Spi_8301_Vars)
float_t maxCurrent_resEst_A
static bool CAL_isEnabled(CAL_Handle handle)
EST_Handle estHandle
the handle for the estimator
volatile float_t gId_ref_A
float_t gTorque_Nm
Global variable for the estimated torque, N*m.
static void TRAJ_run(TRAJ_Handle handle)
TRAJ_Handle trajHandle_Id
the handle for the Id trajectory
volatile float_t gSpeed_Ki
SVGEN_Handle SVGEN_init(void *pMemory, const size_t numBytes)
static void PI_setGains(PI_Handle handle, const _iq Kp, const _iq Ki)
static void PI_run_series(PI_Handle handle, const _iq refValue, const _iq fbackValue, const _iq ffwdValue, _iq *pOutValue)
float_t gCpuUsagePercentageMax
EST_InputData_t gEstInputData
CLARKE_Handle clarkeHandle_I
the handle for the current Clarke transform
static void TRAJ_setMinValue(TRAJ_Handle handle, const _iq minValue)
void EST_run(EST_Handle handle, const MATH_vec2 *pIab_pu, const MATH_vec2 *pVab_pu, const _iq dcBus_pu, const _iq speed_ref_pu)
#define USER_NUM_PWM_TICKS_PER_ISR_TICK
DECIMATION.