62 #pragma CODE_SECTION(CTRL_run,"ramfuncs");
63 #pragma CODE_SECTION(CTRL_setup,"ramfuncs");
184 uint_least16_t stateCnt;
188 pWaitTimes[stateCnt] = obj->
waitTimes[stateCnt];
204 if(count_isr >= numIsrTicksPerCtrlTick)
481 _iq spd_ref_pu =
_IQmpy(spd_ref_krpm,krpm_to_pu_sf);
498 if(count_traj >= numCtrlTicksPerTrajTick)
516 _iq alpha_sf,beta_sf;
520 if(numCurrentSensors == 3)
525 else if(numCurrentSensors == 2)
547 _iq alpha_sf,beta_sf;
551 if(numVoltageSensors == 3)
572 const _iq speed_ref_pu,
573 const _iq speed_fb_pu,
574 const _iq speed_outMax_pu,
577 const bool flag_enableSpeedCtrl,
578 const bool flag_enableCurrentCtrl)
602 if(count_traj >= numCtrlTicksPerTrajTick)
631 uint_least16_t stateCnt;
635 obj->
waitTimes[stateCnt] = pWaitTimes[stateCnt];
646 bool stateChanged =
false;
659 if(counter_ctrlState >= waitTime)
673 if(flag_estStateChanged)
708 if(flag_enableUserMotorParams)
776 return(stateChanged);
static void CTRL_setSpeed_outMax_pu(CTRL_Handle handle, const _iq speed_outMax_pu)
Sets the maximum output value for the speed controller.
void CTRL_getGains(CTRL_Handle handle, const CTRL_Type_e ctrlType, _iq *pKp, _iq *pKi, _iq *pKd)
Gets the gain values for the specified controller.
static void CTRL_setIdq_offset_pu(CTRL_Handle handle, const MATH_vec2 *pIdq_offset_pu)
Sets the direct/quadrature current (Idq) offset vector values in the controller.
void CTRL_incrCounter_isr(CTRL_Handle handle)
Increments the isr counter.
static void TRAJ_setTargetValue(TRAJ_Handle handle, const _iq targetValue)
Sets the target value for the trajectory.
float_t motor_Ls_q
Defines the quadrature stator inductance, H.
void CTRL_setupEstOnLineState(CTRL_Handle handle)
Sets up the controller and trajectory generator for the estimator online state.
void CTRL_getIdq_ref_pu(CTRL_Handle handle, MATH_vec2 *pIdq_ref_pu)
Gets the direct/quadrature current reference vector values from the controller.
void CTRL_run(CTRL_Handle handle, HAL_Handle halHandle, const HAL_AdcData_t *pAdcData, HAL_PwmData_t *pPwmData)
Runs the controller.
MATH_vec2 Vab_in
the Vab input values
MATH_vec2 Idq_ref
the Idq reference values, pu
void CTRL_getIab_filt_pu(CTRL_Handle handle, MATH_vec2 *pIab_filt_pu)
Gets the alpha/beta filtered current vector values from the controller.
CLARKE_Handle clarkeHandle_I
the handle for the current Clarke transform
static void TRAJ_setMaxDelta(TRAJ_Handle handle, const _iq maxDelta)
Sets the maximum delta value for the trajectory.
void CTRL_resetCounter_state(CTRL_Handle handle)
Resets the state counter.
float_t iqFullScaleCurrent_A
Defines the full scale current for the IQ variables, A.
float_t IdRated
Defines the Id rated current value, A.
static void PID_setUi(PID_Handle handle, const _iq Ui)
Sets the integrator start value in the PID controller.
void CTRL_setupClarke_V(CTRL_Handle handle, uint_least8_t numVoltageSensors)
Sets the number of voltage sensors.
void CTRL_setEstParams(EST_Handle estHandle, USER_Params *pUserParams)
Sets the default estimator parameters.
void CTRL_setMotorParams(CTRL_Handle handle, const MOTOR_Type_e motorType, const uint_least16_t numPolePairs, const float_t ratedFlux, const float_t Ls_d, const float_t Ls_q, const float_t Rr, const float_t Rs)
Sets the parameters for the motor in the controller.
#define MATH_TWO_OVER_THREE
Defines 2/3.
static _iq TRAJ_getIntValue(TRAJ_Handle handle)
Gets the intermediate value for the trajectory.
void CTRL_setIab_in_pu(CTRL_Handle handle, const MATH_vec2 *pIab_in_pu)
Sets the alpha/beta current (Iab) input vector values in the controller.
_iq spd_ref
the speed reference, pu
void CTRL_getVdq_out_pu(CTRL_Handle handle, MATH_vec2 *pVdq_out_pu)
Gets the direct/quadrature voltage output vector values from the controller.
float_t motor_Rr
Defines the rotor resistance, ohm.
Defines a two element vector.
the number of controller states
bool EST_isOnLine(EST_Handle handle)
Determines if the estimator is ready for online control.
_iq CTRL_getKd(CTRL_Handle handle, const CTRL_Type_e ctrlType)
Gets the derivative gain (Kd) value from the specified controller.
void CTRL_incrCounter_current(CTRL_Handle handle)
Increments the current counter.
float_t ctrlPeriod_sec
Defines the controller execution period, sec.
TRAJ_Handle trajHandle_Id
the handle for the Id trajectory generator
void EST_setIdle(EST_Handle handle)
Sets the estimator to idle.
uint_least16_t CTRL_getNumCtrlTicksPerTrajTick(CTRL_Handle handle)
Gets the number of controller clock ticks per trajectory clock tick.
uint_least16_t CTRL_getNumIsrTicksPerCtrlTick(CTRL_Handle handle)
Gets the number of Interrupt Service Routine (ISR) clock ticks per controller clock tick...
TRAJ_Handle trajHandle_spd
the handle for the speed trajectory generator
void CTRL_setVab_in_pu(CTRL_Handle handle, const MATH_vec2 *pVab_in_pu)
Sets the alpha/beta voltage input vector values in the controller.
void CTRL_setSpd_max_pu(CTRL_Handle handle, const _iq maxSpd_pu)
Sets the maximum speed value in the controller.
MATH_vec2 Vab_out
the Vab output values
the controller idle state
PID_Handle pidHandle_Id
the handle for the Id PID controller
uint_least32_t ctrlWaitTime[CTRL_numStates]
Defines the wait times for each controller state, estimator ticks.
Defines the controller (CTRL) object.
void CTRL_setTrajPeriod_sec(CTRL_Handle handle, const _iq trajPeriod_sec)
Sets the trajectory execution period.
void CTRL_setMagCurrent_pu(CTRL_Handle handle, const _iq magCurrent_pu)
Sets the magnetizing current value in the controller.
Defines a structure for the user parameters.
uint_least8_t numCurrentSensors
Defines the number of current sensors.
uint_least16_t CTRL_getCount_traj(CTRL_Handle handle)
Gets the trajectory loop count.
EST_Handle estHandle
the handle for the parameter estimator
void CTRL_setKi(CTRL_Handle handle, const CTRL_Type_e ctrlType, const _iq Ki)
Sets the integral gain (Ki) value for the specified controller.
static void PID_setMinMax(PID_Handle handle, const _iq outMin, const _iq outMax)
Sets the minimum and maximum output value allowed in the PID controller.
void CTRL_setFlag_enableCtrl(CTRL_Handle handle, const bool state)
Sets the enable controller flag value in the estimator.
void CTRL_setFlag_enableSpeedCtrl(CTRL_Handle handle, const bool state)
Sets the enable speed control value in the estimator.
void CTRL_getIab_in_pu(CTRL_Handle handle, MATH_vec2 *pIab_in_pu)
Gets the alpha/beta current input vector values from the controller.
float_t maxCurrent
Defines the maximum current value, A.
uint_least32_t CTRL_getWaitTime(CTRL_Handle handle, const CTRL_State_e ctrlState)
Gets the wait time for a given state.
void CTRL_runTraj(CTRL_Handle handle)
Runs the trajectory.
void CTRL_setIdq_ref_pu(CTRL_Handle handle, const MATH_vec2 *pIdq_ref_pu)
Sets the direct/quadrature current (Idq) reference vector values in the controller.
uint_least16_t numCtrlTicksPerCurrentTick
Defines the number of controller clock ticks per current controller clock tick.
#define MATH_ONE_OVER_THREE
Defines 1/3.
void CTRL_resetCounter_current(CTRL_Handle handle)
Resets the current counter.
uint_least16_t CTRL_getCount_isr(CTRL_Handle handle)
Gets the isr count.
static void CTRL_setFlag_enableCurrentCtrl(CTRL_Handle handle, const bool state)
Sets the enable current controllers flag value in the controller.
TRAJ_Handle trajHandle_spdMax
the handle for the maximum speed trajectory generator
void CTRL_setGains(CTRL_Handle handle, const CTRL_Type_e ctrlType, const _iq Kp, const _iq Ki, const _iq Kd)
Sets the gain values for the specified controller.
static void CLARKE_setScaleFactors(CLARKE_Handle handle, const _iq alpha_sf, const _iq beta_sf)
Sets the scale factors.
void CTRL_setupTraj(CTRL_Handle handle)
Sets up the trajectory (TRAJ) object.
void CTRL_setState(CTRL_Handle handle, const CTRL_State_e state)
Sets the controller state.
static _iq TRAJ_getTargetValue(TRAJ_Handle handle)
Gets the target value for the trajectory.
static void TRAJ_setIntValue(TRAJ_Handle handle, const _iq intValue)
Sets the intermediate value for the trajectory.
MATH_vec3 Tabc
the PWM time-durations for each motor phase
static void PID_setGains(PID_Handle handle, const _iq Kp, const _iq Ki, const _iq Kd)
Sets the gains in the PID controller.
void CTRL_setParams(CTRL_Handle handle, USER_Params *pUserParams)
Sets the controller parameters.
MOTOR_Type_e motor_type
Defines the motor type.
static void CTRL_setAngle_pu(CTRL_Handle handle, const _iq angle_pu)
Sets the angle value, pu.
void CTRL_getIdq_in_pu(CTRL_Handle handle, MATH_vec2 *pIdq_in_pu)
Gets the direct/quadrature current input vector values from the controller.
void CTRL_setWaitTimes(CTRL_Handle handle, const uint_least32_t *pWaitTimes)
Sets the wait times for the controller states.
_iq CTRL_getSpd_max_pu(CTRL_Handle handle)
Gets the maximum speed value from the controller.
void CTRL_setVdq_out_pu(CTRL_Handle handle, const MATH_vec2 *pVdq_out_pu)
Sets the direct/quadrature voltage output vector values in the controller.
void CTRL_incrCounter_speed(CTRL_Handle handle)
Increments the speed counter.
void CTRL_resetCounter_isr(CTRL_Handle handle)
Resets the isr counter.
void CTRL_runOnLine_User(CTRL_Handle handle, const HAL_AdcData_t *pAdcData, HAL_PwmData_t *pPwmData)
Runs the online user controller.
void CTRL_setNumCtrlTicksPerTrajTick(CTRL_Handle handle, const uint_least16_t numCtrlTicksPerTrajTick)
Sets the number of controller clock ticks per trajectory clock tick.
MATH_vec2 Idq_in
the Idq input values
PID_Handle pidHandle_spd
the handle for the speed PID controller
void CTRL_setIdq_in_pu(CTRL_Handle handle, const MATH_vec2 *pIdq_in_pu)
Sets the direct/quadrature current (Idq) input vector values in the controller.
uint_least32_t trajFreq_Hz
Defines the trajectory frequency, Hz.
void CTRL_setSpd_out_pu(CTRL_Handle handle, const _iq spd_out_pu)
Sets the output speed value in the controller.
uint_least8_t numVoltageSensors
Defines the number of voltage sensors.
bool CTRL_getFlag_enableUserMotorParams(CTRL_Handle handle)
Gets the enable user motor parameters flag value from the controller.
void CTRL_incrCounter_state(CTRL_Handle handle)
Increments the state counter.
void CTRL_setupEstIdleState(CTRL_Handle handle)
Sets up the controller and trajectory generator for the estimator idle state.
CTRL_State_e CTRL_getState(CTRL_Handle handle)
Gets the controller state.
void CTRL_setUserMotorParams(CTRL_Handle handle)
Sets the controller and estimator with motor parameters from the user.h file.
void CTRL_setLhf(CTRL_Handle handle, const float_t Lhf)
Sets the high frequency inductance (Lhf) value in the controller.
Contains the public interface to the math (MATH) module routines.
void CTRL_setCtrlPeriod_sec(CTRL_Handle handle, const float_t ctrlPeriod_sec)
Sets the controller execution period.
static void SVGEN_setMaxModulation(SVGEN_Handle handle, const _iq maxModulation)
Sets the maximum modulation in the space vector generator module.
EST_State_e EST_getState(EST_Handle handle)
Gets the state of the estimator.
_iq CTRL_getMaximumSpeed_pu(CTRL_Handle handle)
Gets the maximum speed value from the controller.
MATH_vec2 Iab_filt
the Iab filtered values
static void CTRL_setVdq_offset_pu(CTRL_Handle handle, const MATH_vec2 *pVdq_offset_pu)
Sets the direct/quadrature voltage (Vdq) offset vector values in the controller.
MATH_vec2 Vdq_out
the Vdq output values
uint_least32_t waitTimes[CTRL_numStates]
an array of wait times for each state, estimator clock counts
void CTRL_setNumCtrlTicksPerCurrentTick(CTRL_Handle handle, const uint_least16_t numCtrlTicksPerCurrentTick)
Sets the number of controller clock ticks per current controller clock tick.
_iq CTRL_getKp(CTRL_Handle handle, const CTRL_Type_e ctrlType)
Gets the proportional gain (Kp) value from the specified controller.
void CTRL_setup(CTRL_Handle handle)
Sets up the controller (CTRL) object and all of the subordinate objects.
void CTRL_getVab_out_pu(CTRL_Handle handle, MATH_vec2 *pVab_out_pu)
Gets the alpha/beta voltage output vector values from the controller.
void CTRL_setSpd_ref_pu(CTRL_Handle handle, const _iq spd_ref_pu)
Sets the output speed reference value in the controller.
CTRL_State_e
Enumeration for the controller states.
the controller online state
CLARKE_Handle clarkeHandle_V
the handle for the voltage Clarke transform
void CTRL_setTrajFreq_Hz(CTRL_Handle handle, const uint_least32_t trajFreq_Hz)
Sets the trajectory execution frequency.
static void CTRL_setSpeed_fb_pu(CTRL_Handle handle, const _iq speed_fb_pu)
Sets the feedback speed value in the controller.
void CTRL_runOffLine(CTRL_Handle handle, HAL_Handle halHandle, const HAL_AdcData_t *pAdcData, HAL_PwmData_t *pPwmData)
Runs the offline controller.
void CTRL_setErrorCode(CTRL_Handle handle, const CTRL_ErrorCode_e errorCode)
Sets the error code in the controller.
static void CLARKE_setNumSensors(CLARKE_Handle handle, const uint_least8_t numSensors)
Sets the number of sensors.
void CTRL_setVab_out_pu(CTRL_Handle handle, const MATH_vec2 *pVab_out_pu)
Sets the alpha/beta current output vector values in the controller.
void CTRL_setMaxVsMag_pu(CTRL_Handle handle, const _iq maxVsMag)
Sets the maximum voltage vector in the controller.
void CTRL_resetCounter_traj(CTRL_Handle handle)
Resets the trajectory counter.
uint_least16_t numCtrlTicksPerTrajTick
Defines the number of controller clock ticks per trajectory clock tick.
PID_Handle pidHandle_Iq
the handle for the Iq PID controller
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)
Sets up the speed and current controllers.
uint_least16_t numCtrlTicksPerSpeedTick
Defines the number of controller clock ticks per speed controller clock tick.
_iq CTRL_getIdRated_pu(CTRL_Handle handle)
Gets the Id rated current value from the controller.
void CTRL_setFlag_enablePowerWarp(CTRL_Handle handle, const bool state)
Sets the PowerWarp enable flag value in the estimator.
bool CTRL_updateState(CTRL_Handle handle)
Updates the controller state.
CTRL_Type_e
Enumeration for the controller (CTRL) types.
_iq CTRL_getKi(CTRL_Handle handle, const CTRL_Type_e ctrlType)
Gets the integral gain (Ki) value from the specified controller.
void CTRL_getWaitTimes(CTRL_Handle handle, uint_least32_t *pWaitTimes)
Gets the wait times from the estimator.
static void TRAJ_setMaxValue(TRAJ_Handle handle, const _iq maxValue)
Sets the maximum value for the trajectory.
bool CTRL_getFlag_enableCtrl(CTRL_Handle handle)
Gets the enable controller flag value from the estimator.
bool EST_isMotorIdentified(EST_Handle handle)
Determines if the motor has been identified.
void CTRL_setRhf(CTRL_Handle handle, const float_t Rhf)
Sets the high frequency resistance (Rhf) value in the controller.
void CTRL_setFlag_enableOffset(CTRL_Handle handle, const bool state)
Sets the enable offset flag value in the estimator.
float_t motor_Rs
Defines the stator resistance, ohm.
bool EST_isLockRotor(EST_Handle handle)
Determines if the estimator is waiting for the rotor to be locked.
uint_least16_t numIsrTicksPerCtrlTick
Defines the number of Interrupt Service Routine (ISR) clock ticks per controller clock tick...
void CTRL_setFlag_enableDcBusComp(CTRL_Handle handle, const bool state)
Sets the enable DC bus compensation flag value in the estimator.
void EST_setRs_pu(EST_Handle handle, const _iq Rs_pu)
Sets the stator resistance value used in the estimator in per unit (pu), IQ30.
void CTRL_setFlag_enableUserMotorParams(CTRL_Handle handle, const bool state)
Sets the enable user motor parameters flag value in the estimator.
void CTRL_setKd(CTRL_Handle handle, const CTRL_Type_e ctrlType, const _iq Kd)
Sets the derivative gain (Kd) value for the specified controller.
_iq CTRL_getMagCurrent_pu(CTRL_Handle handle)
Gets the magnetizing current value from the controller.
uint_least32_t ctrlFreq_Hz
Defines the controller frequency, Hz.
static void CTRL_setSpeed_ref_pu(CTRL_Handle handle, const _iq speed_ref_pu)
Sets the output speed reference value in the controller.
void CTRL_setIdRated_pu(CTRL_Handle handle, const _iq IdRated_pu)
Sets the Id rated current value in the controller.
_iq EST_get_krpm_to_pu_sf(EST_Handle handle)
Gets the krpm to pu scale factor in per unit (pu), IQ24.
bool EST_isIdle(EST_Handle handle)
Determines if the estimator is idle.
void CTRL_setCtrlFreq_Hz(CTRL_Handle handle, const uint_least32_t ctrlFreq_Hz)
Sets the controller frequency.
uint_least16_t motor_numPolePairs
Defines the number of pole pairs for the motor.
void CTRL_resetCounter_speed(CTRL_Handle handle)
Resets the speed counter.
#define MATH_ONE_OVER_SQRT_THREE
Defines 1/sqrt(3)
void CTRL_checkForErrors(CTRL_Handle handle)
Checks for any controller errors and, if found, sets the controller state to the error state...
void CTRL_getVab_in_pu(CTRL_Handle handle, MATH_vec2 *pVab_in_pu)
Gets the alpha/beta voltage input vector values from the controller.
void CTRL_setMaximumSpeed_pu(CTRL_Handle handle, const _iq maxSpeed_pu)
Sets the maximum speed value in the controller.
void EST_setIdle_all(EST_Handle handle)
Sets the estimator and all of the subordinate estimators to idle.
void CTRL_setNumCtrlTicksPerSpeedTick(CTRL_Handle handle, const uint_least16_t numCtrlTicksPerSpeedTick)
Sets the number of controller clock ticks per speed controller clock tick.
MATH_vec2 Iab_in
the Iab input values
uint_least32_t CTRL_getCount_state(CTRL_Handle handle)
Gets the state count.
bool EST_updateState(EST_Handle handle, const _iq Id_target_pu)
Updates the estimator state.
Contains the public interface to the data logging (DLOG) module routines.
void CTRL_setRoverL(CTRL_Handle handle, const float_t RoverL)
Sets the R/L value in the controller.
the controller offline state
void CTRL_incrCounter_traj(CTRL_Handle handle)
Increments the trajectory counter.
void CTRL_setNumIsrTicksPerCtrlTick(CTRL_Handle handle, const uint_least16_t numIsrTicksPerCtrlTick)
Sets the number of Interrupt Service Routine (ISR) clock ticks per controller clock tick...
float_t iqFullScaleFreq_Hz
Defines the full scale frequency for IQ variable, Hz.
void CTRL_setSpd_ref_krpm(CTRL_Handle handle, const _iq spd_ref_krpm)
Sets the output speed reference value in the controller.
void CTRL_setupClarke_I(CTRL_Handle handle, uint_least8_t numCurrentSensors)
Sets the number of current sensors.
void CTRL_setKp(CTRL_Handle handle, const CTRL_Type_e ctrlType, const _iq Kp)
Sets the proportional gain (Kp) value for the specified controller.
void CTRL_setupCtrl(CTRL_Handle handle)
Sets up the controllers.
float_t motor_Ls_d
Defines the direct stator inductance, H.
Defines the hardware abstraction layer (HAL) data.
float_t motor_ratedFlux
Defines the rated flux of the motor, V/Hz.
void CTRL_runOnLine(CTRL_Handle handle, const HAL_AdcData_t *pAdcData, HAL_PwmData_t *pPwmData)
Runs the online controller.
static void TRAJ_setMinValue(TRAJ_Handle handle, const _iq minValue)
Sets the minimum value for the trajectory.
SVGEN_Handle svgenHandle
the handle for the space vector generator
float_t maxVsMag_pu
Defines the maximum voltage magnitude, pu.
bool CTRL_getFlag_enableOffset(CTRL_Handle handle)
Gets the enable offset flag value from the controller.