instaspin_foc
Macros | Functions | Variables
proj_enc_fast.c File Reference
#include <math.h>
#include "sw/modules/cal/src/float/cal.h"
#include "sw/modules/ipark/src/float/ipark.h"
#include "sw/modules/park/src/float/park.h"
#include "sw/modules/queue/src/queue.h"
#include "sw/modules/svgen/src/float/svgen.h"
#include "sw/drivers/qep/src/32b/f28x/f2806x/qep.h"
#include "dmc_enc/sw/modules/enc/src/float/enc.h"
#include "dmc_enc/sw/modules/enc_cal/src/float/enc_cal.h"
#include "sw/modules/angle/src/float/angle.h"
#include "main.h"

Go to the source code of this file.

Macros

#define GRAPH_SIZE   100
 

Functions

void main (void)
 
void calcGains (CTRL_Handle handle, EST_Handle estHandle)
 Calculates controller gains. More...
 
interrupt void mainISR (void)
 The main interrupt service (ISR) routine. More...
 
void setupClarke_I (CLARKE_Handle handle, const uint_least8_t numCurrentSensors)
 Sets the number of current sensors. More...
 
void setupClarke_V (CLARKE_Handle handle, const uint_least8_t numVoltageSensors)
 Sets the number of voltage sensors. More...
 
void updateGlobalVariables_motor (CTRL_Handle ctrlHandle, EST_Handle estHandle)
 Updates the global motor variables. More...
 
void updateCPUusage (CTRL_Handle handle)
 Updates CPU usage. More...
 

Variables

int_least32_t gCounter_enableSys = 0
 A counter that is incremented while waiting for the enable system flag to be set. More...
 
int_least32_t gCounter_isr = 0
 A counter that is incremented by each call to the mainISR() function. More...
 
int_least32_t gCounter_main = 0
 A counter that is incremented by each iteration of the main() function. More...
 
CAL_State_e gCalState = CAL_State_Idle
 
CTRL_State_e gCtrlState = CTRL_State_Idle
 Global variable for the controller state. More...
 
ENC_CAL_State_e gEncCalState = ENC_CAL_State_Idle
 
EST_State_e gEstState = EST_State_Idle
 Global variable for the estimator state. More...
 
EST_Traj_State_e gTrajState = EST_Traj_State_Idle
 
volatile bool gFlag_bypassLockRotor = false
 
volatile bool gFlag_enableSys = false
 Global flag to enable/disable the system. More...
 
volatile bool gFlag_runCal = false
 
volatile bool gFlag_runIdentAndOnLine = false
 
volatile bool gFlag_enableForceAngle = true
 
volatile bool gFlag_enablePowerWarp = false
 
volatile bool gFlag_enableQueue = false
 
volatile bool gFlag_enableRsOnLine = false
 
volatile bool gFlag_enableRsRecalc = true
 
volatile bool gFlag_updateRs = false
 
volatile bool gFlag_runEncCal = true
 
volatile bool gFlag_runInSpeedMode = true
 
uint_least16_t gBufferIndex_est = 0
 A counter that to denote the buffer index for the estimation. More...
 
uint_least16_t gBufferIndex_setup = 0
 A counter that to denote the buffer index for the setup. More...
 
float_t gFlux_Wb = 0.0
 Global variable for the rotor flux estimate, Wb. More...
 
float_t gId_trajTarget_A = 0.0
 
float_t gIdRated_A = 0.0
 Global variable for the rated Id current current, A. More...
 
float_t gLs_d_H = 0.0
 Global variable for the stator inductance in the direct coordinate direction, Henry. More...
 
float_t gLs_q_H = 0.0
 Global variable for the stator inductance in the quadrature coordinate direction, Henry. More...
 
float_t gLmag_H = 0.0
 Global variable for the magnetizing inductance, Henry. More...
 
float_t gRoverL_rps = 0.0
 Global variable for the R/L value used for the current controller. More...
 
float_t gRsOnLine_Ohm = 0.0
 
float_t gRs_a_Ohm = 0.0
 Global variable for the stator resistance in the alpha coordinate direction, Ohm. More...
 
