instaspin_foc
Modules | Functions | Variables
PROJ_LAB11A

Modules

 Project Overview
 

Functions

void main (void)
 
interrupt void mainISR (void)
 The main ISR that implements the motor control. More...
 
_iq angleDelayComp (const _iq fm_pu, const _iq angleUncomp_pu)
 The angleDelayComp function compensates for the delay introduced. More...
 
void runCurrentIgnore (void)
 
void runCurrentReconstruction (void)
 
void runFieldWeakening (void)
 
void runOffsetsCalculation (void)
 
void softwareUpdate1p6 (EST_Handle handle)
 Updates version 1p6 of library. More...
 
void runSetTrigger (void)
 
void setupClarke_I (CLARKE_Handle handle, const uint_least8_t numCurrentSensors)
 Setup the Clarke transform for either 2 or 3 sensors. More...
 
void setupClarke_V (CLARKE_Handle handle, const uint_least8_t numVoltageSensors)
 Setup the Clarke transform for either 2 or 3 sensors. More...
 
void updateGlobalVariables (EST_Handle handle)
 Update the global variables (gMotorVars). More...
 
void updateCPUusage (void)
 Updates CPU usage. More...
 

Variables

CLARKE_Handle clarkeHandle_I
 the handle for the current Clarke transform More...
 
CLARKE_Obj clarke_I
 the current Clarke transform object More...
 
CLARKE_Handle clarkeHandle_V
 the handle for the voltage Clarke transform More...
 
CLARKE_Obj clarke_V
 the voltage Clarke transform object More...
 
CPU_USAGE_Handle cpu_usageHandle
 
CPU_USAGE_Obj cpu_usage
 
EST_Handle estHandle
 the handle for the estimator More...
 
FW_Handle fwHandle
 
FW_Obj fw
 
PID_Obj pid [3]
 three handles for PID controllers 0 - Speed, 1 - Id, 2 - Iq More...
 
PID_Handle pidHandle [3]
 three objects for PID controllers 0 - Speed, 1 - Id, 2 - Iq More...
 
uint16_t pidCntSpeed
 count variable to decimate the execution of the speed PID controller More...
 
IPARK_Handle iparkHandle
 the handle for the inverse Park transform More...
 
IPARK_Obj ipark
 the inverse Park transform object More...
 
FILTER_FO_Handle filterHandle [6]
 the handles for the 3-current and 3-voltage filters for offset calculation More...
 
FILTER_FO_Obj filter [6]
 the 3-current and 3-voltage filters for offset calculation More...
 
SVGENCURRENT_Obj svgencurrent
 
SVGENCURRENT_Handle svgencurrentHandle
 
SVGEN_Handle svgenHandle
 the handle for the space vector generator More...
 
SVGEN_Obj svgen
 the space vector generator object More...
 
TRAJ_Handle trajHandle_Id
 the handle for the id reference trajectory More...
 
TRAJ_Obj traj_Id
 the id reference trajectory object More...
 
TRAJ_Handle trajHandle_spd
 the handle for the speed reference trajectory More...
 
TRAJ_Obj traj_spd
 the speed reference trajectory object More...
 
HAL_Handle halHandle
 the handle for the hardware abstraction layer (HAL) More...
 
HAL_PwmData_t gPwmData = {_IQ(0.0), _IQ(0.0), _IQ(0.0)}
 contains the three pwm values -1.0 - 0%, 1.0 - 100% More...
 
HAL_AdcData_t gAdcData
 contains three current values, three voltage values and one DC buss value More...
 
MATH_vec3 gOffsets_I_pu = {_IQ(0.0), _IQ(0.0), _IQ(0.0)}
 contains the offsets for the current feedback More...
 
MATH_vec3 gOffsets_V_pu = {_IQ(0.0), _IQ(0.0), _IQ(0.0)}
 contains the offsets for the voltage feedback More...
 
MATH_vec2 gIdq_ref_pu = {_IQ(0.0), _IQ(0.0)}
 contains the Id and Iq references More...
 
MATH_vec2 gVdq_out_pu = {_IQ(0.0), _IQ(0.0)}
 contains the output Vd and Vq from the current controllers More...
 
MATH_vec2 gIdq_pu = {_IQ(0.0), _IQ(0.0)}
 contains the Id and Iq measured values More...
 
