MotorWare f2806x Module API Documentation
Data Structures | Macros | Typedefs | Enumerations | Functions
ENC

Data Structures

struct  _ENC_Obj_
 Defines the encoder object. More...
 

Macros

#define ENC_SPEED_SCALING_FACTOR   16777216.0
 
#define ENC_ZERO_OFFSET   3813071.0
 
#define ENC_SPEED_CUTOFF_FREQ   100.0
 
#define ENC_SPEED_COEFF_Q   6
 
#define ENC_SPEED_COEFF_SCALING   (1<<ENC_SPEED_COEFF_Q)
 
#define ENC_2PI   (2.0*3.14159)
 
#define ENC_LOG_LEN   256
 
#define ENC_RPM_Q1   8
 
#define ENC_RPM_Q2   16
 
#define ENC_LOG_DELTA_TRIGGER_THRES   400
 

Typedefs

typedef struct _ENC_Obj_ ENC_Obj
 Defines the encoder object. More...
 
typedef struct _ENC_Obj_ENC_Handle
 Defines the encoder handle. More...
 

Enumerations

enum  ENC_LOG_State_e { ENC_LOG_STATE_IDLE =0, ENC_LOG_STATE_FREERUN, ENC_LOG_STATE_ACQUIRE }
 Enumeration for the encoder log states. More...
 

Functions

void ENC_calcElecAngle (ENC_Handle encHandle, uint32_t posnCounts)
 Reads encoder and returns the electrical degrees in Q24 format. More...
 
_iq ENC_getElecAngle (ENC_Handle encHandle)
 Returns the electrical angle. More...
 
_iq ENC_getMagneticAngle (ENC_Handle encHandle)
 Returns the magnetic angle. More...
 
_iq ENC_getFilteredSpeed (ENC_Handle encHandle)
 Returns the low-pass filtered speed output. More...
 
int16_t ENC_getSpeedRPM (ENC_Handle encHandle)
 Returns the filtered speed in RPM. More...
 
ENC_Handle ENC_init (void *pMemory, const size_t numBytes)
 Initializes the encoder object. More...
 
void ENC_run (ENC_Handle encHandle, uint32_t posnCounts, uint16_t indextFlag, uint16_t dirFlag, int16_t log_flag)
 Based on the encoder reading, computes the electrical angle and the electrical "speed". More...
 
void ENC_setIncrementalSlip (ENC_Handle encHandle, _iq incrementalSlip)
 Set the amount of incremental slip. More...
 
void ENC_setRunFlag (ENC_Handle encHandle)
 Start logging encoder data. More...
 
void ENC_setZeroOffset (ENC_Handle encHandle, uint32_t zeroOffset)
 Sets the value for the encoder object zero offset. More...
 
void ENC_setup (ENC_Handle encHandle, const int16_t sample_period, const uint16_t num_pole_pairs, const uint16_t num_enc_slots, const uint32_t enc_zero_offset, const float_t full_scale_freq, const float_t speed_update_freq, const float_t speed_cutoff)
 Initializes encoder object parameters. More...
 

Detailed Description


Data Structure Documentation

struct _ENC_Obj_

Defines the encoder object.

Definition at line 86 of file enc.h.

Data Fields
int32_t delta_enc encoder count delta
int32_t enc_elec_angle encoder current electrical angle
int32_t enc_magnetic_angle encoder current magnetic angle (compensated for slip)
int32_t enc_slip_angle amount of total slip
uint32_t enc_zero_offset encoder zero offset in counts
float_t full_scale_freq full scale frequency
int32_t incremental_slip incremental amount of slip
int16_t log[ENC_LOG_LEN] encoder log length
int32_t log_idx encoder log index
ENC_LOG_State_e log_state encoder log state
_iq mech_angle_gain gain which converts the encoder counts to Q24 mechanical degrees
uint16_t num_enc_slots number of encoder slots
uint16_t num_pole_pairs number of pole pairs in motor
int16_t post_trigger_cnt encoder log post trigger counter
int16_t post_trigger_len encoder log post trigger length
int32_t prev_enc previous encoder reading
int32_t rpm_gain gain which converts the Q24 normalized electrical freq to RPM
int16_t run_flag encoder log free run flag
int16_t sample_count when it reaches the sample period, collect & process encoder data
int16_t sample_period sample period of encoder processing
float_t speed_cutoff speed cutoff frequency in Hz
int32_t speed_gain gain which converts a difference in encoder counts to Q24 normalized electrical freq
int32_t speed_lpf_cx speed input coefficient
int32_t speed_lpf_cy speed output coefficient
int32_t speed_lpf_out speed lpf output
int16_t trigger_delta calculated delta when trigger happened
int16_t trigger_idx index where trigger event happened