float_t gRs_b_Ohm = 0.0
 Global variable for the stator resistance in the beta coordinate direction, Ohm. More...
 
float_t gRs_d_Ohm = 0.0
 Global variable for the stator resistance in the direct coordinate direction, Ohm. More...
 
float_t gRs_q_Ohm = 0.0
 Global variable for the stator resistance in the quadrature coordinate direction, Ohm. More...
 
float_t gRr_d_Ohm = 0.0
 Global variable for the rotor resistance in the direct coordinate direction, Ohm. More...
 
float_t gRr_q_Ohm = 0.0
 
float_t gSpeed_Hz = 0.0
 
float_t gSpeed_ref_Hz = 10.0
 
float_t gSpeed_ref_traj = 20.0
 
float_t gSpeedOutMax_A = USER_MOTOR_MAX_CURRENT_A
 
float_t gId_A = 0.0
 
float_t gIq_A = 0.0
 
volatile float_t gSpeed_Kp = 0.1
 
volatile float_t gSpeed_Ki = 0.01
 
HAL_AdcData_t gAdcData
 Defines the ADC data. More...
 
HAL_DacData_t gDacData
 Defines the DAC data. More...
 
HAL_PwmData_t gPwmData
 Defines the PWM data. More...
 
EST_InputData_t gEstInputData [NUM_EST_DATA_BUFFERS]
 
EST_OutputData_t gEstOutputData [NUM_EST_DATA_BUFFERS]
 
volatile float_t gRsOnLineFreq_Hz = 0.2
 
volatile float_t gRsOnLineId_mag_A = 0.5
 
volatile float_t gRsOnLinePole_Hz = 0.2
 
float_t gMaxCurrentSlope = 0.0
 
float_t gTorque_Nm = 0.0
 Global variable for the estimated torque, N*m. More...
 
CTRL_Version gVersion
 Global variable for the controller version. More...
 
USER_Params gUserParams
 The user parameters. More...
 
ANGLE_Handle angleHandle
 the handle for the angle generator More...
 
ANGLE_Obj angle
 the angle object More...
 
ENC_Handle encHandle
 the handle for the encoder More...
 
ENC_Obj enc
 the encoder object More...
 
ENC_CAL_Handle enc_calHandle
 the handle for the encoder calibration More...
 
ENC_CAL_Obj enc_cal
 the encoder calibration object More...
 
CAL_Handle calHandle
 the handle for the calibrator More...
 
CAL_Obj cal
 the calibrator object More...
 
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...
 
CTRL_Handle ctrlHandle
 the handle for the controller More...
 
CTRL_Obj ctrl [CTRL_NUM_CONTROLLERS]
 the controller object More...
 
HAL_Handle halHandle
 the handle for the hardware abstraction layer More...
 
HAL_Obj hal
 the hardware abstraction layer object More...
 
EST_Handle estHandle
 the handle for the estimator More...
 
IPARK_Handle iparkHandle
 the handle for the inverse Park transform More...
 
IPARK_Obj ipark
 the inverse Park transform object More...
 
PARK_Handle parkHandle
 the handle for the Park object More...
 
PARK_Obj park
 the Park transform object More...
 
QUEUE_Handle queueHandle
 the handle for the queue More...
 
QUEUE_Obj queue
 the queue object More...
 
SVGEN_Handle svgenHandle
 the handle for the space vector generator More...
 
SVGEN_Obj svgen
 the space vector generator object More...
 
volatile bool gflag_configCtrl_once = true
 
CPU_USAGE_Handle cpu_usageHandle
 
CPU_USAGE_Obj cpu_usage
 
float_t gCpuUsagePercentageMin = 0.0
 
float_t gCpuUsagePercentageAvg = 0.0
 
float_t gCpuUsagePercentageMax = 0.0
 
float_t Graph_Data1 [GRAPH_SIZE]
 
float_t Graph_Data2 [GRAPH_SIZE]
 
float_t Graph_Data3 [GRAPH_SIZE]
 
volatile bool Graph_Flag_Enable_update = false
 