USER_Params gUserParams
 The user parameters. More...
 
volatile MOTOR_Vars_t gMotorVars = MOTOR_Vars_INIT
 the global motor variables that are defined in main.h and used for display in the debugger's watch window More...
 
int16_t gCmpOffset = (int16_t)(1.0 * USER_SYSTEM_FREQ_MHz)
 
MATH_vec3 gIavg = {_IQ(0.0), _IQ(0.0), _IQ(0.0)}
 
uint16_t gIavg_shift = 1
 
_iq gFlux_pu_to_Wb_sf
 
_iq gFlux_pu_to_VpHz_sf
 
_iq gTorque_Ls_Id_Iq_pu_to_Nm_sf
 
_iq gTorque_Flux_Iq_pu_to_Nm_sf
 
_iq gSpeed_krpm_to_pu_sf = _IQ((float_t)USER_MOTOR_NUM_POLE_PAIRS * 1000.0 / (USER_IQ_FULL_SCALE_FREQ_Hz * 60.0))
 
_iq gSpeed_hz_to_krpm_sf = _IQ(60.0 / (float_t)USER_MOTOR_NUM_POLE_PAIRS / 1000.0)
 
_iq gIs_Max_squared_pu = _IQ((USER_MOTOR_MAX_CURRENT * USER_MOTOR_MAX_CURRENT) / (USER_IQ_FULL_SCALE_CURRENT_A * USER_IQ_FULL_SCALE_CURRENT_A))
 
float_t gCpuUsagePercentageMin = 0.0
 
float_t gCpuUsagePercentageAvg = 0.0
 
float_t gCpuUsagePercentageMax = 0.0
 
uint32_t gOffsetCalcCount = 0
 
volatile bool gFlag_enableRsOnLine = false
 
volatile bool gFlag_updateRs = false
 
volatile _iq gRsOnLineFreq_Hz = _IQ(0.2)
 
volatile _iq gRsOnLineId_mag_A = _IQ(0.5)
 
volatile _iq gRsOnLinePole_Hz = _IQ(0.2)
 

Detailed Description

Function Documentation

_iq angleDelayComp ( const _iq  fm_pu,
const _iq  angleUncomp_pu 
)

The angleDelayComp function compensates for the delay introduced.

from the time when the system inputs are sampled to when the PWM voltages are applied to the motor windings.

Definition at line 793 of file proj_lab11a.c.

References _IQ, _IQabs, _IQmpy, GLOBAL_Q, USER_IQ_FULL_SCALE_FREQ_Hz, USER_NUM_PWM_TICKS_PER_ISR_TICK, and USER_PWM_FREQ_kHz.

Referenced by mainISR().

void main ( void  )

Definition at line 185 of file proj_lab11a.c.

