SensorlessFOCMotorControlLibrary  1.0
Data Structures | Macros | Functions | Variables
FOC_LIBRARY/FOC

Data Structures

struct  COMMAND
 Define command structure. More...
 
struct  ALIGN_Instance
 Define align startup instance. More...
 
struct  RAMPUP_Instance
 Define rampup instance. More...
 
struct  CONTROL
 Define control structure. More...
 
struct  FOC_Instance
 Define FOC structure. More...
 

Macros

#define FLASH_PARAMS_BASE_ADDRESS   HAL_MEMORY_FLASH_PARAMS_BASE_ADDRESS
 Base address of the saved parameters in FLASH.
 
#define SRAM_PARAMS_BASE_ADDRESS   HAL_MEMORY_SRAM_PARAMS_BASE_ADDRESS
 Base address of the saved parameters in SRAM.
 
#define FOC_WRITE_FLAG_SIGNATURE   (0x789ABCDE)
 Memory Signature for write configurations flag.
 
#define FOC_CRC_SEED   (0xFFFFFFFF)
 Seed value for the CRC calculation.
 
#define FOC_WRITE_FLAG_SIZE_BYTES   (4)
 Size of the write flag in bytes.
 
#define FOC_CRC_SIZE_BYTES   (4)
 Size of the CRC in bytes.
 
#define FOC_FLASH_ACCESSKEY   (0xA)
 Access key for flash.
 
#define BYTES_TO_WORD_RSHIFT   (2)
 Right shift to convert bytes to words.
 
#define FOC_CONTROL_LOOP_FREQ_HZ   (1000)
 Frequency of the foc control loop.
 
#define CALIB_SAMPLES_2_POW   (10)
 Calibration samples in power of 2.
 
#define CALIB_AVG_SAMPLES   (1 << CALIB_SAMPLES_2_POW)
 Calibration samples to average.
 
#define FOC_PIIDQ_LMT_IQ   _IQ(0.866)
 Limit for the resultant voltage vector is 0.866 of vdc.
 
#define FOC_LOG_BUF_SIZE   (1024)
 Size of the FOC variable logging buffer.
 
#define FOC_USERVAR_UPDATE_MS   (200)
 Uservar update rate in milliseconds.
 
#define FOC_12_TO_8_BIT_OFFSET_SHIFT   (4)
 12 bit offset to 8 bit shift factor
 
#define USER_DEFAULT_VOLTAGE_SF
 Computing voltage scale factor. More...
 
#define USER_DEFAULT_CURRENT_SF
 Computing current scale factor. More...
 

Functions

void FOC_init (FOC_Instance *handle)
 Disables the PWM outputs. More...
 
void FOC_initFLASH (void)
 Loads the saved variables from flash to sram if the crc is correct.
 
void FOC_initUserParamsFoc (USER_PARAMS *userParamsFoc, USER_PARAMS *userParams, uint32_t size)
 Sets the values of foc vars as user vars + 1, it is used to later update the foc vars with user vars while update parameters. More...
 
void FOC_loadSavedParams (USER_PARAMS *dstParams, const USER_PARAMS *srcParams, uint32_t size)
 Copies from source parameters to destination parameters. More...
 
void FOC_writeFLASH (USER_PARAMS *params, uint32_t size)
 Erases and writes the variables to flash. More...
 
void FOC_setPara (FOC_Instance *handle, PARA_IDX paraIdx, int32_t value)
 Sets the FOC parameter and updates the modules. More...
 
void FOC_setFault (FOC_Instance *handle)
 Sets the state machine to fault state and disables PWM output. More...
 
void FOC_clearFault (FOC_Instance *handle)
 Clears all the recorded faults. More...
 
__STATIC_INLINE bool FOC_getPwmEnableStatus (FOC_Instance *handle)
 Gets the status of the PWM channels. More...
 
__STATIC_INLINE void FOC_setPwmEnableStatus (FOC_Instance *handle, bool enablePWMState)
 Sets the status of the PWM channels. More...
 
