53 #pragma CODE_SECTION(mainISR,"ramfuncs");
62 #define LED_BLINK_FREQ_Hz 5
75 #pragma DATA_SECTION(halHandle,"rom_accessed_data");
80 #pragma DATA_SECTION(gUserParams,"rom_accessed_data");
105 #pragma DATA_SECTION(ctrl,"rom_accessed_data");
116 extern uint16_t *RamfuncsLoadStart, *RamfuncsLoadEnd, *RamfuncsRunStart;
119 extern uint16_t *econst_start, *econst_end, *econst_ram_load;
120 extern uint16_t *switch_start, *switch_end, *switch_ram_load;
149 uint_least8_t estNumber = 0;
152 uint_least8_t ctrlNumber = 0;
161 memCopy((uint16_t *)&RamfuncsLoadStart,(uint16_t *)&RamfuncsLoadEnd,(uint16_t *)&RamfuncsRunStart);
165 if(*econst_end - *econst_start)
167 memCopy((uint16_t *)&econst_start,(uint16_t *)&econst_end,(uint16_t *)&econst_ram_load);
171 if(*switch_end - *switch_start)
173 memCopy((uint16_t *)&switch_start,(uint16_t *)&switch_end,(uint16_t *)&switch_ram_load);
212 controller_obj = (
CTRL_Obj *)ctrlHandle;
233 femHandle =
FEM_init(&fem,
sizeof(fem));
244 (uint32_t)USER_SYSTEM_FREQ_MHz * 1000000,
347 if(flag_ctrlStateChanged)
351 if(ctrlState == CTRL_State_OffLine)
356 else if(ctrlState == CTRL_State_OnLine)
389 else if(ctrlState == CTRL_State_Idle)
397 (ctrlState > CTRL_State_Idle) &&
537 CTRL_run(ctrlHandle,halHandle,&gAdcData,&gPwmData);
644 if(abs(RsError_Ohm) < (gMotorVars.
Rs_Ohm * 0.05))
float_t EST_getFlux_VpHz(EST_Handle handle)
_iq gTorque_Flux_Iq_pu_to_Nm_sf
#define USER_SYSTEM_FREQ_MHz
CLOCKS & TIMERS.
float_t EST_getRsOnLine_Ohm(EST_Handle handle)
void EST_setFlag_enableForceAngle(EST_Handle handle, const bool state)
#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 CTRL_run(CTRL_Handle handle, HAL_Handle halHandle, const HAL_AdcData_t *pAdcData, HAL_PwmData_t *pPwmData)
static void HAL_reloadTimer(HAL_Handle handle, const uint_least8_t timerNumber)
_iq USER_computeFlux_pu_to_VpHz_sf(void)
Computes the scale factor needed to convert from per unit to V/Hz.
_iq EST_getSpeed_krpm(EST_Handle handle)
void EST_setRsOnLineId_mag_pu(EST_Handle handle, const _iq Id_mag_pu)
void USER_calcPIgains(CTRL_Handle handle)
Updates Id and Iq PI gains.
CPU_USAGE_Handle cpu_usageHandle
float_t gCpuUsagePercentageMax
uint_least16_t gCounter_updateGlobals
A counter that is denotes when to update the global variables.
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)
#define NUM_MAIN_TICKS_FOR_GLOBAL_VARIABLE_UPDATE
Defines the number of main iterations before global variables are updated.
void HAL_writeDrvData(HAL_Handle handle, DRV_SPI_8301_Vars_t *Spi_8301_Vars)
bool CTRL_isError(CTRL_Handle handle)
static uint32_t FEM_getErrorCnt(FEM_Handle handle)
HAL_PwmData_t gPwmData
Defines the PWM data.
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)
#define USER_IQ_FULL_SCALE_VOLTAGE_V
Defines full scale value for the IQ30 variable of Voltage inside the system.
uint32_t gMaxDeltaCntObserved
_iq gTorque_Ls_Id_Iq_pu_to_Nm_sf
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)
bool Flag_enableForceAngle
void CTRL_setFlag_enableCtrl(CTRL_Handle handle, const bool state)
static uint32_t CPU_USAGE_getAvgDeltaCntObserved(CPU_USAGE_Handle handle)
void CTRL_setFlag_enableSpeedCtrl(CTRL_Handle handle, const bool state)
float_t gCpuUsagePercentageMin
void EST_setRsOnLine_pu(EST_Handle handle, const _iq Rs_pu)
bool Flag_Latch_softwareUpdate
void USER_setParams(USER_Params *pUserParams)
Sets the user parameter values.
void EST_setFlag_updateRs(EST_Handle handle, const bool state)
void updateGlobalVariables_motor(CTRL_Handle handle)
Updates the global motor variables.
#define V_A_offset
ADC voltage offsets for A, B, and C phases.
#define I_A_offset
ADC current offsets for A, B, and C phases.
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.
CTRL_Obj ctrl
Defines the CTRL 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)
USER_Params gUserParams
The user parameters.
void FEM_setParams(FEM_Handle handle, const float_t timerFreq_Hz, const uint32_t timerPeriod_cnts, const float_t spFreq_Hz, const float_t maxError_Hz)
static void HAL_enablePwm(HAL_Handle handle)
void CTRL_setParams(CTRL_Handle handle, USER_Params *pUserParams)
USER_ErrorCode_e USER_getErrorCode(USER_Params *pUserParams)
Gets the error code in the user parameters.
static void FEM_run(FEM_Handle handle)
void HAL_enableDrv(HAL_Handle handle)
void EST_setRsOnLine_qFmt(EST_Handle handle, const uint_least8_t Rs_qFmt)
void updateCPUusage(void)
Updates CPU usage.
void HAL_setupDrvSpi(HAL_Handle handle, DRV_SPI_8301_Vars_t *Spi_8301_Vars)
float_t EST_getLs_q_H(EST_Handle handle)
bool CTRL_getFlag_enableUserMotorParams(CTRL_Handle handle)
void HAL_enableDebugInt(HAL_Handle handle)
CTRL_State_e CTRL_getState(CTRL_Handle handle)
bool Flag_enableUserParams
EST_State_e EST_getState(EST_Handle handle)
bool Flag_enableOffsetcalc
float_t gCpuUsagePercentageAvg
static bool FEM_isFreqError(FEM_Handle handle)
_iq CTRL_getKp(CTRL_Handle handle, const CTRL_Type_e ctrlType)
void CTRL_setup(CTRL_Handle handle)
#define MOTOR_Vars_INIT
Initialization values of global variables.
void EST_setFlag_enableRsOnLine(EST_Handle handle, const bool state)
_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)
interrupt void mainISR(void)
The main interrupt service (ISR) routine.
#define USER_CTRL_FREQ_Hz
Defines the controller frequency, Hz.
static uint32_t HAL_readTimerCnt(HAL_Handle handle, const uint_least8_t timerNumber)
#define LED_BLINK_FREQ_Hz
float_t EST_getRs_Ohm(EST_Handle handle)
CTRL_Handle CTRL_initCtrl(const uint_least8_t estNumber, void *pMemory, const size_t numBytes)
void CTRL_setFlag_enablePowerWarp(CTRL_Handle handle, const bool state)
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.
HAL_AdcData_t gAdcData
Defines the ADC data.
CPU_USAGE_Handle CPU_USAGE_init(void *pMemory, const size_t numBytes)
bool CTRL_updateState(CTRL_Handle handle)
_iq CTRL_getKi(CTRL_Handle handle, const CTRL_Type_e ctrlType)
static void HAL_disablePwm(HAL_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 FEM_updateCnts(FEM_Handle handle, const uint32_t cnt)
static uint32_t CPU_USAGE_getMaxDeltaCntObserved(CPU_USAGE_Handle handle)
HAL_Handle halHandle
The hal handle.
void CTRL_setFlag_enableDcBusComp(CTRL_Handle handle, const bool state)
static uint32_t FEM_getMaxDeltaCntObserved(FEM_Handle handle)
_iq EST_getMaxCurrentSlope_pu(EST_Handle handle)
void CTRL_setFlag_enableUserMotorParams(CTRL_Handle handle, const bool state)
uint_least8_t EST_getRs_qFmt(EST_Handle handle)
#define USER_IQ_FULL_SCALE_CURRENT_A
Defines the full scale current for the IQ variables, A.
static void HAL_readAdcData(HAL_Handle handle, HAL_AdcData_t *pAdcData)
static _iq HAL_getBias(HAL_Handle handle, const HAL_SensorType_e sensorType, uint_least8_t sensorNumber)
volatile MOTOR_Vars_t gMotorVars
static void CPU_USAGE_updateCnts(CPU_USAGE_Handle handle, const uint32_t cnt)
_iq CTRL_getSpd_int_ref_pu(CTRL_Handle handle)
CTRL_Handle ctrlHandle
The controller handle.
static uint32_t CPU_USAGE_getMinDeltaCntObserved(CPU_USAGE_Handle handle)
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)
void CTRL_getVersion(CTRL_Handle handle, CTRL_Version *pVersion)
static uint16_t HAL_readPwmPeriod(HAL_Handle handle, const PWM_Number_e pwmNumber)
void updateKpKiGains(CTRL_Handle handle)
Updates Kp and Ki gains in the controller object.
float_t EST_getRr_Ohm(EST_Handle handle)
void HAL_setParams(HAL_Handle handle, const USER_Params *pUserParams)
static void CPU_USAGE_run(CPU_USAGE_Handle handle)
void EST_setRsOnLineId_pu(EST_Handle handle, const _iq Id_pu)
void runRsOnLine(CTRL_Handle handle)
Runs Rs online.
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.
FEM_Handle FEM_init(void *pMemory, const size_t numBytes)
CTRL_Obj * controller_obj
_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...
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.
void CTRL_setKp(CTRL_Handle handle, const CTRL_Type_e ctrlType, const _iq Kp)
#define USER_NUM_PWM_TICKS_PER_ISR_TICK
DECIMATION.