References _IQ, _IQmpy, CLARKE_init(), CPU_USAGE_init(), CPU_USAGE_setParams(), CTRL_init(), CTRL_setParams(), CTRL_setupEstIdleState(), CTRL_setUserMotorParams(), _USER_Params_::ctrlFreq_Hz, ctrlHandle, EST_getState(), EST_init(), EST_runPowerWarp(), EST_setAngle_pu(), EST_setEstParams(), EST_setFlag_enableForceAngle(), EST_setFlag_enableRsOnLine(), EST_setFlag_enableRsRecalc(), EST_setFlag_updateRs(), EST_setIdle(), EST_setRsOnLineAngleDelta_pu(), EST_setRsOnLineFilterParams(), EST_setRsOnLineId_mag_pu(), EST_setRsOnLineId_pu(), EST_setupEstIdleState(), EST_updateState(), _CTRL_Obj_::estHandle, estHandle, FILTER_FO_init(), FILTER_FO_setDenCoeffs(), FILTER_FO_setInitialConditions(), FILTER_FO_setNumCoeffs(), _MOTOR_Vars_t_::Flag_enableFieldWeakening, _MOTOR_Vars_t_::Flag_enableForceAngle, _MOTOR_Vars_t_::Flag_enableOffsetcalc, _MOTOR_Vars_t_::Flag_enablePowerWarp, _MOTOR_Vars_t_::Flag_enableRsRecalc, _MOTOR_Vars_t_::Flag_enableSys, _MOTOR_Vars_t_::Flag_Run_Identify, FW_clearCounter(), FW_DEC_DELTA, FW_INC_DELTA, FW_init(), FW_NUM_ISR_TICKS_PER_CTRL_TICK, FW_setDeltas(), FW_setFlag_enableFw(), FW_setMinMax(), FW_setNumIsrTicksPerFwTick(), FW_setOutput(), hal, HAL_disablePwm(), HAL_enableAdcInts(), HAL_enableDebugInt(), HAL_enableDrv(), HAL_enableGlobalInts(), HAL_enablePwm(), HAL_init(), HAL_initIntVectorTable(), HAL_readDrvData(), HAL_setParams(), HAL_setupDrvSpi(), HAL_setupFaults(), HAL_writeDrvData(), I_A_offset, I_B_offset, I_C_offset, IPARK_init(), memCopy(), _USER_Params_::offsetPole_rps, PID_init(), PID_setGains(), PID_setMinMax(), PID_setUi(), pidCntSpeed, setupClarke_I(), setupClarke_V(), softwareUpdate1p6(), _MOTOR_Vars_t_::SpeedRef_krpm, SVGEN_init(), SVGENCURRENT_init(), TRAJ_getIntValue(), TRAJ_init(), TRAJ_setIntValue(), TRAJ_setMaxDelta(), TRAJ_setMaxValue(), TRAJ_setMinValue(), TRAJ_setTargetValue(), updateCPUusage(), updateGlobalVariables(), USER_checkForErrors(), USER_computeFlux_pu_to_VpHz_sf(), USER_computeFlux_pu_to_Wb_sf(), USER_computeTorque_Flux_Iq_pu_to_Nm_sf(), USER_computeTorque_Ls_Id_Iq_pu_to_Nm_sf(), USER_EST_HANDLE_ADDRESS, USER_getErrorCode(), USER_IQ_FULL_SCALE_CURRENT_A, USER_IQ_FULL_SCALE_FREQ_Hz, USER_IQ_FULL_SCALE_VOLTAGE_V, USER_ISR_FREQ_Hz, USER_MAX_ACCEL_Hzps, USER_MAX_NEGATIVE_ID_REF_CURRENT_A, USER_MAX_VS_MAG_PU, USER_MOTOR_Ls_d, USER_MOTOR_Ls_q, USER_MOTOR_MAGNETIZING_CURRENT, USER_MOTOR_RES_EST_CURRENT, USER_MOTOR_Rs, USER_MOTOR_TYPE, USER_NUM_CURRENT_SENSORS, USER_NUM_VOLTAGE_SENSORS, USER_setParams(), USER_SYSTEM_FREQ_MHz, USER_VD_SF, _MOTOR_Vars_t_::UserErrorCode, V_A_offset, V_B_offset, V_C_offset, _MATH_vec3_::value, and _MATH_vec2_::value.

interrupt void mainISR ( void  )
void runCurrentIgnore ( void  )

Definition at line 819 of file proj_lab11a.c.

References HAL_readPwmCmpA(), and HAL_readPwmCmpAM().

Referenced by mainISR().

void runCurrentReconstruction ( void  )

Definition at line 835 of file proj_lab11a.c.

References _HAL_AdcData_t_::I, and _MATH_vec3_::value.

Referenced by mainISR().

void runFieldWeakening ( void  )
void runOffsetsCalculation ( void  )
void runSetTrigger ( void  )

Definition at line 957 of file proj_lab11a.c.

References gCmpOffset, and HAL_setTrigger().

Referenced by mainISR().

void setupClarke_I ( CLARKE_Handle  handle,
const uint_least8_t  numCurrentSensors 
)

Setup the Clarke transform for either 2 or 3 sensors.

Sets up the Clarke transform for current.

Sets the number of current sensors.

Parameters
[in]handleThe clarke (CLARKE) handle
[in]numCurrentSensorsThe number of current sensors

Definition at line 972 of file proj_lab11a.c.

References _IQ, CLARKE_setNumSensors(), CLARKE_setScaleFactors(), MATH_ONE_OVER_SQRT_THREE, and MATH_ONE_OVER_THREE.

Referenced by main().

void setupClarke_V ( CLARKE_Handle  handle,
const uint_least8_t  numVoltageSensors 
)

Setup the Clarke transform for either 2 or 3 sensors.

Sets up the Clarke transform for voltage.

Sets the number of voltage sensors.

