Rev 2035 | Rev 2051 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 2035 | Rev 2049 | ||
---|---|---|---|
1 | #ifndef _ANALOG_H |
1 | #ifndef _ANALOG_H |
2 | #define _ANALOG_H |
2 | #define _ANALOG_H |
3 | #include <inttypes.h> |
3 | #include <inttypes.h> |
4 | #include "configuration.h" |
4 | #include "configuration.h" |
5 | 5 | ||
6 | /* |
6 | /* |
7 | * How much low pass filtering to apply for gyro_PID. |
- | |
8 | * 0=illegal, 1=no filtering, 2=50% last value + 50% new value, 3=67% last value + 33 % new value etc... |
- | |
9 | * Temporarily replaced by userparam-configurable variable. |
- | |
10 | */ |
- | |
11 | // #define GYROS_PID_FILTER 1 |
- | |
12 | - | ||
13 | /* |
- | |
14 | * How much low pass filtering to apply for gyro_ATT. |
- | |
15 | * 0=illegal, 1=no filtering, 2=50% last value + 50% new value, 3=67% last value + 33 % new value etc... |
- | |
16 | * Temporarily replaced by userparam-configurable variable. |
- | |
17 | */ |
- | |
18 | // #define GYROS_ATT_FILTER 1 |
- | |
19 | // #define ACC_FILTER 4 |
- | |
20 | - | ||
21 | /* |
- | |
22 | About setting constants for different gyros: |
7 | About setting constants for different gyros: |
23 | Main parameters are positive directions and voltage/angular speed gain. |
8 | Main parameters are positive directions and voltage/angular speed gain. |
24 | The "Positive direction" is the rotation direction around an axis where |
9 | The "Positive direction" is the rotation direction around an axis where |
25 | the corresponding gyro outputs a voltage > the no-rotation voltage. |
10 | the corresponding gyro outputs a voltage > the no-rotation voltage. |
26 | A gyro is considered, in this code, to be "forward" if its positive |
11 | A gyro is considered, in this code, to be "forward" if its positive |
27 | direction is: |
12 | direction is: |
28 | - Nose down for pitch |
13 | - Nose down for pitch |
29 | - Left hand side down for roll |
14 | - Left hand side down for roll |
30 | - Clockwise seen from above for yaw. |
15 | - Clockwise seen from above for yaw. |
31 | |
16 | |
32 | Setting gyro gain correctly: All sensor measurements in analog.c take |
17 | Setting gyro gain correctly: All sensor measurements in analog.c take |
33 | place in a cycle, each cycle comprising all sensors. Some sensors are |
18 | place in a cycle, each cycle comprising all sensors. Some sensors are |
34 | sampled more than ones, and the results added. The pitch and roll gyros |
19 | sampled more than once (oversampled), and the results added. |
35 | are sampled 4 times and the yaw gyro 2 times in the original H&I V0.74 |
- | |
36 | code. |
- | |
37 | In the H&I code, the results for pitch and roll are multiplied by 2 (FC1.0) |
20 | In the H&I code, the results for pitch and roll are multiplied by 2 (FC1.0) |
38 | or 4 (other versions), offset to zero, low pass filtered and then assigned |
21 | or 4 (other versions), offset to zero, low pass filtered and then assigned |
39 | to the "HiResXXXX" and "AdWertXXXXFilter" variables, where XXXX is nick or |
22 | to the "HiResXXXX" and "AdWertXXXXFilter" variables, where XXXX is nick or |
40 | roll. |
- | |
41 | So: |
- | |
42 | - | ||
43 | gyro = V * (ADCValue1 + ADCValue2 + ADCValue3 + ADCValue4), |
23 | roll. The factor 2 or 4 or whatever is called GYRO_FACTOR_PITCHROLL here. |
44 | where V is 2 for FC1.0 and 4 for all others. |
- | |
45 | 24 | */ |
|
46 | Assuming constant ADCValue, in the H&I code: |
25 | #define GYRO_FACTOR_PITCHROLL 1 |
47 | |
- | |
48 | gyro = I * ADCValue. |
- | |
49 | - | ||
50 | where I is 8 for FC1.0 and 16 for all others. |
- | |
- | 26 | ||
51 | 27 | /* |
|
52 | The relation between rotation rate and ADCValue: |
28 | GYRO_HW_FACTOR is the relation between rotation rate and ADCValue: |
53 | ADCValue [units] = |
29 | ADCValue [units] = |
54 | rotational speed [deg/s] * |
30 | rotational speed [deg/s] * |
55 | gyro sensitivity [V / deg/s] * |
31 | gyro sensitivity [V / deg/s] * |
56 | amplifier gain [units] * |
32 | amplifier gain [units] * |
57 | 1024 [units] / |
33 | 1024 [units] / |
58 | 3V full range [V] |
34 | 3V full range [V] |
59 | - | ||
60 | or: H is the number of steps the ADC value changes with, |
35 | |
61 | for a 1 deg/s change in rotational velocity: |
- | |
62 | H = ADCValue [units] / rotation rate [deg/s] = |
36 | GYRO_HW_FACTOR is: |
63 | gyro sensitivity [V / deg/s] * |
37 | gyro sensitivity [V / deg/s] * |
64 | amplifier gain [units] * |
38 | amplifier gain [units] * |
65 | 1024 [units] / |
39 | 1024 [units] / |
66 | 3V full range [V] |
40 | 3V full range [V] |
67 | 41 | ||
68 | Examples: |
42 | Examples: |
69 | FC1.3 has 0.67 mV/deg/s gyros and amplifiers with a gain of 5.7: |
43 | FC1.3 has 0.67 mV/deg/s gyros and amplifiers with a gain of 5.7: |
70 | H = 0.00067 V / deg / s * 5.7 * 1024 / 3V = 1.304 units/(deg/s). |
44 | GYRO_HW_FACTOR = 0.00067 V / deg / s * 5.7 * 1024 / 3V = 1.304 units/(deg/s). |
- | 45 | ||
71 | FC2.0 has 6*(3/5) mV/deg/s gyros (they are ratiometric) and no amplifiers: |
46 | FC2.0 has 6*(3/5) mV/deg/s gyros (they are ratiometric) and no amplifiers: |
72 | H = 0.006 V / deg / s * 1 * 1024 * 3V / (3V * 5V) = 1.2288 units/(deg/s). |
47 | GYRO_HW_FACTOR = 0.006 V / deg / s * 1 * 1024 * 3V / (3V * 5V) = 1.2288 units/(deg/s). |
- | 48 | ||
73 | My InvenSense copter has 2mV/deg/s gyros and no amplifiers: |
49 | My InvenSense copter has 2mV/deg/s gyros and no amplifiers: |
74 | H = 0.002 V / deg / s * 1 * 1024 / 3V = 0.6827 units/(deg/s) |
50 | GYRO_HW_FACTOR = 0.002 V / deg / s * 1 * 1024 / 3V = 0.6827 units/(deg/s) |
75 | (only about half as sensitive as V1.3. But it will take about twice the |
51 | (only about half as sensitive as V1.3. But it will take about twice the |
76 | rotation rate!) |
52 | rotation rate!) |
77 | 53 | ||
78 | All together: gyro = I * H * rotation rate [units / (deg/s)]. |
54 | GYRO_HW_FACTOR is given in the makefile. |
79 | */ |
55 | */ |
80 | - | ||
81 | /* |
- | |
82 | * A factor that the raw gyro values are multiplied by, |
- | |
83 | * before being filtered and passed to the attitude module. |
- | |
84 | * A value of 1 would cause a little bit of loss of precision in the |
- | |
85 | * filtering (on the other hand the values are so noisy in flight that |
- | |
86 | * it will not really matter - but when testing on the desk it might be |
- | |
87 | * noticeable). 4 is fine for the default filtering. |
- | |
88 | * Experiment: Set it to 1. |
- | |
89 | */ |
- | |
90 | #define GYRO_FACTOR_PITCHROLL 1 |
- | |
91 | 56 | ||
92 | /* |
57 | /* |
93 | * How many samples are summed in one ADC loop, for pitch&roll and yaw, |
58 | * How many samples are added in one ADC loop, for pitch&roll and yaw, |
94 | * respectively. This is = the number of occurences of each channel in the |
59 | * respectively. This is = the number of occurences of each channel in the |
95 | * channelsForStates array in analog.c. |
60 | * channelsForStates array in analog.c. |
96 | */ |
61 | */ |
97 | #define GYRO_OVERSAMPLING_PITCHROLL 4 |
62 | #define GYRO_OVERSAMPLING_PITCHROLL 4 |
98 | #define GYRO_OVERSAMPLING_YAW 2 |
63 | #define GYRO_OVERSAMPLING_YAW 2 |
99 | 64 | ||
100 | #define ACC_OVERSAMPLING_XY 2 |
65 | #define ACC_OVERSAMPLING_XY 2 |
101 | #define ACC_OVERSAMPLING_Z 1 |
66 | #define ACC_OVERSAMPLING_Z 1 |
102 | 67 | ||
103 | /* |
68 | /* |
104 | Integration: |
- | |
105 | The HiResXXXX values are divided by 8 (in H&I firmware) before integration. |
- | |
106 | In the Killagreg rewrite of the H&I firmware, the factor 8 is called |
- | |
107 | HIRES_GYRO_AMPLIFY. In this code, it is called HIRES_GYRO_INTEGRATION_FACTOR, |
- | |
108 | and care has been taken that all other constants (gyro to degree factor, and |
- | |
109 | 180 degree flip-over detection limits) are corrected to it. Because the |
- | |
110 | division by the constant takes place in the flight attitude code, the |
69 | * The product of the 3 above constants. This represents the expected change in ADC value sums for 1 deg/s of rotation rate. |
111 | constant is there. |
- | |
112 | - | ||
113 | The control loop executes at 488Hz, and for each iteration |
- | |
114 | gyro_ATT[PITCH/ROLL] is added to gyroIntegral[PITCH/ROLL]. |
- | |
115 | Assuming a constant rotation rate v and a zero initial gyroIntegral |
- | |
116 | (for this explanation), we get: |
- | |
117 | - | ||
118 | gyroIntegral = |
- | |
119 | N * gyro / HIRES_GYRO_INTEGRATION_FACTOR = |
- | |
120 | N * I * H * v / HIRES_GYRO_INTEGRATION_FACTOR |
- | |
121 | - | ||
122 | where N is the number of summations; N = t*488. |
- | |
123 | - | ||
124 | For one degree of rotation: t*v = 1: |
- | |
125 | - | ||
126 | gyroIntegralXXXX = t * 488 * I * H * 1/t = INTEGRATION_FREQUENCY * I * H / HIRES_GYRO_INTEGRATION_FACTOR. |
- | |
127 | - | ||
128 | This number (INTEGRATION_FREQUENCY * I * H) is the integral-to-degree factor. |
- | |
129 | - | ||
130 | Examples: |
- | |
131 | FC1.3: I=4, H=1.304, HIRES_GYRO_INTEGRATION_FACTOR=1 --> integralDegreeFactor = 2545 |
- | |
132 | FC2.0: I=4, H=1.2288, HIRES_GYRO_INTEGRATION_FACTOR=1 --> integralDegreeFactor = 2399 |
- | |
133 | My InvenSense copter: HIRES_GYRO_INTEGRATION_FACTOR=4, H=0.6827 --> integralDegreeFactor = 1333 |
- | |
134 | */ |
70 | */ |
- | 71 | #define GYRO_RATE_FACTOR_PITCHROLL (GYRO_HW_FACTOR * GYRO_OVERSAMPLING_PITCHROLL * GYRO_FACTOR_PITCHROLL) |
|
- | 72 | #define GYRO_RATE_FACTOR_YAW (GYRO_HW_FACTOR * GYRO_OVERSAMPLING_YAW) |
|
135 | 73 | ||
136 | /* |
74 | /* |
137 | * The value of gyro[PITCH/ROLL] for one deg/s = The hardware factor H * the number of samples * multiplier factor. |
75 | * The value of gyro[PITCH/ROLL] for one deg/s = The hardware factor H * the number of samples * multiplier factor. |
138 | * Will be about 10 or so for InvenSense, and about 33 for ADXRS610. |
76 | * Will be about 10 or so for InvenSense, and about 33 for ADXRS610. |
139 | */ |
77 | */ |
140 | #define GYRO_RATE_FACTOR_PITCHROLL (GYRO_HW_FACTOR * GYRO_OVERSAMPLING_PITCHROLL * GYRO_FACTOR_PITCHROLL) |
- | |
141 | #define GYRO_RATE_FACTOR_YAW (GYRO_HW_FACTOR * GYRO_OVERSAMPLING_YAW) |
- | |
142 | 78 | ||
143 | /* |
79 | /* |
144 | * Gyro saturation prevention. |
80 | * Gyro saturation prevention. |
145 | */ |
81 | */ |
146 | // How far from the end of its range a gyro is considered near-saturated. |
82 | // How far from the end of its range a gyro is considered near-saturated. |
147 | #define SENSOR_MIN_PITCHROLL 32 |
83 | #define SENSOR_MIN_PITCHROLL 32 |
148 | // Other end of the range (calculated) |
84 | // Other end of the range (calculated) |
149 | #define SENSOR_MAX_PITCHROLL (GYRO_OVERSAMPLING_PITCHROLL * 1023 - SENSOR_MIN_PITCHROLL) |
85 | #define SENSOR_MAX_PITCHROLL (GYRO_OVERSAMPLING_PITCHROLL * 1023 - SENSOR_MIN_PITCHROLL) |
150 | // Max. boost to add "virtually" to gyro signal at total saturation. |
86 | // Max. boost to add "virtually" to gyro signal at total saturation. |
151 | #define EXTRAPOLATION_LIMIT 2500 |
87 | #define EXTRAPOLATION_LIMIT 2500 |
152 | // Slope of the boost (calculated) |
88 | // Slope of the boost (calculated) |
153 | #define EXTRAPOLATION_SLOPE (EXTRAPOLATION_LIMIT/SENSOR_MIN_PITCHROLL) |
89 | #define EXTRAPOLATION_SLOPE (EXTRAPOLATION_LIMIT/SENSOR_MIN_PITCHROLL) |
154 | 90 | ||
155 | /* |
91 | /* |
156 | * This value is subtracted from the gyro noise measurement in each iteration, |
92 | * This value is subtracted from the gyro noise measurement in each iteration, |
157 | * making it return towards zero. |
93 | * making it return towards zero. |
158 | */ |
94 | */ |
159 | #define GYRO_NOISE_MEASUREMENT_DAMPING 5 |
95 | #define GYRO_NOISE_MEASUREMENT_DAMPING 5 |
160 | 96 | ||
161 | #define PITCH 0 |
97 | #define PITCH 0 |
162 | #define ROLL 1 |
98 | #define ROLL 1 |
163 | #define YAW 2 |
99 | #define YAW 2 |
164 | #define Z 2 |
100 | #define Z 2 |
165 | /* |
101 | /* |
166 | * The values that this module outputs |
102 | * The values that this module outputs |
167 | * These first 2 exported arrays are zero-offset. The "PID" ones are used |
103 | * These first 2 exported arrays are zero-offset. The "PID" ones are used |
168 | * in the attitude control as rotation rates. The "ATT" ones are for |
104 | * in the attitude control as rotation rates. The "ATT" ones are for |
169 | * integration to angles. For the same axis, the PID and ATT variables |
105 | * integration to angles. For the same axis, the PID and ATT variables |
170 | * generally have about the same values. There are just some differences |
106 | * generally have about the same values. There are just some differences |
171 | * in filtering, and when a gyro becomes near saturated. |
107 | * in filtering, and when a gyro becomes near saturated. |
172 | * Maybe this distinction is not really necessary. |
108 | * Maybe this distinction is not really necessary. |
173 | */ |
109 | */ |
174 | extern int16_t gyro_PID[2]; |
110 | extern int16_t gyro_PID[2]; |
175 | extern int16_t gyro_ATT[2]; |
111 | extern int16_t gyro_ATT[2]; |
176 | extern int16_t gyroD[2]; |
112 | extern int16_t gyroD[2]; |
177 | extern int16_t yawGyro; |
113 | extern int16_t yawGyro; |
178 | extern volatile uint16_t ADCycleCount; |
114 | extern volatile uint16_t ADCycleCount; |
179 | extern int16_t UBat; |
115 | extern int16_t UBat; |
180 | 116 | ||
181 | // 1:11 voltage divider, 1024 counts per 3V, and result is divided by 3. |
117 | // 1:11 voltage divider, 1024 counts per 3V, and result is divided by 3. |
182 | #define UBAT_AT_5V (int16_t)((5.0 * (1.0/11.0)) * 1024 / (3.0 * 3)) |
118 | #define UBAT_AT_5V (int16_t)((5.0 * (1.0/11.0)) * 1024 / (3.0 * 3)) |
183 | 119 | ||
184 | extern sensorOffset_t gyroOffset; |
120 | extern sensorOffset_t gyroOffset; |
185 | extern sensorOffset_t accOffset; |
121 | extern sensorOffset_t accOffset; |
186 | extern sensorOffset_t gyroAmplifierOffset; |
122 | extern sensorOffset_t gyroAmplifierOffset; |
187 | 123 | ||
188 | /* |
124 | /* |
189 | * This is not really for external use - but the ENC-03 gyro modules needs it. |
125 | * This is not really for external use - but the ENC-03 gyro modules needs it. |
190 | */ |
126 | */ |
191 | //extern volatile int16_t rawGyroSum[3]; |
127 | //extern volatile int16_t rawGyroSum[3]; |
192 | 128 | ||
193 | /* |
129 | /* |
194 | * The acceleration values that this module outputs. They are zero based. |
130 | * The acceleration values that this module outputs. They are zero based. |
195 | */ |
131 | */ |
196 | extern int16_t acc[3]; |
132 | extern int16_t acc[3]; |
197 | extern int16_t filteredAcc[3]; |
133 | extern int16_t filteredAcc[3]; |
198 | // extern volatile int32_t stronglyFilteredAcc[3]; |
134 | // extern volatile int32_t stronglyFilteredAcc[3]; |
199 | 135 | ||
200 | /* |
136 | /* |
201 | * Diagnostics: Gyro noise level because of motor vibrations. The variables |
137 | * Diagnostics: Gyro noise level because of motor vibrations. The variables |
202 | * only really reflect the noise level when the copter stands still but with |
138 | * only really reflect the noise level when the copter stands still but with |
203 | * its motors running. |
139 | * its motors running. |
204 | */ |
140 | */ |
205 | extern uint16_t gyroNoisePeak[3]; |
141 | extern uint16_t gyroNoisePeak[3]; |
206 | extern uint16_t accNoisePeak[3]; |
142 | extern uint16_t accNoisePeak[3]; |
207 | 143 | ||
208 | /* |
144 | /* |
209 | * Air pressure. |
145 | * Air pressure. |
210 | * The sensor has a sensitivity of 45 mV/kPa. |
146 | * The sensor has a sensitivity of 45 mV/kPa. |
211 | * An approximate p(h) formula is = p(h[m])[kPa] = p_0 - 11.95 * 10^-3 * h |
147 | * An approximate p(h) formula is = p(h[m])[kPa] = p_0 - 11.95 * 10^-3 * h |
212 | * p(h[m])[kPa] = 101.3 - 11.95 * 10^-3 * h |
148 | * p(h[m])[kPa] = 101.3 - 11.95 * 10^-3 * h |
213 | * 11.95 * 10^-3 * h = 101.3 - p[kPa] |
149 | * 11.95 * 10^-3 * h = 101.3 - p[kPa] |
214 | * h = (101.3 - p[kPa])/0.01195 |
150 | * h = (101.3 - p[kPa])/0.01195 |
215 | * That is: dV = -45 mV * 11.95 * 10^-3 dh = -0.53775 mV / m. |
151 | * That is: dV = -45 mV * 11.95 * 10^-3 dh = -0.53775 mV / m. |
216 | * That is, with 38.02 * 1.024 / 3 steps per mV: -7 steps / m |
152 | * That is, with 38.02 * 1.024 / 3 steps per mV: -7 steps / m |
217 | 153 | ||
218 | Display pressures |
154 | Display pressures |
219 | 4165 mV-->1084.7 |
155 | 4165 mV-->1084.7 |
220 | 4090 mV-->1602.4 517.7 |
156 | 4090 mV-->1602.4 517.7 |
221 | 3877 mV-->3107.8 1503.4 |
157 | 3877 mV-->3107.8 1503.4 |
222 | 158 | ||
223 | 4165 mV-->1419.1 |
159 | 4165 mV-->1419.1 |
224 | 3503 mV-->208.1 |
160 | 3503 mV-->208.1 |
225 | Diff.: 1211.0 |
161 | Diff.: 1211.0 |
226 | 162 | ||
227 | Calculated Vout = 5V(.009P-0.095) --> 5V .009P = Vout + 5V 0.095 --> P = (Vout + 5V 0.095)/(5V 0.009) |
163 | Calculated Vout = 5V(.009P-0.095) --> 5V .009P = Vout + 5V 0.095 --> P = (Vout + 5V 0.095)/(5V 0.009) |
228 | 4165 mV = 5V(0.009P-0.095) P = 103.11 kPa h = -151.4m |
164 | 4165 mV = 5V(0.009P-0.095) P = 103.11 kPa h = -151.4m |
229 | 4090 mV = 5V(0.009P-0.095) P = 101.44 kPa h = -11.7m 139.7m |
165 | 4090 mV = 5V(0.009P-0.095) P = 101.44 kPa h = -11.7m 139.7m |
230 | 3877 mV = 5V(0.009P-0.095) P = 96.7 kPa h = 385m 396.7m |
166 | 3877 mV = 5V(0.009P-0.095) P = 96.7 kPa h = 385m 396.7m |
231 | 167 | ||
232 | 4165 mV = 5V(0.009P-0.095) P = 103.11 kPa h = -151.4m |
168 | 4165 mV = 5V(0.009P-0.095) P = 103.11 kPa h = -151.4m |
233 | 3503 mV = 5V(0.009P-0.095) P = 88.4 kPa h = 384m Diff: 1079.5m |
169 | 3503 mV = 5V(0.009P-0.095) P = 88.4 kPa h = 384m Diff: 1079.5m |
234 | Pressure at sea level: 101.3 kPa. voltage: 5V * (0.009P-0.095) = 4.0835V |
170 | Pressure at sea level: 101.3 kPa. voltage: 5V * (0.009P-0.095) = 4.0835V |
235 | This is OCR2 = 143.15 at 1.5V in --> simple pressure = |
171 | This is OCR2 = 143.15 at 1.5V in --> simple pressure = |
236 | */ |
172 | */ |
237 | 173 | ||
238 | #define AIRPRESSURE_OVERSAMPLING 14 |
174 | #define AIRPRESSURE_OVERSAMPLING 14 |
239 | #define AIRPRESSURE_FILTER 8 |
175 | #define AIRPRESSURE_FILTER 8 |
240 | // Minimum A/D value before a range change is performed. |
176 | // Minimum A/D value before a range change is performed. |
241 | #define MIN_RAWPRESSURE (200 * 2) |
177 | #define MIN_RAWPRESSURE (200 * 2) |
242 | // Maximum A/D value before a range change is performed. |
178 | // Maximum A/D value before a range change is performed. |
243 | #define MAX_RAWPRESSURE (1023 * 2 - MIN_RAWPRESSURE) |
179 | #define MAX_RAWPRESSURE (1023 * 2 - MIN_RAWPRESSURE) |
244 | 180 | ||
245 | #define MIN_RANGES_EXTRAPOLATION 15 |
181 | #define MIN_RANGES_EXTRAPOLATION 15 |
246 | #define MAX_RANGES_EXTRAPOLATION 240 |
182 | #define MAX_RANGES_EXTRAPOLATION 240 |
247 | 183 | ||
248 | #define PRESSURE_EXTRAPOLATION_COEFF 25L |
184 | #define PRESSURE_EXTRAPOLATION_COEFF 25L |
249 | #define AUTORANGE_WAIT_FACTOR 1 |
185 | #define AUTORANGE_WAIT_FACTOR 1 |
250 | 186 | ||
251 | #define ABS_ALTITUDE_OFFSET 108205 |
187 | #define ABS_ALTITUDE_OFFSET 108205 |
252 | 188 | ||
253 | extern uint16_t simpleAirPressure; |
189 | extern uint16_t simpleAirPressure; |
254 | /* |
190 | /* |
255 | * At saturation, the filteredAirPressure may actually be (simulated) negative. |
191 | * At saturation, the filteredAirPressure may actually be (simulated) negative. |
256 | */ |
192 | */ |
257 | extern int32_t filteredAirPressure; |
193 | extern int32_t filteredAirPressure; |
258 | 194 | ||
259 | /* |
195 | /* |
260 | * Flag: Interrupt handler has done all A/D conversion and processing. |
196 | * Flag: Interrupt handler has done all A/D conversion and processing. |
261 | */ |
197 | */ |
262 | extern volatile uint8_t analogDataReady; |
198 | extern volatile uint8_t analogDataReady; |
263 | 199 | ||
264 | void analog_init(void); |
200 | void analog_init(void); |
265 | 201 | ||
266 | /* |
202 | /* |
267 | * This is really only for use for the ENC-03 code module, which needs to get the raw value |
203 | * This is really only for use for the ENC-03 code module, which needs to get the raw value |
268 | * for its calibration. The raw value should not be used for anything else. |
204 | * for its calibration. The raw value should not be used for anything else. |
269 | */ |
205 | */ |
270 | uint16_t rawGyroValue(uint8_t axis); |
206 | uint16_t rawGyroValue(uint8_t axis); |
271 | 207 | ||
272 | /* |
208 | /* |
273 | * Start the conversion cycle. It will stop automatically. |
209 | * Start the conversion cycle. It will stop automatically. |
274 | */ |
210 | */ |
275 | void startAnalogConversionCycle(void); |
211 | void startAnalogConversionCycle(void); |
276 | 212 | ||
277 | /* |
213 | /* |
278 | * Process the sensor data to update the exported variables. Must be called after each measurement cycle and before the data is used. |
214 | * Process the sensor data to update the exported variables. Must be called after each measurement cycle and before the data is used. |
279 | */ |
215 | */ |
280 | void analog_update(void); |
216 | void analog_update(void); |
281 | 217 | ||
282 | /* |
218 | /* |
283 | * Read gyro and acc.meter calibration from EEPROM. |
219 | * Read gyro and acc.meter calibration from EEPROM. |
284 | */ |
220 | */ |
285 | void analog_setNeutral(void); |
221 | void analog_setNeutral(void); |
286 | 222 | ||
287 | /* |
223 | /* |
288 | * Zero-offset gyros and write the calibration data to EEPROM. |
224 | * Zero-offset gyros and write the calibration data to EEPROM. |
289 | */ |
225 | */ |
290 | void analog_calibrateGyros(void); |
226 | void analog_calibrateGyros(void); |
291 | 227 | ||
292 | /* |
228 | /* |
293 | * Zero-offset accelerometers and write the calibration data to EEPROM. |
229 | * Zero-offset accelerometers and write the calibration data to EEPROM. |
294 | */ |
230 | */ |
295 | void analog_calibrateAcc(void); |
231 | void analog_calibrateAcc(void); |
296 | 232 | ||
297 | 233 | ||
298 | void analog_setGround(void); |
234 | void analog_setGround(void); |
299 | 235 | ||
300 | int32_t analog_getHeight(void); |
236 | int32_t analog_getHeight(void); |
301 | int16_t analog_getDHeight(void); |
237 | int16_t analog_getDHeight(void); |
302 | 238 | ||
303 | #endif //_ANALOG_H |
239 | #endif //_ANALOG_H |
304 | 240 |