qec.h
00001
00002
00003
00004
00005
00006
00007
00008
00009 #ifndef __QEC_H__
00010 #define __QEC_H__
00011
00012
00013
00014
00016 typedef enum qec_resolution {
00017 QEC_NULL = 0,
00018 QEC_2X = 2,
00019 QEC_4X = 4
00020 } QEC_RESOLUTION;
00021
00023 typedef enum qec_nums {
00024 QEC_1 = 0,
00025 QEC_2
00026 } QEC_ID;
00027
00028
00030 typedef struct qec_data{
00031 volatile int current_pos;
00032 int prev_pos;
00033 int delta_pos;
00034 int delta_time;
00035 int* pos_buf;
00036 int* time_buf;
00037 int index;
00038 int length;
00039 float velocity;
00040 volatile int prev_chA;
00041 volatile int prev_chB;
00042 QEC_RESOLUTION resolution;
00043 } QEC_DATA;
00044
00045 #define QEC_2_PI (6.283185307179586476925286766559f) //approximately
00046
00047
00048
00049 int qec_get_abs_pos(QEC_ID id);
00050 void qec_update_velocity(void);
00051 float qec_get_velocity(QEC_ID id);
00052 void qec_init(QEC_RESOLUTION enc_res_1, int enc1_avg_time, QEC_RESOLUTION enc_res_2, int enc2_avg_time, VOID_VOID_F function);
00053 int qec_is_stopped(QEC_ID id);
00054
00055 void qec_isr(void);
00056 static void qec_init_data(volatile QEC_DATA* data, QEC_RESOLUTION resolution, int* pos_buf, int* time_buf, int length);
00057 static void qec_calc_velocity(volatile QEC_DATA* data, int ticks_elapsed);
00058
00059 void qec_update(volatile QEC_DATA* data, int flag_chA, int flag_chB, int chA, int chB);
00060
00061 #endif // __QEC_H__
00062