Parameters
[in]handleThe clarke (CLARKE) handle
[in]numVoltageSensorsThe number of voltage sensors

Definition at line 1004 of file proj_lab11a.c.

References _IQ, CLARKE_setNumSensors(), CLARKE_setScaleFactors(), MATH_ONE_OVER_SQRT_THREE, and MATH_ONE_OVER_THREE.

Referenced by main().

void softwareUpdate1p6 ( EST_Handle  handle)

Updates version 1p6 of library.

Updates version 1p6 of library.

implementation of InstaSPIN (version 1.6 of ROM) since the inductance calculation is not done correctly in ROM, so this function fixes that ROM bug.

Definition at line 937 of file proj_lab11a.c.

References _IQ30, _IQ30toF(), EST_getLs_coarse_max_pu(), EST_setLs_d_pu(), EST_setLs_q_pu(), EST_setLs_qFmt(), USER_IQ_FULL_SCALE_CURRENT_A, USER_IQ_FULL_SCALE_VOLTAGE_V, USER_MOTOR_Ls_d, USER_MOTOR_Ls_q, and USER_VOLTAGE_FILTER_POLE_rps.

Referenced by main().

void updateCPUusage ( void  )
void updateGlobalVariables ( EST_Handle  handle)

Variable Documentation

CLARKE_Obj clarke_I

the current Clarke transform object

Definition at line 65 of file proj_lab11a.c.

CLARKE_Obj clarke_V

the voltage Clarke transform object

Definition at line 68 of file proj_lab11a.c.

CLARKE_Handle clarkeHandle_I

the handle for the current Clarke transform

Definition at line 64 of file proj_lab11a.c.

CLARKE_Handle clarkeHandle_V

the handle for the voltage Clarke transform

Definition at line 67 of file proj_lab11a.c.

CPU_USAGE_Obj cpu_usage

Definition at line 71 of file proj_lab11a.c.

CPU_USAGE_Handle cpu_usageHandle

Definition at line 70 of file proj_lab11a.c.

EST_Handle estHandle

the handle for the estimator

Definition at line 73 of file proj_lab11a.c.

Referenced by main(), and mainISR().

FILTER_FO_Obj filter[6]

the 3-current and 3-voltage filters for offset calculation

Definition at line 86 of file proj_lab11a.c.

FILTER_FO_Handle filterHandle[6]

the handles for the 3-current and 3-voltage filters for offset calculation

Definition at line 85 of file proj_lab11a.c.

FW_Obj fw

Definition at line 76 of file proj_lab11a.c.

FW_Handle fwHandle

Definition at line 75 of file proj_lab11a.c.

HAL_AdcData_t gAdcData

contains three current values, three voltage values and one DC buss value

Defines the ADC data.

Definition at line 107 of file proj_lab11a.c.

int16_t gCmpOffset = (int16_t)(1.0 * USER_SYSTEM_FREQ_MHz)

Definition at line 138 of file proj_lab11a.c.

Referenced by runSetTrigger().

float_t gCpuUsagePercentageAvg = 0.0

Definition at line 168 of file proj_lab11a.c.

float_t gCpuUsagePercentageMax = 0.0

Definition at line 169 of file proj_lab11a.c.

float_t gCpuUsagePercentageMin = 0.0

Definition at line 167 of file proj_lab11a.c.

volatile bool gFlag_enableRsOnLine = false

Definition at line 173 of file proj_lab11a.c.

volatile bool gFlag_updateRs = false

Definition at line 175 of file proj_lab11a.c.

_iq gFlux_pu_to_VpHz_sf

Definition at line 155 of file proj_lab11a.c.

_iq gFlux_pu_to_Wb_sf

Definition at line 153 of file proj_lab11a.c.

MATH_vec3 gIavg = {_IQ(0.0), _IQ(0.0), _IQ(0.0)}

Definition at line 140 of file proj_lab11a.c.

uint16_t gIavg_shift = 1

Definition at line 141 of file proj_lab11a.c.

MATH_vec2 gIdq_pu = {_IQ(0.0), _IQ(0.0)}

contains the Id and Iq measured values

Definition at line 117 of file proj_lab11a.c.

MATH_vec2 gIdq_ref_pu = {_IQ(0.0), _IQ(0.0)}

contains the Id and Iq references

Definition at line 113 of file proj_lab11a.c.

