10 #if !defined(__TMS320C28XX_CLA__)
30 #pragma CODE_SECTION(CTRL_computePhasor,"ramfuncs");
31 #pragma CODE_SECTION(CTRL_getCount_isr,"ramfuncs");
32 #pragma CODE_SECTION(CTRL_getNumIsrTicksPerCtrlTick,"ramfuncs");
33 #pragma CODE_SECTION(CTRL_incrCounter_isr,"ramfuncs");
34 #pragma CODE_SECTION(CTRL_isEnabled,"ramfuncs");
35 #pragma CODE_SECTION(CTRL_resetCounter_isr,"ramfuncs");
36 #pragma CODE_SECTION(CTRL_setup,"ramfuncs");
37 #pragma CODE_SECTION(CTRL_run,"ramfuncs");
40 #ifdef __TMS320C28XX_CLA__
41 #pragma CODE_SECTION(CTRL_getVersion,"Cla1Prog2");
42 #pragma CODE_SECTION(CTRL_getWaitTimes,"Cla1Prog2");
43 #pragma CODE_SECTION(CTRL_init,"Cla1Prog2");
44 #pragma CODE_SECTION(CTRL_reset,"Cla1Prog2");
45 #pragma CODE_SECTION(CTRL_setParams,"Cla1Prog2");
46 #pragma CODE_SECTION(CTRL_setVersion,"Cla1Prog2");
47 #pragma CODE_SECTION(CTRL_setWaitTimes,"Cla1Prog2");
48 #pragma CODE_SECTION(CTRL_updateState,"Cla1Prog2");
74 uint_least16_t stateCnt;
78 pWaitTimes[stateCnt] = obj->
waitTimes[stateCnt];
91 if((int16_t)numBytes < (int16_t)
sizeof(
CTRL_Obj))
250 Kp =
MATH_TWO_PI * BWc_rps / (BWdelta * Kctrl_Wb_p_kgm2);
251 Ki = BWc_rps * speedCtrlPeriod_sec / (BWdelta * BWdelta);
266 Kp = Ls_d_H * pUserParams->
BWc_rps;
267 RoverL_rps = Rs_d_Ohm / Ls_d_H;
268 Ki = RoverL_rps * currentCtrlPeriod_sec;
273 Kp = Ls_q_H * pUserParams->
BWc_rps;
274 RoverL_rps = Rs_q_Ohm / Ls_q_H;
297 const uint16_t majorReleaseNumber,
const uint16_t minorReleaseNumber)
313 uint_least16_t stateCnt;
317 obj->
waitTimes[stateCnt] = pWaitTimes[stateCnt];
328 bool stateChanged =
false;
341 if(counter_state >= waitTime)
376 return(stateChanged);
Defines the controller (CTRL) version number.
the controller error state
#define CTRL_MAJOR_RELEASE_NUMBER
Defines the major release number.
void CTRL_resetCounter_state(CTRL_Handle handle)
Resets the state counter.
void CTRL_setWaitTimes(CTRL_Handle handle, const int_least32_t *pWaitTimes)
Sets the wait times for the controller states.
float_t motor_Rs_d_Ohm
Defines the direct stator resistance, Ohm.
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.
PI_Handle piHandle_Id
the handle for the Id PI controller
static void CTRL_setVdq_offset_V(CTRL_Handle handle, const MATH_vec2 *pVdq_offset_V)
Sets the direct/quadrature offset voltage (Vdq_offset) vector values in the controller.
Contains the public interface to the math (MATH) module routines.
Defines a two element vector.
the number of controller states
#define MATH_TWO_PI
Defines 2*pi.
float_t BWc_rps
Defines the bandwidth of the current controllers, rad/sec.
uint16_t major
the major release number
float_t ctrlPeriod_sec
Defines the controller execution period, sec.
float_t maxCurrent_A
Defines the maximum current value, A.
void CTRL_getWaitTimes(CTRL_Handle handle, int_least32_t *pWaitTimes)
Gets the wait times from the controller.
static void PI_setUi(PI_Handle handle, const _iq Ui)
Sets the integrator start value in the PI controller.
static void CTRL_setBWdelta(CTRL_Handle handle, const float_t BWdelta)
Sets the bandwidth scale factor used to maximize phase margin.
the controller idle state
uint_least32_t ctrlWaitTime[CTRL_numStates]
Defines the wait times for each controller state, estimator ticks.
float_t motor_Rs_q_Ohm
Defines the quadrature stator resistance, Ohm.
static void CTRL_setSpeed_outMax_A(CTRL_Handle handle, const float_t speed_outMax_A)
Sets the maximum output value for the speed controller.
Defines the controller (CTRL) object.
Defines a structure for the user parameters.
PI_Obj pi_Id
the Id PI controller object
PI_Handle piHandle_Iq
the handle for the Iq PI controller
static void CTRL_setBWc_rps(CTRL_Handle handle, const float_t BWc_rps)
Sets the current controller bandwidth.
static void CTRL_setSpeed_ref_Hz(CTRL_Handle handle, const float_t speed_ref_Hz)
Sets the output speed reference value in the controller.
CTRL_TargetProc_e
Enumeration for the target processors.
static void CTRL_setIdq_ref_A(CTRL_Handle handle, const MATH_vec2 *pIdq_ref_A)
Sets the direct/quadrature current (Idq) reference vector values in the controller.
void CTRL_setFlag_enableSpeedCtrl(CTRL_Handle handle, const bool state)
Sets the enable speed control value in the estimator.
uint_least32_t CTRL_getWaitTime(CTRL_Handle handle, const CTRL_State_e ctrlState)
Gets the wait time for a given state.
void CTRL_reset(CTRL_Handle handle)
Resets the controller.
uint_least16_t numCtrlTicksPerCurrentTick
Defines the number of controller clock ticks per current controller clock tick.
void CTRL_resetCounter_current(CTRL_Handle handle)
Resets the current counter.
static void CTRL_setFlag_enableCurrentCtrl(CTRL_Handle handle, const bool state)
Sets the enable current controllers flag value in the controller.
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 CTRL_setSpeed_fb_Hz(CTRL_Handle handle, const float_t speed_fb_Hz)
Sets the feedback speed value in the controller.
void CTRL_setState(CTRL_Handle handle, const CTRL_State_e state)
Sets the controller state.
CTRL_Handle CTRL_init(void *pMemory, const size_t numBytes)
Initializes the controller.
float_t maxVsMag_V
Defines the maximum stator voltage magnitude, V.
static void CTRL_setFlag_resetInt_Id(CTRL_Handle handle, const bool state)
Sets the reset Id integrator flag value in the controller.
static void CTRL_setIdq_offset_A(CTRL_Handle handle, const MATH_vec2 *pIdq_offset_A)
Sets the direct/quadrature current (Idq) offset vector values in the controller.
void CTRL_setParams(CTRL_Handle handle, USER_Params *pUserParams)
Sets the controller parameters.
MOTOR_Type_e motor_type
Defines the motor type.
void CTRL_resetCounter_isr(CTRL_Handle handle)
Resets the isr counter.
uint16_t rsvd
reserved value
float_t BWdelta
Defines the bandwidth scaling to maximize phase margin.
PI_Handle PI_init(void *pMemory, const size_t numBytes)
Initializes the PI controller.
static void CTRL_setFlag_enable(CTRL_Handle handle, const bool state)
Sets the enable controller flag value in the controller.
float_t Vd_sf
Defines the Vd scale factor to prevent a Vd only component for the Vdq vector.
CTRL_State_e CTRL_getState(CTRL_Handle handle)
Gets the controller state.
static void CTRL_setSpeed_out_A(CTRL_Handle handle, const float_t speed_out_A)
Sets the maximum output value for the speed controller.
void CTRL_setCtrlPeriod_sec(CTRL_Handle handle, const float_t ctrlPeriod_sec)
Sets the controller execution period.
static void CTRL_setFlag_resetInt_Iq(CTRL_Handle handle, const bool state)
Sets the reset Iq integrator flag value in the controller.
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.
static void CTRL_setFlag_useZeroIq_ref(CTRL_Handle handle, const bool state)
Sets the use zero Iq reference flag value in the controller.
CTRL_State_e
Enumeration for the controller states.
the controller online state
float_t Kctrl_Wb_p_kgm2
Defines the speed controller constant, Wb/(kg*m^2)
void CTRL_setErrorCode(CTRL_Handle handle, const CTRL_ErrorCode_e errorCode)
Sets the error code in the controller.
CTRL_Version version
the controller version
uint_least16_t numCtrlTicksPerSpeedTick
Defines the number of controller clock ticks per speed controller clock tick.
static bool CTRL_getFlag_enable(CTRL_Handle handle)
Gets the enable controller flag value from the controller.
static bool CTRL_isNotIdle(CTRL_Handle handle)
Determines if the controller is not in the idle state.
#define CTRL_MINOR_RELEASE_NUMBER
Defines the major release number.
bool CTRL_updateState(CTRL_Handle handle)
Updates the controller state.
PI_Obj pi_spd
the speed PI controller object
static void CTRL_setIdq_A(CTRL_Handle handle, const MATH_vec2 *pIdq_A)
Sets the direct/quadrature current (Idq) vector values in the controller.
CTRL_TargetProc_e targetProc
the target processor
uint_least16_t numIsrTicksPerCtrlTick
Defines the number of Interrupt Service Routine (ISR) clock ticks per controller clock tick...
static void CTRL_setVdq_V(CTRL_Handle handle, const MATH_vec2 *pVdq_V)
Sets the direct/quadrature voltage (Vdq) vector values in the controller.
float_t motor_Rr_q_Ohm
Defines the quadrature rotor resistance, Ohm.
float_t motor_ratedFlux_Wb
Defines the rated flux of the motor, Wb.
static void CTRL_setSpeed_outMin_A(CTRL_Handle handle, const float_t speed_outMin_A)
Sets the minimum output value for the speed controller.
static void CTRL_setFlag_resetInt_spd(CTRL_Handle handle, const bool state)
Sets the reset speed integrator flag value in the controller.
uint_least32_t ctrlFreq_Hz
Defines the controller frequency, Hz.
float_t motor_Rr_d_Ohm
Defines the direct rotor resistance, Ohm.
static void PI_setMinMax(PI_Handle handle, const _iq outMin, const _iq outMax)
Sets the minimum and maximum output value allowed in the PI controller.
void CTRL_setCtrlFreq_Hz(CTRL_Handle handle, const uint_least32_t ctrlFreq_Hz)
Sets the controller frequency.
float_t dcBus_nominal_V
Defines the nominal DC bus voltage, V.
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.
static void CTRL_setCurrentCtrlPeriod_sec(CTRL_Handle handle, const float_t currentCtrlPeriod_sec)
Sets the current controller period value.
void CTRL_checkForErrors(CTRL_Handle handle)
Checks for any controller errors and, if found, sets the controller state to the error state...
void CTRL_setNumCtrlTicksPerSpeedTick(CTRL_Handle handle, const uint_least16_t numCtrlTicksPerSpeedTick)
Sets the number of controller clock ticks per speed controller clock tick.
void CTRL_getVersion(CTRL_Handle handle, CTRL_Version *pVersion)
Gets the controller version number.
uint16_t minor
the minor release number
static void CTRL_setMaxVsMag_V(CTRL_Handle handle, const float_t maxVsMag_V)
Sets the maximum stator voltage magnitude value.
void CTRL_setVersion(CTRL_Handle handle, const CTRL_TargetProc_e targetProc, const uint16_t majorReleaseNumber, const uint16_t minorReleaseNumber)
Sets the controller version.
uint_least32_t CTRL_getCount_state(CTRL_Handle handle)
Gets the state count.
PI_Handle piHandle_spd
the handle for the speed PI controller
Contains public interface to various functions related to the controller (CTRL) object.
static void CTRL_setSpeedCtrlPeriod_sec(CTRL_Handle handle, const float_t speedCtrlPeriod_sec)
Sets the speed controller period value.
PI_Obj pi_Iq
the Iq PI controller object
struct _CTRL_Obj_ * CTRL_Handle
Defines the CTRL handle.
float_t motor_Ls_d_H
Defines the direct stator inductance, H.
static void CTRL_setVd_sf(CTRL_Handle handle, const float_t Vd_sf)
Sets the direct voltage scale factor.
float_t motor_Ls_q_H
Defines the quadrature stator inductance, H.
void CTRL_setUi(CTRL_Handle handle, const CTRL_Type_e ctrlType, const _iq Ui)
Sets the integrator (Ui) value in the specified controller.
static void CTRL_setKctrl_Wb_p_kgm2(CTRL_Handle handle, const float_t Kctrl_Wb_p_kgm2)
Sets the speed controller constant.
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 float_t
Defines the portable data type for 32 bit, signed floating-point data.