Macro Definition Documentation

#define ENC_2PI   (2.0*3.14159)

Definition at line 65 of file enc.h.

Referenced by ENC_setup().

#define ENC_LOG_DELTA_TRIGGER_THRES   400

Definition at line 69 of file enc.h.

Referenced by ENC_run().

#define ENC_LOG_LEN   256

Definition at line 66 of file enc.h.

Referenced by ENC_run(), and ENC_setup().

#define ENC_RPM_Q1   8

Definition at line 67 of file enc.h.

Referenced by ENC_getSpeedRPM().

#define ENC_RPM_Q2   16

Definition at line 68 of file enc.h.

Referenced by ENC_getSpeedRPM().

#define ENC_SPEED_COEFF_Q   6

Definition at line 63 of file enc.h.

Referenced by ENC_run().

#define ENC_SPEED_COEFF_SCALING   (1<<ENC_SPEED_COEFF_Q)

Definition at line 64 of file enc.h.

Referenced by ENC_setup().

#define ENC_SPEED_CUTOFF_FREQ   100.0

Definition at line 62 of file enc.h.

#define ENC_SPEED_SCALING_FACTOR   16777216.0

Definition at line 60 of file enc.h.

Referenced by ENC_setup().

#define ENC_ZERO_OFFSET   3813071.0

Definition at line 61 of file enc.h.

Typedef Documentation

typedef struct _ENC_Obj_* ENC_Handle

Defines the encoder handle.

Definition at line 120 of file enc.h.

typedef struct _ENC_Obj_ ENC_Obj

Defines the encoder object.

Enumeration Type Documentation

Enumeration for the encoder log states.

Enumerator
ENC_LOG_STATE_IDLE 

idle state

ENC_LOG_STATE_FREERUN 

freerun state

ENC_LOG_STATE_ACQUIRE 

acquire state

Definition at line 77 of file enc.h.

Function Documentation

void ENC_calcElecAngle ( ENC_Handle  encHandle,
uint32_t  posnCounts 
)

Reads encoder and returns the electrical degrees in Q24 format.

Parameters
[in]encHandleHandle to the ENC object
[in]posnCountsCurrent position counts from encoder
Returns
Nothing

Definition at line 129 of file enc.c.

References _ENC_Obj_::enc_elec_angle, _ENC_Obj_::enc_magnetic_angle, _ENC_Obj_::enc_slip_angle, _ENC_Obj_::enc_zero_offset, _ENC_Obj_::incremental_slip, _ENC_Obj_::mech_angle_gain, and _ENC_Obj_::num_pole_pairs.

_iq ENC_getElecAngle ( ENC_Handle  encHandle)
inline

Returns the electrical angle.

Parameters
[in]encHandleHandle to the ENC object
Returns
Electrical angle in Q24

Definition at line 136 of file enc.h.

References _ENC_Obj_::enc_elec_angle.

_iq ENC_getFilteredSpeed ( ENC_Handle  encHandle)
inline

Returns the low-pass filtered speed output.

Parameters
[in]encHandleHandle to the ENC object
Returns
LPF speed output in Q24

Definition at line 156 of file enc.h.

References _ENC_Obj_::speed_lpf_out.

_iq ENC_getMagneticAngle ( ENC_Handle  encHandle)
inline

Returns the magnetic angle.

Parameters
[in]encHandleHandle to the ENC object
Returns
Magnetic angle in Q24

Definition at line 146 of file enc.h.

References _ENC_Obj_::enc_magnetic_angle.

int16_t ENC_getSpeedRPM ( ENC_Handle  encHandle)

Returns the filtered speed in RPM.

Parameters
[in]encHandleHandle to the ENC object
Returns
RPM in Q0

Definition at line 300 of file enc.c.

References ENC_RPM_Q1, ENC_RPM_Q2, _ENC_Obj_::rpm_gain, and _ENC_Obj_::speed_lpf_out.

ENC_Handle ENC_init ( void *  pMemory,
const size_t  numBytes 
)

Initializes the encoder object.

Parameters
[in]pMemoryMemory pointer to object
[in]numBytesObject size
Returns
Object handle

Definition at line 55 of file enc.c.

void ENC_run ( ENC_Handle  encHandle,
uint32_t  posnCounts,
uint16_t  indextFlag,
uint16_t  dirFlag,
int16_t  log_flag 
)

Based on the encoder reading, computes the electrical angle and the electrical "speed".