uint16_t Graph_Counter = 0
 
uint16_t Graph_Tick_Counter = 0
 
volatile uint16_t Graph_Tick_Counter_Value = 10
 
float_t gAngle_enc = 0.0
 
float_t gAngleError = 0.0
 

Macro Definition Documentation

#define GRAPH_SIZE   100

Definition at line 207 of file proj_enc_fast.c.

Referenced by main(), and mainISR().

Function Documentation

void main ( void  )

Definition at line 221 of file proj_enc_fast.c.

References ANGLE_init(), ANGLE_setParams(), _USER_Params_::angleDelayed_sf_sec, CAL_disable(), CAL_enable(), CAL_getOffsetHandleAddr_I(), CAL_getOffsetHandleAddr_V(), CAL_getState(), CAL_init(), CAL_isError(), CAL_setFlag_enableAdcOffset(), CAL_setParams(), CAL_updateState(), calcGains(), CLARKE_init(), CPU_USAGE_init(), CPU_USAGE_setParams(), CTRL_disable(), CTRL_enable(), CTRL_getCurrentCtrlPeriod_sec(), CTRL_getState(), CTRL_getVersion(), CTRL_init(), CTRL_isError(), CTRL_setGains(), CTRL_setParams(), _USER_Params_::ctrlPeriod_sec, enc_cal, enc_calHandle, ENC_init(), EST_configureCtrl(), EST_configureTraj(), EST_disable(), EST_disableTraj(), EST_enable(), EST_enableTraj(), EST_getIdRated_A(), EST_getTrajState(), EST_initEst(), EST_isError(), EST_isIdle(), EST_isLockRotor(), EST_isMotorIdentified(), EST_isOnLine(), EST_isTrajError(), EST_setFlag_bypassLockRotor(), EST_setFlag_enableForceAngle(), EST_setFlag_enablePowerWarp(), EST_setFlag_enableRsOnLine(), EST_setFlag_enableRsRecalc(), EST_setFlag_updateRs(), EST_setParams(), EST_setRsOnLine_beta_rad(), EST_setRsOnLineAngleDelta_rad(), EST_setRsOnLineId_mag_A(), EST_updateState(), EST_updateTrajState(), estHandle, gCounter_enableSys, gCounter_main, gFlag_bypassLockRotor, gFlag_enableForceAngle, gFlag_enablePowerWarp, gFlag_enableRsOnLine, gFlag_enableRsRecalc, gFlag_enableSys, gFlag_runCal, gFlag_runEncCal, gFlag_runIdentAndOnLine, gFlag_updateRs, gId_trajTarget_A, Graph_Data1, Graph_Data2, Graph_Data3, GRAPH_SIZE, gRsOnLineFreq_Hz, gRsOnLineId_mag_A, gRsOnLinePole_Hz, gSpeed_Ki, gSpeed_Kp, gSpeed_ref_traj, 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_updateAdcBias(), HAL_writeDrvData(), IPARK_init(), MATH_TWO_PI, _USER_Params_::motor_type, _USER_Params_::numCurrentSensors, _USER_Params_::numVoltageSensors, PARK_init(), QUEUE_executeEvent(), QUEUE_init(), QUEUE_isEvent(), setupClarke_I(), setupClarke_V(), SVGEN_init(), _USER_Params_::trajFreq_Hz, updateCPUusage(), updateGlobalVariables_motor(), USER_EST_FREQ_Hz, USER_ISR_FREQ_Hz, USER_setParams(), USER_SYSTEM_FREQ_MHz, and USER_TRAJ_FREQ_Hz.

Variable Documentation

ANGLE_Obj angle

the angle object

Definition at line 154 of file proj_enc_fast.c.

ANGLE_Handle angleHandle

the handle for the angle generator

Definition at line 153 of file proj_enc_fast.c.

CAL_Obj cal

the calibrator object

Definition at line 163 of file proj_enc_fast.c.

CAL_Handle calHandle

the handle for the calibrator

Definition at line 162 of file proj_enc_fast.c.

CLARKE_Obj clarke_I

the current Clarke transform object

