57 #pragma CODE_SECTION(mainISR,"ramfuncs");
67 #define LED_BLINK_FREQ_Hz 5
129 extern uint16_t *RamfuncsLoadStart, *RamfuncsLoadEnd, *RamfuncsRunStart;
157 uint_least8_t estNumber = 0;
160 uint_least8_t ctrlNumber = 0;
169 memCopy((uint16_t *)&RamfuncsLoadStart,(uint16_t *)&RamfuncsLoadEnd,(uint16_t *)&RamfuncsRunStart);
205 controller_obj = (
CTRL_Obj *)ctrlHandle;
226 clarkeHandle_I =
CLARKE_init(&clarke_I,
sizeof(clarke_I));
227 clarkeHandle_V =
CLARKE_init(&clarke_V,
sizeof(clarke_V));
246 iparkHandle =
IPARK_init(&ipark,
sizeof(ipark));
250 parkHandle =
PARK_init(&park,
sizeof(park));
254 svgenHandle =
SVGEN_init(&svgen,
sizeof(svgen));
257 trajHandle_Iq =
TRAJ_init(&traj_Iq,
sizeof(traj_Iq));
272 IPD_HFI_LP_SPD_FILT_HZ,
273 IPD_HFI_HP_IQ_FILT_HZ,
276 IPD_HFI_EXC_MAG_COARSE_PU,
277 IPD_HFI_EXC_MAG_FINE_PU,
278 IPD_HFI_EXC_TIME_COARSE_S,
279 IPD_HFI_EXC_TIME_FINE_S);
294 AFSEL_MAX_IQ_REF_HFI,
295 AFSEL_MAX_IQ_REF_EST,
416 if(flag_ctrlStateChanged)
420 if(ctrlState == CTRL_State_OffLine)
425 else if(ctrlState == CTRL_State_OnLine)
435 for(cnt=0;cnt<3;cnt++)
439 for(cnt=0;cnt<3;cnt++)
449 for(cnt=0;cnt<3;cnt++)
453 for(cnt=0;cnt<3;cnt++)
464 else if(ctrlState == CTRL_State_Idle)
478 (ctrlState > CTRL_State_Idle) &&
537 uint_least32_t Periods[IPD_HFI_TRAJ_State_NumStates] = {0,0};
539 Periods[IPD_HFI_TRAJ_State_Coarse] = period;
540 Periods[IPD_HFI_TRAJ_State_Fine] = period;
549 _iq Mags[4] = {0,0,0,0};
560 uint_least32_t WaitTimes[5] = {0,0,0,0,0};
562 WaitTimes[IPD_HFI_State_Coarse] = coarse_s;
563 WaitTimes[IPD_HFI_State_Fine] = fine_s;
638 _iq angle_pu,angle_hfi_pu,angle_est_pu;
639 _iq speed_pu,speed_hfi_pu,speed_est_pu;
670 if(count_isr >= numIsrTicksPerCtrlTick)
674 bool flag_enableSpeedCtrl;
675 bool flag_enableCurrentCtrl;
776 flag_enableSpeedCtrl,
777 flag_enableCurrentCtrl);
780 if(ctrlState == CTRL_State_OnLine)
792 IPARK_run(iparkHandle,&Vdq_out_pu,&Vab_out_pu);
797 else if(ctrlState == CTRL_State_OffLine)
820 _iq alpha_sf,beta_sf;
824 if(numCurrentSensors == 3)
829 else if(numCurrentSensors == 2)
850 _iq alpha_sf,beta_sf;
854 if(numVoltageSensors == 3)
float_t EST_getFlux_VpHz(EST_Handle handle)
void EST_setFlag_enableForceAngle(EST_Handle handle, const bool state)
float ipd_waitTime_fine_sec
CTRL_Obj ctrl
Defines the CTRL object.
IPARK_Handle iparkHandle
the handle for the inverse Park transform
IPARK_Handle IPARK_init(void *pMemory, const size_t numBytes)
void CTRL_incrCounter_isr(CTRL_Handle handle)
static void TRAJ_setTargetValue(TRAJ_Handle handle, const _iq targetValue)
struct _FStart_Handle_ * FStart_Handle
#define MAX_ACCEL_KRPMPS_SF
Defines the speed acceleration scale factor.
void HAL_enableGlobalInts(HAL_Handle handle)
void HAL_enableAdcInts(HAL_Handle handle)
USER_ErrorCode_e UserErrorCode
bool Flag_MotorIdentified
void updateGlobalVariables_motor(EST_Handle estHandle)
Updates the global motor variables.
uint_least16_t gCounter_updateGlobals
A counter that is denotes when to update the global variables.
_iq USER_computeFlux_pu_to_VpHz_sf(void)
Computes the scale factor needed to convert from per unit to V/Hz.
static void TRAJ_setMaxDelta(TRAJ_Handle handle, const _iq maxDelta)
static void PARK_setPhasor(PARK_Handle handle, const MATH_vec2 *pPhasor)
_iq EST_getSpeed_krpm(EST_Handle handle)
_iq gTorque_Flux_Iq_pu_to_Nm_sf
CLARKE_Obj clarke_V
the voltage Clarke transform object
static _iq TRAJ_getIntValue(TRAJ_Handle handle)
void AFSEL_run(AFSEL_Handle handle)
void AFSEL_enable(AFSEL_Handle handle)
void CTRL_getVdq_out_pu(CTRL_Handle handle, MATH_vec2 *pVdq_out_pu)
void USER_calcPIgains(CTRL_Handle handle)
Updates Id and Iq PI gains.
#define USER_EST_FREQ_Hz
Defines the estimator frequency, Hz.
bool Flag_enablePowerWarp
static void HAL_writePwmData(HAL_Handle handle, HAL_PwmData_t *pPwmData)
void EST_setMaxCurrentSlope_pu(EST_Handle handle, const _iq maxCurrentSlope_pu)
interrupt void mainISR(void)
The main interrupt service (ISR) routine.
_iq FStart_run(FStart_Handle handle, const _iq fm_Hz, const _iq flux_VpHz)
#define NUM_MAIN_TICKS_FOR_GLOBAL_VARIABLE_UPDATE
Defines the number of main iterations before global variables are updated.
CLARKE_Handle clarkeHandle_V
the handle for the voltage Clarke transform
struct _EST_Obj_ * EST_Handle
void HAL_writeDrvData(HAL_Handle handle, DRV_SPI_8301_Vars_t *Spi_8301_Vars)
bool CTRL_isError(CTRL_Handle handle)
void AFSEL_setParams(AFSEL_Handle handle, const _iq IqMaxLfEst, const _iq IqMaxHfEst, const _iq IqSlopeLfEst, const _iq IqSlopeHfEst, const _iq freqLow_pu, const _iq freqHigh_pu, IPD_HFI_Handle hfiHandle, EST_Handle estHandle)
uint_least16_t CTRL_getNumIsrTicksPerCtrlTick(CTRL_Handle handle)
AFSEL_Handle AFSEL_init(void)
FStart_Handle FStart_init(void)
void USER_softwareUpdate1p6(CTRL_Handle handle)
Recalculates Inductances with the correct Q Format.
static void HAL_acqAdcInt(HAL_Handle handle, const ADC_IntNumber_e intNumber)
_iq EST_get_pu_to_krpm_sf(EST_Handle handle)
_iq AFSEL_getAngle_pu(AFSEL_Handle handle)
TRAJ_Handle trajHandle_spd
the handle for the speed trajectory
#define USER_IQ_FULL_SCALE_VOLTAGE_V
Defines full scale value for the IQ30 variable of Voltage inside the system.
uint_least8_t numCurrentSensors
void memCopy(uint16_t *srcStartAddr, uint16_t *srcEndAddr, uint16_t *dstAddr)
void CTRL_setKi(CTRL_Handle handle, const CTRL_Type_e ctrlType, const _iq Ki)
HAL_AdcData_t gAdcData
Defines the ADC data.
bool Flag_enableForceAngle
TRAJ_Handle trajHandle_Iq
the trajectory handle for the Iq current reference
static void SVGEN_run(SVGEN_Handle handle, const MATH_vec2 *pVab, MATH_vec3 *pT)
void CTRL_setFlag_enableCtrl(CTRL_Handle handle, const bool state)
void CTRL_setFlag_enableSpeedCtrl(CTRL_Handle handle, const bool state)
void IPD_HFI_disable(IPD_HFI_Handle handle)
void IPD_HFI_setTrajPeriods(IPD_HFI_Handle handle, const uint_least32_t *pPeriods)
_iq AFSEL_getIqSlope(AFSEL_Handle handle)
AFSEL_Handle afselHandle
the handle for the afselect general algorithm
MATH_vec2 * CTRL_getIdq_in_addr(CTRL_Handle handle)
void AFSEL_updateState(AFSEL_Handle handle)
#define MATH_ONE_OVER_THREE
void IPD_HFI_setAngle_pu(IPD_HFI_Handle handle, const _iq angle_pu)
void USER_setParams(USER_Params *pUserParams)
Sets the user parameter values.
_iq IPD_HFI_getSpeed_lp_pu(IPD_HFI_Handle handle)
uint_least16_t CTRL_getCount_isr(CTRL_Handle handle)
void setupClarke_V(CLARKE_Handle handle, const uint_least8_t numVoltageSensors)
Sets the number of voltage sensors.
void AFSEL_disable(AFSEL_Handle handle)
_iq IPD_HFI_getVdValue(IPD_HFI_Handle handle)
static void CLARKE_setScaleFactors(CLARKE_Handle handle, const _iq alpha_sf, const _iq beta_sf)
Defines the structures, global initialization, and functions used in MAIN.
void CTRL_setMaxAccel_pu(CTRL_Handle handle, const _iq maxAccel_pu)
_iq USER_computeFlux(CTRL_Handle handle, const _iq sf)
Computes Flux in Wb or V/Hz depending on the scale factor sent as parameter.
TRAJ_Handle TRAJ_init(void *pMemory, const size_t numBytes)
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)
static void HAL_enablePwm(HAL_Handle handle)
void CTRL_setParams(CTRL_Handle handle, USER_Params *pUserParams)
volatile MOTOR_Vars_t gMotorVars
void IPD_HFI_run(IPD_HFI_Handle handle, const MATH_vec2 *pIab_pu)
USER_ErrorCode_e USER_getErrorCode(USER_Params *pUserParams)
Gets the error code in the user parameters.
void HAL_enableDrv(HAL_Handle handle)
void CTRL_resetCounter_isr(CTRL_Handle handle)
void IPD_HFI_setWaitTimes(IPD_HFI_Handle handle, const uint_least32_t *pWaitTimes)
TRAJ_Handle trajHandle_Id
the handle for the Id trajectory
bool EST_doSpeedCtrl(EST_Handle handle)
_iq EST_getFlux_pu(EST_Handle handle)
#define USER_MOTOR_RATED_FLUX
IPD_HFI_Handle ipdHandle
the handle for the ipd algorithm
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)
bool CTRL_getFlag_enableUserMotorParams(CTRL_Handle handle)
void HAL_enableDebugInt(HAL_Handle handle)
CLARKE_Handle CLARKE_init(void *pMemory, const size_t numBytes)
PARK_Obj park
the Park transform object
CTRL_State_e CTRL_getState(CTRL_Handle handle)
void IPD_HFI_setParams(IPD_HFI_Handle handle, float_t estFreq_Hz, float_t excFreq_Hz, float_t lpFilterCutOffFreq_Hz, float_t hpFilterCutOffFreq_Hz, float_t iqFullScaleFreq_Hz, float_t Kspd, float_t excMag_coarse_pu, float_t excMag_fine_pu, float_t waitTime_coarse_sec, float_t waitTime_fine_sec)
static void IPARK_run(IPARK_Handle handle, const MATH_vec2 *pInVec, MATH_vec2 *pOutVec)
bool Flag_enableUserParams
EST_State_e EST_getState(EST_Handle handle)
bool Flag_enableOffsetcalc
void setupClarke_I(CLARKE_Handle handle, const uint_least8_t numCurrentSensors)
Sets the number of current sensors.
PARK_Handle parkHandle
the handle for the Park object
_iq EST_getFm_pu(EST_Handle handle)
_iq CTRL_getKp(CTRL_Handle handle, const CTRL_Type_e ctrlType)
#define MOTOR_Vars_INIT
Initialization values of global variables.
bool Flag_Latch_softwareUpdate
_iq AFSEL_getFreq_pu(AFSEL_Handle handle)
_iq USER_computeTorque_Flux_Iq_pu_to_Nm_sf(void)
Computes the scale factor needed to convert from torque created by flux and Iq, from per unit to Nm...
float_t EST_getIdRated(EST_Handle handle)
void CTRL_runOffLine(CTRL_Handle handle, HAL_Handle halHandle, const HAL_AdcData_t *pAdcData, HAL_PwmData_t *pPwmData)
_iq gTorque_Ls_Id_Iq_pu_to_Nm_sf
static void CLARKE_setNumSensors(CLARKE_Handle handle, const uint_least8_t numSensors)
float_t EST_getRs_Ohm(EST_Handle handle)
CTRL_Handle CTRL_initCtrl(const uint_least8_t estNumber, void *pMemory, const size_t numBytes)
bool Flag_enableSpeedCtrl
bool AFSEL_isEnabled(AFSEL_Handle handle)
bool EST_doCurrentCtrl(EST_Handle handle)
#define USER_IQ_FULL_SCALE_FREQ_Hz
CURRENTS AND VOLTAGES.
void CTRL_setup_user(CTRL_Handle handle, const _iq angle_pu, const _iq speed_ref_pu, const _iq speed_fb_pu, const _iq speed_outMax_pu, const MATH_vec2 *pIdq_offset_pu, const MATH_vec2 *pVdq_offset_pu, const bool flag_enableSpeedCtrl, const bool flag_enableCurrentCtrl)
HAL_Handle halHandle
The hal handle.
void CTRL_setFlag_enablePowerWarp(CTRL_Handle handle, const bool state)
IPD_HFI_Handle IPD_HFI_init(void)
#define USER_ISR_FREQ_Hz
Defines the Interrupt Service Routine (ISR) frequency, Hz.
static void IPARK_setPhasor(IPARK_Handle handle, const MATH_vec2 *pPhasor)
_iq IPD_HFI_getAngle_pu(IPD_HFI_Handle handle)
bool CTRL_updateState(CTRL_Handle handle)
_iq EST_getAngle_pu(EST_Handle handle)
_iq CTRL_getKi(CTRL_Handle handle, const CTRL_Type_e ctrlType)
static void HAL_disablePwm(HAL_Handle handle)
void CTRL_runPiOnly(CTRL_Handle handle)
static void TRAJ_setMaxValue(TRAJ_Handle handle, const _iq maxValue)
struct IPD_HFI_Obj * IPD_HFI_Handle
bool EST_isMotorIdentified(EST_Handle handle)
FStart_Handle fstartHandle
the handle for the flying start algorithm
bool IPD_HFI_isEnabled(IPD_HFI_Handle handle)
_iq USER_computeTorque_Nm(CTRL_Handle handle, const _iq torque_Flux_sf, const _iq torque_Ls_sf)
Computes Torque in Nm.
void CTRL_setFlag_enableOffset(CTRL_Handle handle, const bool state)
HAL_Handle HAL_init(void *pMemory, const size_t numBytes)
static void CLARKE_run(CLARKE_Handle handle, const MATH_vec3 *pInVec, MATH_vec2 *pOutVec)
void AFSEL_setup(AFSEL_Handle handle, const _iq angleLf_pu, const _iq freqLf_pu, const _iq angleHf_pu, const _iq freqHf_pu)
static void PARK_run(PARK_Handle handle, const MATH_vec2 *pInVec, MATH_vec2 *pOutVec)
void CTRL_setFlag_enableDcBusComp(CTRL_Handle handle, const bool state)
HAL_PwmData_t gPwmData
Defines the PWM data.
CTRL_Handle ctrlHandle
The controller handle.
SVGEN_Obj svgen
the space vector generator object
float ipd_waitTime_coarse_sec
_iq EST_getMaxCurrentSlope_pu(EST_Handle handle)
void CTRL_setFlag_enableUserMotorParams(CTRL_Handle handle, const bool state)
static void HAL_readAdcData(HAL_Handle handle, HAL_AdcData_t *pAdcData)
void updateKpKiGains(CTRL_Handle handle)
Updates Kp and Ki gains in the controller object.
static _iq HAL_getBias(HAL_Handle handle, const HAL_SensorType_e sensorType, uint_least8_t sensorNumber)
void IPD_HFI_setKspd_pu(IPD_HFI_Handle handle, const _iq Kspd_pu)
_iq CTRL_getSpd_int_ref_pu(CTRL_Handle handle)
#define MATH_ONE_OVER_SQRT_THREE
void IPD_HFI_updateState(IPD_HFI_Handle handle)
CLARKE_Obj clarke_I
the current Clarke transform object
static void HAL_initIntVectorTable(HAL_Handle handle)
static void HAL_setBias(HAL_Handle handle, const HAL_SensorType_e sensorType, uint_least8_t sensorNumber, const _iq bias)
static void HAL_updateAdcBias(HAL_Handle handle)
PARK_Handle PARK_init(void *pMemory, const size_t numBytes)
void CTRL_getVersion(CTRL_Handle handle, CTRL_Version *pVersion)
SVGEN_Handle svgenHandle
the handle for the space vector generator
float_t EST_getRr_Ohm(EST_Handle handle)
void CTRL_computePhasor(const _iq angle_pu, MATH_vec2 *pPhasor)
TRAJ_Obj traj_Iq
the trajectory for Iq current reference
void HAL_setParams(HAL_Handle handle, const USER_Params *pUserParams)
void IPD_HFI_setId_sum(IPD_HFI_Handle handle, const _iq Id_sum_pu)
CLARKE_Handle clarkeHandle_I
the handle for the current Clarke transform
_iq AFSEL_getIqMax(AFSEL_Handle handle)
void HAL_readDrvData(HAL_Handle handle, DRV_SPI_8301_Vars_t *Spi_8301_Vars)
void IPD_HFI_setTrajMags(IPD_HFI_Handle handle, const _iq *pMags)
static void TRAJ_run(TRAJ_Handle handle)
struct _AFSEL_Obj_ * AFSEL_Handle
void FStart_setParams(FStart_Handle handle, const float_t iqFullScaleVoltage_V, const float_t iqFullScaleFreq_Hz, const float_t estFreq_Hz, const float_t maxFlux_VpHz)
void USER_checkForErrors(USER_Params *pUserParams)
Checks for errors in the user parameter values.
CTRL_Obj * controller_obj
USER_Params gUserParams
The user parameters.
SVGEN_Handle SVGEN_init(void *pMemory, const size_t numBytes)
EST_Handle estHandle
the handle for the estimator
void IPD_HFI_enable(IPD_HFI_Handle handle)
_iq USER_computeTorque_Ls_Id_Iq_pu_to_Nm_sf(void)
Computes the scale factor needed to convert from torque created by Ld, Lq, Id and Iq...
IPARK_Obj ipark
the inverse Park transform object
float_t iqFullScaleFreq_Hz
void CTRL_setSpd_ref_krpm(CTRL_Handle handle, const _iq spd_ref_krpm)
_iq USER_computeFlux_pu_to_Wb_sf(void)
Computes the scale factor needed to convert from per unit to Wb.
#define LED_BLINK_FREQ_Hz
void CTRL_setKp(CTRL_Handle handle, const CTRL_Type_e ctrlType, const _iq Kp)
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)