-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathencoder.h
executable file
·159 lines (146 loc) · 5.59 KB
/
encoder.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
/*******************************************************************************
*
* TITLE: encoder.h
*
* VERSION: 0.6 (Beta)
*
* DATE: 15-Jan-2008
*
* AUTHOR: R. Kevin Watson
*
* COMMENTS: This version is compatible with Microchip C18 3.0+ only.
*
* This file best viewed with tabs set to four.
*
* You are free to use this source code for any non-commercial
* use. Please do not make copies of this source code, modified
* or un-modified, publicly available on the internet or
* elsewhere without permission. Thanks.
*
* Copyright ©2003-2008 R. Kevin Watson. All rights are reserved.
*
********************************************************************************
*
* CHANGE LOG:
*
* DATE REV DESCRIPTION
* ----------- --- ----------------------------------------------------------
* 20-Dec-2003 0.1 RKW - Original code.
* 18-Feb-2004 0.2 RKW - Reassigned the encoder digital inputs to run
* on the FRC robot controller too.
* 01-Jan-2005 0.3 RKW - Get_Left_Encoder_Count(), Get_Right_Encoder_Count(),
* Reset_Left_Encoder_Count() and Reset_Right_Encoder_Count()
* functions added.
* 01-Jan-2005 0.3 RKW - Renamed Int_1_Handler() and Int_2_Handler() to
* Left_Encoder_Int_Handler() and Right_Encoder_Int_Handler
* respectively.
* 01-Jan-2005 0.3 RKW - Altered the interrupt service routines to easily
* flip the direction the encoders count by altering the
* RIGHT_ENCODER_TICK_DELTA and LEFT_ENCODER_TICK_DELTA
* #defines found in encoder.h
* 06-Jan-2005 0.4 RKW - Rebuilt with C18 version 2.40.
* 17-Dec-2005 0.5 RKW - Added code to accomodate four more encoder on
* interrupts 3 through 6. These additional encoder inputs
* are optimized for position control.
* 13-Jan-2006 0.5 RKW - Verified code works properly on new PIC18F8722-
* based robot controllers.
* 15-Jan-2008 0.6 RKW - renamed ISRs to be compatible with new robot
* controller code; restructured the ENABLE_ENCODER_n
* scheme to be compatible with new robot controller code.
*
*******************************************************************************/
#ifndef _encoder_h
#define _encoder_h
// Remove the comment slashes from one or more of the following lines to
// enable the respective encoder channel(s). By doing so, you only enable
// the code within encoder.c to become part of your software build. For
// your software to be fully functional, you must also enable the
// interrupt(s) in ifi_frc.h.
#define ENABLE_ENCODER_1 // also enable interrupt 1 in ifi_frc.h
// #define ENABLE_ENCODER_2 // also enable interrupt 2 in ifi_frc.h
// #define ENABLE_ENCODER_3 // also enable interrupt 3 in ifi_frc.h
// #define ENABLE_ENCODER_4 // also enable interrupt 4 in ifi_frc.h
// #define ENABLE_ENCODER_5 // also enable interrupt 5 in ifi_frc.h
// #define ENABLE_ENCODER_6 // also enable interrupt 6 in ifi_frc.h
// Digital input pin(s) assigned to the encoder's phase-B output. Make sure
// this pin is configured as an input in main.c/Initialization().
#define ENCODER_1_PHASE_B_PIN rc_dig_in06
#define ENCODER_2_PHASE_B_PIN rc_dig_in12
#define ENCODER_3_PHASE_B_PIN rc_dig_in13
#define ENCODER_4_PHASE_B_PIN rc_dig_in14
#define ENCODER_5_PHASE_B_PIN rc_dig_in15
#define ENCODER_6_PHASE_B_PIN rc_dig_in16
// Change the sign of these if you need to flip the way the encoders count.
// For instance, if a given encoder count increases in the positive direction
// when rotating counter-clockwise, but you want it to count in the negative
// direction when rotating in the counter-clockwise direction, flip the sign
// (i.e., change 1 to -1) and it'll work the way you need it to.
#define ENCODER_1_TICK_DELTA 1
#define ENCODER_2_TICK_DELTA 1
#define ENCODER_3_TICK_DELTA 1
#define ENCODER_4_TICK_DELTA 1
#define ENCODER_5_TICK_DELTA 1
#define ENCODER_6_TICK_DELTA 1
//
// If you modify stuff below this line, you'll break the software.
//
// #define ENABLE_ENCODER_3_6 if encoder 3, 4, 5 or 6 is enabled
#ifdef ENABLE_ENCODER_3
#ifndef ENABLE_ENCODER_3_6
#define ENABLE_ENCODER_3_6
#endif
#endif
#ifdef ENABLE_ENCODER_4
#ifndef ENABLE_ENCODER_3_6
#define ENABLE_ENCODER_3_6
#endif
#endif
#ifdef ENABLE_ENCODER_5
#ifndef ENABLE_ENCODER_3_6
#define ENABLE_ENCODER_3_6
#endif
#endif
#ifdef ENABLE_ENCODER_6
#ifndef ENABLE_ENCODER_3_6
#define ENABLE_ENCODER_3_6
#endif
#endif
// function prototypes
#ifdef ENABLE_ENCODER_1
void Initialize_Encoder_1(void);
long Get_Encoder_1_Count(void);
void Reset_Encoder_1_Count(void);
void Int_1_ISR(void);
#endif
#ifdef ENABLE_ENCODER_2
void Initialize_Encoder_2(void);
long Get_Encoder_2_Count(void);
void Reset_Encoder_2_Count(void);
void Int_2_ISR(void);
#endif
#ifdef ENABLE_ENCODER_3
void Initialize_Encoder_3_6(void);
long Get_Encoder_3_Count(void);
void Reset_Encoder_3_Count(void);
void Int_3_ISR(unsigned char);
#endif
#ifdef ENABLE_ENCODER_4
void Initialize_Encoder_3_6(void);
long Get_Encoder_4_Count(void);
void Reset_Encoder_4_Count(void);
void Int_4_ISR(unsigned char);
#endif
#ifdef ENABLE_ENCODER_5
void Initialize_Encoder_3_6(void);
long Get_Encoder_5_Count(void);
void Reset_Encoder_5_Count(void);
void Int_5_ISR(unsigned char);
#endif
#ifdef ENABLE_ENCODER_6
void Initialize_Encoder_3_6(void);
long Get_Encoder_6_Count(void);
void Reset_Encoder_6_Count(void);
void Int_6_ISR(unsigned char);
#endif
#endif