Parameters
[in]encHandleHandle to the ENC object
[in]posnCountsCurrent position counts from encoder
[in]indextFlagIf set, there was an index
[in]dirFlagIndicates direction of rotation
[in]log_flagIf set, logs the encoder data
Returns
Nothing

Definition at line 163 of file enc.c.

References _ENC_Obj_::delta_enc, _ENC_Obj_::enc_elec_angle, ENC_LOG_DELTA_TRIGGER_THRES, ENC_LOG_LEN, ENC_LOG_STATE_ACQUIRE, ENC_LOG_STATE_FREERUN, ENC_LOG_STATE_IDLE, ENC_SPEED_COEFF_Q, _ENC_Obj_::enc_zero_offset, _ENC_Obj_::log, _ENC_Obj_::log_idx, _ENC_Obj_::log_state, _ENC_Obj_::mech_angle_gain, _ENC_Obj_::num_enc_slots, _ENC_Obj_::num_pole_pairs, _ENC_Obj_::post_trigger_cnt, _ENC_Obj_::post_trigger_len, _ENC_Obj_::prev_enc, _ENC_Obj_::run_flag, _ENC_Obj_::sample_count, _ENC_Obj_::sample_period, _ENC_Obj_::speed_gain, _ENC_Obj_::speed_lpf_cx, _ENC_Obj_::speed_lpf_cy, _ENC_Obj_::speed_lpf_out, _ENC_Obj_::trigger_delta, and _ENC_Obj_::trigger_idx.

void ENC_setIncrementalSlip ( ENC_Handle  encHandle,
_iq  incrementalSlip 
)
inline

Set the amount of incremental slip.

Parameters
[in]encHandleHandle to the ENC object
[in]incrementalSlipAmount of incremental slip in Electrical Angle

Definition at line 189 of file enc.h.

References _ENC_Obj_::incremental_slip.

void ENC_setRunFlag ( ENC_Handle  encHandle)
inline

Start logging encoder data.

Parameters
[in]encHandleHandle to the ENC object

Definition at line 201 of file enc.h.

References _ENC_Obj_::run_flag.

void ENC_setup ( ENC_Handle  encHandle,
const int16_t  sample_period,
const uint16_t  num_pole_pairs,
const uint16_t  num_enc_slots,
const uint32_t  enc_zero_offset,
const float_t  full_scale_freq,
const float_t  speed_update_freq,
const float_t  speed_cutoff 
)

Initializes encoder object parameters.

Parameters
[in]encHandleHandle to the ENC object
[in]sample_periodHow often the encoder is read & processed
[in]num_pole_pairsNumber of pole pairs in motor
[in]num_enc_slotsNumber of encoder slots
[in]enc_zero_offsetEncoder zero offset in counts
[in]full_scale_freqFull scale speed for normalization
[in]speed_update_freqUpdate frequency in Hz for speed calculation
[in]speed_cutoffSpeed calculation LPF cutoff frequency in Hz

Definition at line 68 of file enc.c.

References _ENC_Obj_::delta_enc, ENC_2PI, _ENC_Obj_::enc_elec_angle, ENC_LOG_LEN, ENC_LOG_STATE_IDLE, ENC_SPEED_COEFF_SCALING, ENC_SPEED_SCALING_FACTOR, _ENC_Obj_::enc_zero_offset, _ENC_Obj_::full_scale_freq, _ENC_Obj_::log, _ENC_Obj_::log_idx, _ENC_Obj_::log_state, _ENC_Obj_::mech_angle_gain, _ENC_Obj_::num_enc_slots, _ENC_Obj_::num_pole_pairs, _ENC_Obj_::post_trigger_cnt, _ENC_Obj_::post_trigger_len, _ENC_Obj_::prev_enc, _ENC_Obj_::rpm_gain, _ENC_Obj_::run_flag, _ENC_Obj_::sample_count, _ENC_Obj_::sample_period, _ENC_Obj_::speed_cutoff, _ENC_Obj_::speed_gain, _ENC_Obj_::speed_lpf_cx, _ENC_Obj_::speed_lpf_cy, _ENC_Obj_::speed_lpf_out, _ENC_Obj_::trigger_delta, and _ENC_Obj_::trigger_idx.

void ENC_setZeroOffset ( ENC_Handle  encHandle,
uint32_t  zeroOffset 
)
inline

Sets the value for the encoder object zero offset.

Parameters
[in]encHandleHandle to the ENC object
[in]zeroOffsetNew zero offset

Definition at line 214 of file enc.h.

References _ENC_Obj_::enc_zero_offset, and _ENC_Obj_::mech_angle_gain.