__STATIC_INLINE _iq FOC_getPIIQLMT (FOC_Instance *handle)
 Calculated the limits for the PI IQ integral outputs. More...
 
__STATIC_INLINE void FOC_setADCTrig (FOC_Instance *handle)
 Set the PWM channel to trigger ADC. More...
 
void FOC_paramsUpdateProcess (FOC_Instance *handle, USER_VAR *userVar)
 Does the process of updating the foc variables with the userVar. More...
 
__STATIC_INLINE void FOC_runMonitor (FOC_Instance *handle)
 Checks the fault conditions. More...
 
__STATIC_INLINE void FOC_CONTROL_run (FOC_Instance *handle)
 FOC motor control loop. More...
 
__STATIC_INLINE void FOC_run (FOC_Instance *handle)
 Runs FOC loop. More...
 
__STATIC_INLINE void FOC_UpdateADCRaw (FOC_Instance *handle, uint16_t vdcAdc, uint16_t iaAdc, uint16_t ibAdc, uint16_t icAdc)
 Updates the adc values in the FOC instance. More...
 
__STATIC_INLINE void FOC_loop (FOC_Instance *handle, uint16_t vdcAdc, uint16_t iaAdc, uint16_t ibAdc, uint16_t icAdc)
 Runs the FOC tasks. More...
 

Variables

IPD_Instance ipd
 Create a ipd instance.
 
PWMGEN_Instance pwmgen
 Create a pwmgen instance.
 
PI_Instance piSpd
 Create a PI speed instance.
 
PI_Instance piId
 Create a PI Id instance.
 
PI_Instance piIq
 Create a PI Iq instance.
 
CLARKE_Instance clarke
 Create a clarke instance.
 
PARK_Instance park
 Create a park instance.
 
IPARK_Instance ipark
 Create a inverse park instance.
 
SVGEN_Instance svgen
 Create a Space Vector PWM modulator instance.
 
RMPCNTL_Instance rc
 Create a Ramp control instance for speed ramping.
 
RAMPGEN_Instance rg
 Create a Ramp control instance for generating the open loop angle.
 
PHASEVOLT_Instance phaseVolt
 Create a phaseVolt instance.
 
EST_Instance est
 Create an estimator instance.
 
uint32_t offsetCalibcnt
 Counter for offset calibration.
 
uint32_t calibSumA
 Calibration sum of phase A.
 
uint32_t calibSumB
 Calibration sum of phase B.
 
uint32_t calibSumC
 Calibration sum of phase C.
 
uint32_t pAngle
 Temp variable used for storing angle.
 
uint8_t userVarUpdateCounter
 Counter for userVar update.
 

Detailed Description

Macro Definition Documentation

§ USER_DEFAULT_VOLTAGE_SF

#define USER_DEFAULT_VOLTAGE_SF
Value:
#define HAL_ADC_DEFAULT_REF_VOLTAGE
Value of default ADC reference voltage in volts.
Definition: hal.h:81
#define USER_DEFAULT_FOC_VOLT_RATIO
DC bus voltage divider ratio.
Definition: param_drv8323rs.h:56

Computing voltage scale factor.

Referenced by FOC_init().

§ USER_DEFAULT_CURRENT_SF

#define USER_DEFAULT_CURRENT_SF
Value:
#define USER_DEFAULT_BASE_CSA_GAIN
DRV CSA gain when gain setting is 0.
Definition: user.h:64
#define HAL_ADC_DEFAULT_REF_VOLTAGE
Value of default ADC reference voltage in volts.
Definition: hal.h:81
#define USER_DEFAULT_DRV_RSHUNT
DRV shunt resistor in ohms.
Definition: param_drv8323rs.h:59

Computing current scale factor.

Referenced by FOC_init().

Function Documentation

§ FOC_init()

void FOC_init ( FOC_Instance handle)

§ FOC_initUserParamsFoc()

void FOC_initUserParamsFoc ( USER_PARAMS userParamsFoc,
USER_PARAMS userParams,
uint32_t  size 
)

