53 #if defined(FLASH) && !defined(F2802xF)
54 #pragma CODE_SECTION(mainISR,"ramfuncs");
64 #define LED_BLINK_FREQ_Hz 5
96 #pragma DATA_SECTION(halHandle,"rom_accessed_data");
101 #pragma DATA_SECTION(gUserParams,"rom_accessed_data");
115 #pragma DATA_SECTION(ctrl,"rom_accessed_data");
126 extern uint16_t *RamfuncsLoadStart, *RamfuncsLoadEnd, *RamfuncsRunStart;
129 extern uint16_t *econst_start, *econst_end, *econst_ram_load;
130 extern uint16_t *switch_start, *switch_end, *switch_ram_load;
159 uint_least8_t estNumber = 0;
162 uint_least8_t ctrlNumber = 0;
171 memCopy((uint16_t *)&RamfuncsLoadStart,(uint16_t *)&RamfuncsLoadEnd,(uint16_t *)&RamfuncsRunStart);
175 if(*econst_end - *econst_start)
177 memCopy((uint16_t *)&econst_start,(uint16_t *)&econst_end,(uint16_t *)&econst_ram_load);
181 if(*switch_end - *switch_start)
183 memCopy((uint16_t *)&switch_start,(uint16_t *)&switch_end,(uint16_t *)&switch_ram_load);
222 controller_obj = (
CTRL_Obj *)ctrlHandle;
243 clarkeHandle_I =
CLARKE_init(&clarke_I,
sizeof(clarke_I));
244 clarkeHandle_V =
CLARKE_init(&clarke_V,
sizeof(clarke_V));
263 iparkHandle =
IPARK_init(&ipark,
sizeof(ipark));
267 parkHandle =
PARK_init(&park,
sizeof(park));
271 svgenHandle =
SVGEN_init(&svgen,
sizeof(svgen));
370 if(flag_ctrlStateChanged)
374 if(ctrlState == CTRL_State_OffLine)
379 else if(ctrlState == CTRL_State_OnLine)
389 for(cnt=0;cnt<3;cnt++)
393 for(cnt=0;cnt<3;cnt++)
403 for(cnt=0;cnt<3;cnt++)
407 for(cnt=0;cnt<3;cnt++)
414 else if(ctrlState == CTRL_State_Idle)
422 (ctrlState > CTRL_State_Idle) &&
546 if(count_isr >= numIsrTicksPerCtrlTick)
550 bool flag_enableSpeedCtrl;
551 bool flag_enableCurrentCtrl;
595 Vdq_offset_pu.
value[0] = 0;
596 Vdq_offset_pu.
value[1] = 0;
605 flag_enableSpeedCtrl,
606 flag_enableCurrentCtrl);
609 if(ctrlState == CTRL_State_OnLine)
621 IPARK_run(iparkHandle,&Vdq_out_pu,&Vab_out_pu);
626 else if(ctrlState == CTRL_State_OffLine)
649 _iq alpha_sf,beta_sf;
653 if(numCurrentSensors == 3)
658 else if(numCurrentSensors == 2)
679 _iq alpha_sf,beta_sf;
683 if(numVoltageSensors == 3)
float_t EST_getFlux_VpHz(EST_Handle handle)
void EST_setFlag_enableForceAngle(EST_Handle handle, const bool state)
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)
#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 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 CTRL_getVdq_out_pu(CTRL_Handle handle, MATH_vec2 *pVdq_out_pu)
void USER_calcPIgains(CTRL_Handle handle)
Updates Id and Iq PI gains.
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.
#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)
uint_least16_t CTRL_getNumIsrTicksPerCtrlTick(CTRL_Handle handle)
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)
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
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)
MATH_vec2 * CTRL_getIdq_in_addr(CTRL_Handle handle)
#define MATH_ONE_OVER_THREE
void USER_setParams(USER_Params *pUserParams)
Sets the user parameter values.
uint_least16_t CTRL_getCount_isr(CTRL_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.
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)
void setupClarke_V(CLARKE_Handle handle, const uint_least8_t numVoltageSensors)
Sets the number of voltage sensors.
static void HAL_enablePwm(HAL_Handle handle)
void CTRL_setParams(CTRL_Handle handle, USER_Params *pUserParams)
volatile MOTOR_Vars_t gMotorVars
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)
TRAJ_Handle trajHandle_Id
the handle for the Id trajectory
bool EST_doSpeedCtrl(EST_Handle handle)
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
void setupClarke_I(CLARKE_Handle handle, const uint_least8_t numCurrentSensors)
Sets the number of current sensors.
CTRL_State_e CTRL_getState(CTRL_Handle handle)
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
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 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 EST_doCurrentCtrl(EST_Handle handle)
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)
#define USER_ISR_FREQ_Hz
Defines the Interrupt Service Routine (ISR) frequency, Hz.
static void IPARK_setPhasor(IPARK_Handle handle, const MATH_vec2 *pPhasor)
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)
bool EST_isMotorIdentified(EST_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)
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
_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)
_iq CTRL_getSpd_int_ref_pu(CTRL_Handle handle)
#define MATH_ONE_OVER_SQRT_THREE
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)
void HAL_setParams(HAL_Handle handle, const USER_Params *pUserParams)
CLARKE_Handle clarkeHandle_I
the handle for the current Clarke transform
void HAL_readDrvData(HAL_Handle handle, DRV_SPI_8301_Vars_t *Spi_8301_Vars)
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
_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
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)
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)