68 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)
101 temp = (
float_t)((full_scale_freq*60.0)/num_pole_pairs);
106 speed_cutoff_radians =
ENC_2PI*speed_cutoff;
107 temp = speed_cutoff_radians/(speed_update_freq+speed_cutoff_radians);
144 temp &= ((uint32_t) 0x00ffffff);
154 temp &= ((uint32_t) 0x00ffffff);
163 void ENC_run(
ENC_Handle encHandle, uint32_t posnCounts, uint16_t indextFlag, uint16_t dirFlag, int16_t log_flag)
166 uint16_t index_event_before;
167 uint16_t index_event_after;
172 int16_t sample_count;
187 index_event_before = indextFlag;
190 enc_val = posnCounts;
200 temp &= ((uint32_t) 0x00ffffff);
212 index_event_after = indextFlag;
215 if (index_event_after)
228 delta_enc = enc_val - enc->
prev_enc;
232 if ((index_event_after == index_event_before) && (abs(delta_enc) < enc->
num_enc_slots))
311 return (int16_t) temp;
int16_t post_trigger_len
encoder log post trigger length
int16_t trigger_idx
index where trigger event happened
int16_t run_flag
encoder log free run flag
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".
float_t full_scale_freq
full scale frequency
int32_t speed_lpf_cy
speed output coefficient
int32_t delta_enc
encoder count delta
int16_t sample_count
when it reaches the sample period, collect & process encoder data
#define ENC_LOG_DELTA_TRIGGER_THRES
#define ENC_SPEED_COEFF_Q
int32_t speed_lpf_cx
speed input coefficient
int32_t rpm_gain
gain which converts the Q24 normalized electrical freq to RPM
uint16_t num_pole_pairs
number of pole pairs in motor
int32_t prev_enc
previous encoder reading
#define ENC_SPEED_COEFF_SCALING
uint32_t enc_zero_offset
encoder zero offset in counts
Defines the encoder object.
int16_t sample_period
sample period of encoder processing
int16_t trigger_delta
calculated delta when trigger happened
int32_t incremental_slip
incremental amount of slip
ENC_Handle ENC_init(void *pMemory, const size_t numBytes)
Initializes the encoder object.
void ENC_calcElecAngle(ENC_Handle encHandle, uint32_t posnCounts)
Reads encoder and returns the electrical degrees in Q24 format.
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.
int32_t enc_elec_angle
encoder current electrical angle
int32_t log_idx
encoder log index
int16_t post_trigger_cnt
encoder log post trigger counter
uint16_t num_enc_slots
number of encoder slots
Contains the public interface to the encoder module routines.
int32_t enc_magnetic_angle
encoder current magnetic angle (compensated for slip)
int32_t enc_slip_angle
amount of total slip
ENC_LOG_State_e log_state
encoder log state
int32_t speed_lpf_out
speed lpf output
int16_t ENC_getSpeedRPM(ENC_Handle encHandle)
Returns the filtered speed in RPM.
int32_t speed_gain
gain which converts a difference in encoder counts to Q24 normalized electrical freq ...
float_t speed_cutoff
speed cutoff frequency in Hz
struct _ENC_Obj_ * ENC_Handle
Defines the encoder handle.
_iq mech_angle_gain
gain which converts the encoder counts to Q24 mechanical degrees
#define ENC_SPEED_SCALING_FACTOR
int16_t log[ENC_LOG_LEN]
encoder log length
float float_t
Defines the portable data type for 32 bit, signed floating-point data.