54 #pragma CODE_SECTION(mainISR,"ramfuncs");
90 #pragma DATA_SECTION(halHandle,"rom_accessed_data");
118 #pragma DATA_SECTION(gUserParams,"rom_accessed_data");
129 extern uint16_t *RamfuncsLoadStart, *RamfuncsLoadEnd, *RamfuncsRunStart;
132 extern uint16_t *econst_start, *econst_end, *econst_ram_load;
133 extern uint16_t *switch_start, *switch_end, *switch_ram_load;
177 memCopy((uint16_t *)&RamfuncsLoadStart,(uint16_t *)&RamfuncsLoadEnd,
178 (uint16_t *)&RamfuncsRunStart);
182 if(*econst_end - *econst_start)
184 memCopy((uint16_t *)&econst_start,(uint16_t *)&econst_end,
185 (uint16_t *)&econst_ram_load);
189 if(*switch_end - *switch_start)
191 memCopy((uint16_t *)&switch_start,(uint16_t *)&switch_end,
192 (uint16_t *)&switch_ram_load);
225 clarkeHandle_I =
CLARKE_init(&clarke_I,
sizeof(clarke_I));
227 clarkeHandle_V =
CLARKE_init(&clarke_V,
sizeof(clarke_V));
329 _iq Kp_Id =
_IQ((0.25 * Ls_d * fullScaleCurrent) / (IsrPeriod_sec
330 * fullScaleVoltage));
340 _iq Ki_Id =
_IQ(RoverLs_d * IsrPeriod_sec);
345 _iq Kp_Iq =
_IQ((0.25 * Ls_q * fullScaleCurrent) / (IsrPeriod_sec
346 * fullScaleVoltage));
351 _iq Ki_Iq =
_IQ(RoverLs_q * IsrPeriod_sec);
357 pidHandle[0] =
PID_init(&pid[0],
sizeof(pid[0]));
359 pidHandle[1] =
PID_init(&pid[1],
sizeof(pid[1]));
361 pidHandle[2] =
PID_init(&pid[2],
sizeof(pid[2]));
413 iparkHandle =
IPARK_init(&ipark,
sizeof(ipark));
416 svgenHandle =
SVGEN_init(&svgen,
sizeof(svgen));
602 &(gIdq_ref_pu.
value[1]));
611 refValue = gIdq_ref_pu.
value[0];
614 fbackValue = gIdq_pu.
value[0];
619 PID_run(pidHandle[1],refValue,fbackValue,&(gVdq_out_pu.
value[0]));
622 refValue = gIdq_ref_pu.
value[1];
625 fbackValue = gIdq_pu.
value[1];
644 PID_run(pidHandle[2],refValue,fbackValue,&(gVdq_out_pu.
value[1]));
668 IPARK_run(iparkHandle,&gVdq_out_pu,&Vab_pu);
710 _iq angleDeltaComp_pu =
_IQmpy(angleDelta_pu,angleCompFactor);
711 uint32_t angleMask = ((uint32_t)0xFFFFFFFF >> (32 -
GLOBAL_Q));
716 angleTmp_pu = angleUncomp_pu + angleDeltaComp_pu;
720 angleComp_pu =
_IQabs(angleTmp_pu) & angleMask;
723 if(angleTmp_pu <
_IQ(0.0))
725 angleComp_pu = -angleComp_pu;
728 return(angleComp_pu);
743 * fullScaleInductance)) / log(2.0));
744 uint_least8_t Ls_qFmt = 30 - lShift;
745 float_t L_max = fullScaleInductance * pow(2.0,lShift);
763 _iq alpha_sf,beta_sf;
766 if(numCurrentSensors == 3)
771 else if(numCurrentSensors == 2)
795 _iq alpha_sf,beta_sf;
798 if(numVoltageSensors == 3)
842 _iq Torque_Nm = Torque_Flux_Iq_Nm + Torque_Ls_Id_Iq_Nm;
876 gMotorVars.
Vd = gVdq_out_pu.
value[0];
877 gMotorVars.
Vq = gVdq_out_pu.
value[1];
float_t EST_getFlux_VpHz(EST_Handle handle)
#define USER_NUM_CURRENT_SENSORS
Defines the number of current sensors used.
void EST_setFlag_enableForceAngle(EST_Handle handle, const bool state)
IPARK_Handle IPARK_init(void *pMemory, const size_t numBytes)
_iq EST_getLs_coarse_max_pu(EST_Handle handle)
void updateGlobalVariables(EST_Handle handle)
Update the global variables (gMotorVars).
void HAL_enableGlobalInts(HAL_Handle handle)
void HAL_enableAdcInts(HAL_Handle handle)
USER_ErrorCode_e UserErrorCode
static void HAL_readAdcDataWithOffsets(HAL_Handle handle, HAL_AdcData_t *pAdcData)
_iq USER_computeFlux_pu_to_VpHz_sf(void)
Computes the scale factor needed to convert from per unit to V/Hz.
interrupt void mainISR(void)
The main ISR that implements the motor control.
static void PID_setUi(PID_Handle handle, const _iq Ui)
_iq EST_getSpeed_krpm(EST_Handle handle)
USER_Params gUserParams
The user parameters.
void EST_setupEstIdleState(EST_Handle handle)
HAL_AdcData_t gAdcData
Defines the ADC data.
_iq gTorque_Ls_Id_Iq_pu_to_Nm_sf
IPARK_Obj ipark
the inverse Park transform object
static void HAL_writePwmData(HAL_Handle handle, HAL_PwmData_t *pPwmData)
struct _EST_Obj_ * EST_Handle
void EST_setIdle(EST_Handle handle)
void HAL_writeDrvData(HAL_Handle handle, DRV_SPI_8301_Vars_t *Spi_8301_Vars)
#define USER_VD_SF
Defines the direct voltage (Vd) scale factor.
void setupClarke_V(CLARKE_Handle handle, const uint_least8_t numVoltageSensors)
Setup the Clarke transform for either 2 or 3 sensors.
static void HAL_acqAdcInt(HAL_Handle handle, const ADC_IntNumber_e intNumber)
#define USER_IQ_FULL_SCALE_VOLTAGE_V
Defines full scale value for the IQ30 variable of Voltage inside the system.
void softwareUpdate1p6(EST_Handle handle)
Call this function to fix 1p6. This is only used for F2806xF/M.
#define USER_MOTOR_NUM_POLE_PAIRS
void memCopy(uint16_t *srcStartAddr, uint16_t *srcEndAddr, uint16_t *dstAddr)
bool Flag_enableForceAngle
#define USER_PWM_FREQ_kHz
Defines the Pulse Width Modulation (PWM) frequency, kHz.
EST_Handle estHandle
the handle for the estimator
static void PID_setMinMax(PID_Handle handle, const _iq outMin, const _iq outMax)
static void SVGEN_run(SVGEN_Handle handle, const MATH_vec2 *pVab, MATH_vec3 *pT)
HAL_PwmData_t gPwmData
Defines the PWM data.
static _iq PID_getFbackValue(PID_Handle handle)
#define MATH_ONE_OVER_THREE
void USER_setParams(USER_Params *pUserParams)
Sets the user parameter values.
void EST_setLs_qFmt(EST_Handle handle, const uint_least8_t Ls_qFmt)
CLARKE_Obj clarke_I
the current Clarke transform object
#define V_A_offset
ADC voltage offsets for A, B, and C phases.
CLARKE_Handle clarkeHandle_V
_iq EST_getLs_d_pu(EST_Handle handle)
#define I_A_offset
ADC current offsets for A, B, and C phases.
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.
CTRL_Handle CTRL_init(void *pMemory, const size_t numBytes)
void HAL_setupFaults(HAL_Handle handle)
EST_Handle EST_init(void *pMemory, const size_t numBytes)
float_t EST_getLs_d_H(EST_Handle handle)
void EST_setFlag_enableRsRecalc(EST_Handle handle, const bool state)
MATH_vec3 gOffsets_I_pu
the offsets for the current feedback
static void PID_setGains(PID_Handle handle, const _iq Kp, const _iq Ki, const _iq Kd)
static void HAL_enablePwm(HAL_Handle handle)
#define USER_MAX_VS_MAG_PU
Defines the maximum Voltage vector (Vs) magnitude allowed. This value sets the maximum magnitude for ...
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.
void HAL_enableDrv(HAL_Handle handle)
HAL_Handle halHandle
The hal handle.
_iq angleDelayComp(const _iq fm_pu, const _iq angleUncomp_pu)
The angleDelayComp function compensates for the delay introduced.
_iq EST_getOneOverDcBus_pu(EST_Handle handle)
_iq EST_getFlux_pu(EST_Handle handle)
void HAL_setupDrvSpi(HAL_Handle handle, DRV_SPI_8301_Vars_t *Spi_8301_Vars)
float_t EST_getLs_q_H(EST_Handle handle)
#define USER_EST_HANDLE_ADDRESS
Defines the address of estimator handle.
void HAL_enableDebugInt(HAL_Handle handle)
void CTRL_setupEstIdleState(CTRL_Handle handle)
#define USER_NUM_CTRL_TICKS_PER_SPEED_TICK
Defines the number of controller clock ticks per speed controller clock tick.
CLARKE_Handle CLARKE_init(void *pMemory, const size_t numBytes)
volatile MOTOR_Vars_t gMotorVars
void CTRL_setUserMotorParams(CTRL_Handle handle)
static void IPARK_run(IPARK_Handle handle, const MATH_vec2 *pInVec, MATH_vec2 *pOutVec)
EST_State_e EST_getState(EST_Handle handle)
SVGEN_Handle svgenHandle
the handle for the space vector generator
CLARKE_Handle clarkeHandle_I
_iq EST_getFm_pu(EST_Handle handle)
#define MOTOR_Vars_INIT
Initialization values of global variables.
_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)
_iq EST_getLs_q_pu(EST_Handle handle)
static void CLARKE_setNumSensors(CLARKE_Handle handle, const uint_least8_t numSensors)
float_t EST_getRs_Ohm(EST_Handle handle)
#define USER_IQ_FULL_SCALE_FREQ_Hz
CURRENTS AND VOLTAGES.
MATH_vec2 gIdq_pu
measured values
SVGEN_Obj svgen
the space vector generator object
#define USER_ISR_FREQ_Hz
Defines the Interrupt Service Routine (ISR) frequency, Hz.
static void IPARK_setPhasor(IPARK_Handle handle, const MATH_vec2 *pPhasor)
MATH_vec2 gIdq_ref_pu
Iq references.
_iq EST_getAngle_pu(EST_Handle handle)
static void HAL_disablePwm(HAL_Handle handle)
MATH_vec3 gOffsets_V_pu
the offsets for the voltage feedback
PID_Handle PID_init(void *pMemory, const size_t numBytes)
HAL_Handle HAL_init(void *pMemory, const size_t numBytes)
static void CLARKE_run(CLARKE_Handle handle, const MATH_vec3 *pInVec, MATH_vec2 *pOutVec)
_iq gTorque_Flux_Iq_pu_to_Nm_sf
MATH_vec2 gVdq_out_pu
Vd and Vq from the current controllers.
#define USER_VOLTAGE_FILTER_POLE_rps
Defines the analog voltage filter pole location, rad/s.
CLARKE_Obj clarke_V
the voltage Clarke transform object
#define USER_NUM_VOLTAGE_SENSORS
Defines the number of voltage (phase) sensors.
void EST_setLs_q_pu(EST_Handle handle, const _iq Ls_q_pu)
#define USER_IQ_FULL_SCALE_CURRENT_A
Defines the full scale current for the IQ variables, A.
static void PID_run_spd(PID_Handle handle, const _iq refValue, const _iq fbackValue, _iq *pOutValue)
CTRL_Handle ctrlHandle
The controller handle.
#define MATH_ONE_OVER_SQRT_THREE
static void HAL_initIntVectorTable(HAL_Handle handle)
bool EST_updateState(EST_Handle handle, const _iq Id_target_pu)
float_t EST_getRr_Ohm(EST_Handle handle)
void HAL_setParams(HAL_Handle handle, const USER_Params *pUserParams)
void HAL_readDrvData(HAL_Handle handle, DRV_SPI_8301_Vars_t *Spi_8301_Vars)
#define USER_MOTOR_MAX_CURRENT
void setupClarke_I(CLARKE_Handle handle, const uint_least8_t numCurrentSensors)
Setup the Clarke transform for either 2 or 3 sensors.
void EST_getIdq_pu(EST_Handle handle, MATH_vec2 *pIdq_pu)
void USER_checkForErrors(USER_Params *pUserParams)
Checks for errors in the user parameter values.
SVGEN_Handle SVGEN_init(void *pMemory, const size_t numBytes)
void EST_setEstParams(EST_Handle handle, USER_Params *pUserParams)
_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...
_iq USER_computeFlux_pu_to_Wb_sf(void)
Computes the scale factor needed to convert from per unit to Wb.
void EST_setLs_d_pu(EST_Handle handle, const _iq Ls_d_pu)
static void PID_run(PID_Handle handle, const _iq refValue, const _iq fbackValue, _iq *pOutValue)
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.