Sets the values of foc vars as user vars + 1, it is used to later update the foc vars with user vars while update parameters.

Parameters
[in]userParamsFocA pointer to user parameters used by foc
[in]userParamsA pointer to user parameters set by user
[in]sizeSize of variables to init in bytes

References BYTES_TO_WORD_RSHIFT.

Referenced by FOC_init(), and FOC_paramsUpdateProcess().

§ FOC_loadSavedParams()

void FOC_loadSavedParams ( USER_PARAMS dstParams,
const USER_PARAMS srcParams,
uint32_t  size 
)

Copies from source parameters to destination parameters.

Parameters
[in]dstParamsPointer to destination parameters
[in]srcParamsPointer to source parameters
[in]sizeSize of variables to init in bytes

Referenced by FOC_initFLASH(), and FOC_paramsUpdateProcess().

§ FOC_writeFLASH()

void FOC_writeFLASH ( USER_PARAMS params,
uint32_t  size 
)

Erases and writes the variables to flash.

Parameters
[in]paramsPointer to the data to be written to flash
[in]sizeSize of variables to init in bytes

References USER_PARAMS::crc, FLASH_PARAMS_BASE_ADDRESS, FOC_CRC_SEED, FOC_CRC_SIZE_BYTES, FOC_WRITE_FLAG_SIGNATURE, FOC_WRITE_FLAG_SIZE_BYTES, HAL_copyMemoryBlock(), HAL_eraseFLASH(), HAL_getCRC(), HAL_unprotectFLASH(), savedParams, and USER_PARAMS::writeFlag.

Referenced by FOC_initFLASH(), and FOC_paramsUpdateProcess().

§ FOC_setPara()

void FOC_setPara ( FOC_Instance handle,
PARA_IDX  paraIdx,
int32_t  value 
)

Sets the FOC parameter and updates the modules.

Parameters
[in]handleA pointer to FOC instance
[in]paraIdxIndex of the parameter to set. USER parameters of PARA_IDX
[in]valueValue to be set

References _IQdiv_rts, _IQmpy_rts, CONTROL::align, ALIGN_Instance::alignCurr, ALIGN_Instance::alignTime, FOC_Instance::cmd, FOC_Instance::control, FOC_Instance::csaDiv, COMMAND::directionReversal, DRV_CSA_GAIN, DRV_HANDLE, DRV_setCsaGain, est, FOC_CONTROL_LOOP_FREQ_HZ, FOC_CSA_GAIN_MAX, FOC_PWM_FREQ_MAX, FOC_Instance::hal, HAL_getPWMLoadValue(), HAL_setDeadband(), HAL_setPWMFreq(), HAL_setRepeatCounter(), ipd, COMMAND::outerLoop, FOC_Instance::overCurrentLimit, FOC_Instance::overVoltageLimit, PARA_checkEST(), PARA_checkIPD(), PARA_checkPIID(), PARA_checkPIIQ(), PARA_checkPISPD(), PARA_checkPWMGEN(), PARA_checkRC(), PARA_checkRG(), PARA_IDX_SYS_DEADBAND_CYC, PARA_IDX_SYS_PWMPERIOD, PARA_IDX_SYS_SAMPLE_FREQ, PARA_IDX_SYS_TS, PARA_IDX_USER_ALIGN_CURRENT, PARA_IDX_USER_ALIGN_TIME, PARA_IDX_USER_AMP_GAIN, PARA_IDX_USER_DEADBAND, PARA_IDX_USER_DIRECTION_REVERSE, PARA_IDX_USER_OUTER_LOOP, PARA_IDX_USER_OVER_CURRENT_LIMIT, PARA_IDX_USER_OVER_VOLTAGE_LIMIT, PARA_IDX_USER_PISPD_DIV, PARA_IDX_USER_PWMFREQ, PARA_IDX_USER_RAMPUP_CURRENT, PARA_IDX_USER_RAMPUP_RATE, PARA_IDX_USER_RAMPUP_TARGET, PARA_IDX_USER_SLOW_FIRST_CYC_FREQ, PARA_IDX_USER_STARTUP_METHOD, PARA_IDX_USER_UNDER_VOLTAGE_LIMIT, FOC_Instance::parameter, FOC_Instance::PISpdExecDivider, FOC_HAL::pwmAHal, CONTROL::rampup, RAMPUP_Instance::rampupCurr, RAMPUP_Instance::rate, CONTROL::slowFirstCycFreq, CONTROL::startupMethod, RAMPUP_Instance::target, and FOC_Instance::underVoltageLimit.