Definition at line 166 of file proj_enc_fast.c.

CLARKE_Obj clarke_V

the voltage Clarke transform object

Definition at line 169 of file proj_enc_fast.c.

CLARKE_Handle clarkeHandle_I

the handle for the current Clarke transform

Definition at line 165 of file proj_enc_fast.c.

CLARKE_Handle clarkeHandle_V

the handle for the voltage Clarke transform

Definition at line 168 of file proj_enc_fast.c.

CPU_USAGE_Obj cpu_usage

Definition at line 201 of file proj_enc_fast.c.

CPU_USAGE_Handle cpu_usageHandle

Definition at line 200 of file proj_enc_fast.c.

ENC_Obj enc

the encoder object

Definition at line 157 of file proj_enc_fast.c.

ENC_CAL_Obj enc_cal

the encoder calibration object

Definition at line 160 of file proj_enc_fast.c.

Referenced by main().

ENC_CAL_Handle enc_calHandle

the handle for the encoder calibration

Definition at line 159 of file proj_enc_fast.c.

Referenced by main(), and mainISR().

ENC_Handle encHandle

the handle for the encoder

Definition at line 156 of file proj_enc_fast.c.

EST_Handle estHandle

the handle for the estimator

Definition at line 177 of file proj_enc_fast.c.

Referenced by main(), and mainISR().

float_t gAngle_enc = 0.0

Definition at line 215 of file proj_enc_fast.c.

Referenced by mainISR().

float_t gAngleError = 0.0

Definition at line 216 of file proj_enc_fast.c.

Referenced by mainISR().

CAL_State_e gCalState = CAL_State_Idle

Definition at line 47 of file proj_enc_fast.c.

Referenced by updateGlobalVariables_motor().

float_t gCpuUsagePercentageAvg = 0.0

Definition at line 203 of file proj_enc_fast.c.

Referenced by updateCPUusage().

float_t gCpuUsagePercentageMax = 0.0

Definition at line 204 of file proj_enc_fast.c.

Referenced by updateCPUusage().

float_t gCpuUsagePercentageMin = 0.0

Definition at line 202 of file proj_enc_fast.c.

Referenced by updateCPUusage().

ENC_CAL_State_e gEncCalState = ENC_CAL_State_Idle

Definition at line 51 of file proj_enc_fast.c.

Definition at line 135 of file proj_enc_fast.c.

Definition at line 137 of file proj_enc_fast.c.

volatile bool gFlag_bypassLockRotor = false

Definition at line 57 of file proj_enc_fast.c.

Referenced by main().

volatile bool gflag_configCtrl_once = true

Definition at line 192 of file proj_enc_fast.c.

volatile bool gFlag_enableForceAngle = true

Definition at line 65 of file proj_enc_fast.c.

Referenced by main().

volatile bool gFlag_enablePowerWarp = false

Definition at line 67 of file proj_enc_fast.c.

Referenced by main().

volatile bool gFlag_enableQueue = false

Definition at line 69 of file proj_enc_fast.c.

Referenced by mainISR().

volatile bool gFlag_enableRsOnLine = false

Definition at line 71 of file proj_enc_fast.c.

Referenced by main().

volatile bool gFlag_enableRsRecalc = true

Definition at line 73 of file proj_enc_fast.c.

Referenced by main().

volatile bool gFlag_runCal = false

Definition at line 61 of file proj_enc_fast.c.

Referenced by main().

volatile bool gFlag_runEncCal = true

Definition at line 77 of file proj_enc_fast.c.

Referenced by main().

volatile bool gFlag_runIdentAndOnLine = false

Definition at line 63 of file proj_enc_fast.c.

Referenced by main().

volatile bool gFlag_runInSpeedMode = true

Definition at line 79 of file proj_enc_fast.c.

Referenced by mainISR().

volatile bool gFlag_updateRs = false

Definition at line 75 of file proj_enc_fast.c.

Referenced by main().

float_t gId_A = 0.0

Definition at line 121 of file proj_enc_fast.c.

Referenced by mainISR().

float_t gId_trajTarget_A = 0.0

