SensorlessFOCMotorControlLibrary  1.0
Data Structures | Macros | Functions | Variables
foc.h File Reference

Detailed Description

Sensorless FOC Motor Control Library FOC Module.


Overview

APIs for FOC motor control


#include <stdint.h>
#include <stdbool.h>
#include <ti/iqmath/include/IQmathLib.h>
#include "iqmath_rts.h"
#include "hal.h"
#include "user.h"
#include "foc_types.h"
#include "ipd.h"
#include "rampgen.h"
#include "rmp_cntl.h"
#include "clarke.h"
#include "park.h"
#include "ipark.h"
#include "pi.h"
#include "volt_calc.h"
#include "estimator.h"
#include "svgen.h"
#include "pwmgen.h"
#include "motor_params.h"
#include "parameter.h"
#include "transit.h"
Include dependency graph for foc.h:

Go to the source code of this file.

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.
 
© Copyright 1995-2023, Texas Instruments Incorporated. All rights reserved.
Trademarks | Privacy policy | Terms of use | Terms of sale