Referenced by FOC_paramsUpdateProcess().

§ FOC_setFault()

void FOC_setFault ( FOC_Instance handle)

§ FOC_clearFault()

void FOC_clearFault ( FOC_Instance handle)

Clears all the recorded faults.

Parameters
[in]handleA pointer to FOC instance

References FAULT_STATUS::all, DRV_HANDLE, FAULT_INPUT_CLEAR, and FOC_Instance::faultStatus.

Referenced by FOC_init(), and FOC_paramsUpdateProcess().

§ FOC_getPwmEnableStatus()

__STATIC_INLINE bool FOC_getPwmEnableStatus ( FOC_Instance handle)

Gets the status of the PWM channels.

Parameters
[in]handleA pointer to FOC instance
Returns
Returns the status of the pwm channels
Return values
trueThe PWM channels are enabled
falseThe PWM channels are disabled

References FOC_Instance::enablePWMStatus.

Referenced by FOC_run().

§ FOC_setPwmEnableStatus()

__STATIC_INLINE void FOC_setPwmEnableStatus ( FOC_Instance handle,
bool  enablePWMState 
)

Sets the status of the PWM channels.

Parameters
[in]handleA pointer to FOC instance
[in]enablePWMStatePWM state to be set

References FOC_Instance::enablePWMStatus, and FOC_LOG_BUF_SIZE.

Referenced by FOC_CONTROL_run(), FOC_run(), and FOC_setFault().

§ FOC_getPIIQLMT()

__STATIC_INLINE _iq FOC_getPIIQLMT ( FOC_Instance handle)

Calculated the limits for the PI IQ integral outputs.

Parameters
[in]handleA pointer to FOC instance
Returns
Returns the PI iq limit

References FOC_PIIDQ_LMT_IQ, PI_Instance::out, and FOC_Instance::vdc.

Referenced by FOC_run().

§ FOC_setADCTrig()

__STATIC_INLINE void FOC_setADCTrig ( FOC_Instance handle)

Set the PWM channel to trigger ADC.

Parameters
[in]handleA pointer to FOC instance

References FOC_HAL::adcTrigHal, FOC_Instance::adcTrigVal, FOC_paramsUpdateProcess(), FOC_Instance::hal, HAL_setPWMCcValue(), and userVar.

Referenced by FOC_init(), and FOC_loop().

§ FOC_paramsUpdateProcess()

void FOC_paramsUpdateProcess ( FOC_Instance handle,
USER_VAR userVar 
)

§ FOC_runMonitor()

__STATIC_INLINE void FOC_runMonitor ( FOC_Instance handle)

§ FOC_CONTROL_run()

__STATIC_INLINE void FOC_CONTROL_run ( FOC_Instance handle)

§ FOC_run()

__STATIC_INLINE void FOC_run ( FOC_Instance handle)

Runs FOC loop.

Parameters
[in]handleA pointer to FOC instance