Definition at line 87 of file proj_enc_fast.c.

Referenced by main(), and mainISR().

float_t gIq_A = 0.0

Definition at line 123 of file proj_enc_fast.c.

Referenced by mainISR().

float_t gMaxCurrentSlope = 0.0

Definition at line 145 of file proj_enc_fast.c.

uint16_t Graph_Counter = 0

Definition at line 212 of file proj_enc_fast.c.

Referenced by mainISR().

float_t Graph_Data1[GRAPH_SIZE]

Definition at line 208 of file proj_enc_fast.c.

Referenced by main(), and mainISR().

float_t Graph_Data2[GRAPH_SIZE]

Definition at line 209 of file proj_enc_fast.c.

Referenced by main(), and mainISR().

float_t Graph_Data3[GRAPH_SIZE]

Definition at line 210 of file proj_enc_fast.c.

Referenced by main(), and mainISR().

volatile bool Graph_Flag_Enable_update = false

Definition at line 211 of file proj_enc_fast.c.

Referenced by mainISR().

uint16_t Graph_Tick_Counter = 0

Definition at line 213 of file proj_enc_fast.c.

Referenced by mainISR().

volatile uint16_t Graph_Tick_Counter_Value = 10

Definition at line 214 of file proj_enc_fast.c.

Referenced by mainISR().

float_t gRr_q_Ohm = 0.0

Definition at line 111 of file proj_enc_fast.c.

Referenced by updateGlobalVariables_motor().

float_t gRsOnLine_Ohm = 0.0

Definition at line 99 of file proj_enc_fast.c.

Referenced by updateGlobalVariables_motor().

volatile float_t gRsOnLineFreq_Hz = 0.2

Definition at line 139 of file proj_enc_fast.c.

Referenced by main().

volatile float_t gRsOnLineId_mag_A = 0.5

Definition at line 141 of file proj_enc_fast.c.

Referenced by main().

volatile float_t gRsOnLinePole_Hz = 0.2

Definition at line 143 of file proj_enc_fast.c.

Referenced by main().

float_t gSpeed_Hz = 0.0

Definition at line 113 of file proj_enc_fast.c.

Referenced by updateGlobalVariables_motor().

volatile float_t gSpeed_Ki = 0.01

Definition at line 127 of file proj_enc_fast.c.

Referenced by main().

volatile float_t gSpeed_Kp = 0.1

Definition at line 125 of file proj_enc_fast.c.

Referenced by main().

float_t gSpeed_ref_Hz = 10.0

Definition at line 115 of file proj_enc_fast.c.

Referenced by mainISR().

float_t gSpeed_ref_traj = 20.0

Definition at line 117 of file proj_enc_fast.c.

Referenced by main().

float_t gSpeedOutMax_A = USER_MOTOR_MAX_CURRENT_A

Definition at line 119 of file proj_enc_fast.c.

Referenced by mainISR().

EST_Traj_State_e gTrajState = EST_Traj_State_Idle

Definition at line 55 of file proj_enc_fast.c.

Referenced by updateGlobalVariables_motor().

HAL_Obj hal

the hardware abstraction layer object

Definition at line 175 of file proj_enc_fast.c.

IPARK_Obj ipark

the inverse Park transform object

Definition at line 180 of file proj_enc_fast.c.

IPARK_Handle iparkHandle

the handle for the inverse Park transform

Definition at line 179 of file proj_enc_fast.c.

PARK_Obj park

the Park transform object

Definition at line 183 of file proj_enc_fast.c.

PARK_Handle parkHandle

the handle for the Park object

Definition at line 182 of file proj_enc_fast.c.

QUEUE_Obj queue

the queue object

Definition at line 186 of file proj_enc_fast.c.

QUEUE_Handle queueHandle

the handle for the queue

Definition at line 185 of file proj_enc_fast.c.

SVGEN_Obj svgen

the space vector generator object

Definition at line 189 of file proj_enc_fast.c.

SVGEN_Handle svgenHandle

the handle for the space vector generator

Definition at line 188 of file proj_enc_fast.c.