Definition at line 165 of file proj_lab11a.c.

volatile MOTOR_Vars_t gMotorVars = MOTOR_Vars_INIT

the global motor variables that are defined in main.h and used for display in the debugger's watch window

Definition at line 124 of file proj_lab11a.c.

uint32_t gOffsetCalcCount = 0

Definition at line 171 of file proj_lab11a.c.

MATH_vec3 gOffsets_I_pu = {_IQ(0.0), _IQ(0.0), _IQ(0.0)}

contains the offsets for the current feedback

Definition at line 109 of file proj_lab11a.c.

MATH_vec3 gOffsets_V_pu = {_IQ(0.0), _IQ(0.0), _IQ(0.0)}

contains the offsets for the voltage feedback

Definition at line 111 of file proj_lab11a.c.

HAL_PwmData_t gPwmData = {_IQ(0.0), _IQ(0.0), _IQ(0.0)}

contains the three pwm values -1.0 - 0%, 1.0 - 100%

Defines the PWM data.

Definition at line 105 of file proj_lab11a.c.

volatile _iq gRsOnLineFreq_Hz = _IQ(0.2)

Definition at line 177 of file proj_lab11a.c.

volatile _iq gRsOnLineId_mag_A = _IQ(0.5)

Definition at line 179 of file proj_lab11a.c.

volatile _iq gRsOnLinePole_Hz = _IQ(0.2)

Definition at line 181 of file proj_lab11a.c.

_iq gSpeed_hz_to_krpm_sf = _IQ(60.0 / (float_t)USER_MOTOR_NUM_POLE_PAIRS / 1000.0)

Definition at line 163 of file proj_lab11a.c.

_iq gSpeed_krpm_to_pu_sf = _IQ((float_t)USER_MOTOR_NUM_POLE_PAIRS * 1000.0 / (USER_IQ_FULL_SCALE_FREQ_Hz * 60.0))

Definition at line 161 of file proj_lab11a.c.

_iq gTorque_Flux_Iq_pu_to_Nm_sf

Definition at line 159 of file proj_lab11a.c.

_iq gTorque_Ls_Id_Iq_pu_to_Nm_sf

Definition at line 157 of file proj_lab11a.c.

USER_Params gUserParams

The user parameters.

Definition at line 122 of file proj_lab11a.c.

MATH_vec2 gVdq_out_pu = {_IQ(0.0), _IQ(0.0)}

contains the output Vd and Vq from the current controllers

Definition at line 115 of file proj_lab11a.c.

HAL_Handle halHandle

the handle for the hardware abstraction layer (HAL)

The hal handle.

Definition at line 103 of file proj_lab11a.c.

IPARK_Obj ipark

the inverse Park transform object

Definition at line 83 of file proj_lab11a.c.

IPARK_Handle iparkHandle

the handle for the inverse Park transform

Definition at line 82 of file proj_lab11a.c.

PID_Obj pid[3]

three handles for PID controllers 0 - Speed, 1 - Id, 2 - Iq

Definition at line 78 of file proj_lab11a.c.

uint16_t pidCntSpeed

count variable to decimate the execution of the speed PID controller

Definition at line 80 of file proj_lab11a.c.

Referenced by main(), and mainISR().

PID_Handle pidHandle[3]

three objects for PID controllers 0 - Speed, 1 - Id, 2 - Iq

Definition at line 79 of file proj_lab11a.c.

SVGEN_Obj svgen

the space vector generator object

Definition at line 92 of file proj_lab11a.c.

SVGENCURRENT_Obj svgencurrent

Definition at line 88 of file proj_lab11a.c.

SVGENCURRENT_Handle svgencurrentHandle

Definition at line 89 of file proj_lab11a.c.

SVGEN_Handle svgenHandle

the handle for the space vector generator

Definition at line 91 of file proj_lab11a.c.

TRAJ_Obj traj_Id

the id reference trajectory object

Definition at line 95 of file proj_lab11a.c.

TRAJ_Obj traj_spd

the speed reference trajectory object

Definition at line 98 of file proj_lab11a.c.

TRAJ_Handle trajHandle_Id

the handle for the id reference trajectory

Definition at line 94 of file proj_lab11a.c.

TRAJ_Handle trajHandle_spd

the handle for the speed reference trajectory

Definition at line 97 of file proj_lab11a.c.