References PARK_Instance::Alpha, IPARK_Instance::Alpha, CLARKE_Instance::Alpha, PARK_Instance::Angle, RAMPGEN_Instance::Angle, ANGLE_getSine(), ANGLE_MATH_PIp2_PU, CLARKE_Instance::As, PARK_Instance::Beta, IPARK_Instance::Beta, CLARKE_Instance::Beta, CLARKE_Instance::Bs, CLARKE_run(), FOC_Instance::cmd, FOC_Instance::control, IPARK_Instance::Cosine, PARK_Instance::Cosine, FOC_Instance::csaDiv, FOC_Instance::currentSF, PHASEVOLT_Instance::DcBusVolt, COMMAND::directionReversal, IPARK_Instance::Ds, PARK_Instance::Ds, PWMGEN_Instance::dutyA, PWMGEN_Instance::dutyB, PWMGEN_Instance::dutyC, FOC_Instance::enablePWM, PI_Instance::fbk, FOC_12_TO_8_BIT_OFFSET_SHIFT, FOC_getPIIQLMT(), FOC_getPwmEnableStatus(), FOC_OUTER_LOOP_SPEED, FOC_PIIDQ_LMT_IQ, FOC_setPwmEnableStatus(), RAMPGEN_Instance::Freq, FOC_Instance::hal, HAL_PWMDisableChannel(), HAL_PWMEnableChannel(), HAL_setPWMCcValue(), FOC_Instance::ia, FOC_Instance::ib, COMMAND::IdRef, IPARK_run(), COMMAND::IqRef, PWMGEN_Instance::MfuncC1, PWMGEN_Instance::MfuncC2, PWMGEN_Instance::MfuncC3, PHASEVOLT_Instance::MfuncV1, PHASEVOLT_Instance::MfuncV2, PHASEVOLT_Instance::MfuncV3, MOTOR_ALIGN, MOTOR_IDLE, MOTOR_IPD, MOTOR_RAMPUP, MOTOR_RUN, MOTOR_SLOW_FIRST_CYC, MOTOR_STANDBY, MOTOR_STOP, MOTOR_TRANSIT, FOC_Instance::offsetA, FOC_Instance::offsetB, FOC_Instance::offsetC, RAMPGEN_Instance::Out, PI_Instance::out, COMMAND::outerLoop, PI_Instance::outIMax, PI_Instance::outIMin, PI_Instance::outMax, PI_Instance::outMin, PARK_run(), PHASEVOLT_run(), PI_run(), FOC_Instance::PISpdExecCount, FOC_Instance::PISpdExecDivider, FOC_HAL::pwmAHal, FOC_HAL::pwmBHal, FOC_HAL::pwmCHal, PWMGEN_run(), PARK_Instance::Qs, IPARK_Instance::Qs, RAMPUP_Instance::rampOut, CONTROL::rampup, RC_run(), PI_Instance::ref, RG_run(), RMPCNTL_Instance::SetpointValue, IPARK_Instance::Sine, PARK_Instance::Sine, CONTROL::slowFirstCycCmplt, COMMAND::speedRef, FOC_Instance::state, SVGEN_run(), SVGEN_Instance::Ta, RMPCNTL_Instance::TargetValue, SVGEN_Instance::Tb, SVGEN_Instance::Tc, CONTROL::transit, TRANSIT_run(), SVGEN_Instance::Ualpha, SVGEN_Instance::Ubeta, PHASEVOLT_Instance::Valpha, PHASEVOLT_Instance::Vbeta, and FOC_Instance::vdc.

Referenced by FOC_loop().

§ FOC_UpdateADCRaw()

__STATIC_INLINE void FOC_UpdateADCRaw ( FOC_Instance handle,
uint16_t  vdcAdc,
uint16_t  iaAdc,
uint16_t  ibAdc,
uint16_t  icAdc 
)

Updates the adc values in the FOC instance.

Parameters
[in]handleA pointer to FOC instance
[in]vdcAdcADC reading of dc bus
[in]iaAdcADC reading from A phase
[in]ibAdcADC reading from B phase
[in]icAdcADC reading from C phase

References FOC_Instance::iaAdc, FOC_Instance::ibAdc, FOC_Instance::icAdc, and FOC_Instance::vdcAdc.

Referenced by FOC_loop().

§ FOC_loop()

__STATIC_INLINE void FOC_loop ( FOC_Instance handle,
uint16_t  vdcAdc,
uint16_t  iaAdc,
uint16_t  ibAdc,
uint16_t  icAdc 
)
© Copyright 1995-2023, Texas Instruments Incorporated. All rights reserved.
Trademarks | Privacy policy | Terms of use | Terms of sale