Go to most recent revision | Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
1 | ingob | 1 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
2 | // + Copyright (c) 04.2007 Holger Buss |
||
3 | // + only for non-profit use |
||
4 | // + www.MikroKopter.com |
||
5 | // + see the File "License.txt" for further Informations |
||
6 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
||
7 | |||
8 | #include "main.h" |
||
9 | volatile int Aktuell_Nick,Aktuell_Roll,Aktuell_Gier,Aktuell_ax, Aktuell_ay,Aktuell_az, UBat = 100; |
||
1166 | hbuss | 10 | volatile int AdWertNickFilter = 0, AdWertRollFilter = 0, AdWertGierFilter = 0; |
11 | volatile int HiResNick = 2500, HiResRoll = 2500; |
||
380 | hbuss | 12 | volatile int AdWertNick = 0, AdWertRoll = 0, AdWertGier = 0; |
13 | volatile int AdWertAccRoll = 0,AdWertAccNick = 0,AdWertAccHoch = 0; |
||
1166 | hbuss | 14 | volatile char messanzahl_AccHoch = 0; |
1 | ingob | 15 | volatile long Luftdruck = 32000; |
16 | volatile int StartLuftdruck; |
||
17 | volatile unsigned int MessLuftdruck = 1023; |
||
18 | unsigned char DruckOffsetSetting; |
||
1036 | hbuss | 19 | signed char ExpandBaro = 0; |
1 | ingob | 20 | volatile int HoeheD = 0; |
21 | volatile char messanzahl_Druck; |
||
22 | volatile int tmpLuftdruck; |
||
23 | volatile unsigned int ZaehlMessungen = 0; |
||
918 | hbuss | 24 | unsigned char AnalogOffsetNick = 115,AnalogOffsetRoll = 115,AnalogOffsetGier = 115; |
25 | unsigned char GyroDefektN = 0,GyroDefektR = 0,GyroDefektG = 0; |
||
1155 | hbuss | 26 | unsigned char AdReady = 1; |
1 | ingob | 27 | //####################################################################################### |
28 | // |
||
29 | void ADC_Init(void) |
||
30 | //####################################################################################### |
||
31 | { |
||
32 | ADMUX = 0;//Referenz ist extern |
||
1155 | hbuss | 33 | ANALOG_ON; |
1 | ingob | 34 | } |
35 | |||
36 | void SucheLuftruckOffset(void) |
||
37 | { |
||
38 | unsigned int off; |
||
173 | holgerb | 39 | off = eeprom_read_byte(&EEPromArray[EEPROM_ADR_LAST_OFFSET]); |
40 | if(off > 20) off -= 10; |
||
41 | OCR0A = off; |
||
1036 | hbuss | 42 | ExpandBaro = 0; |
380 | hbuss | 43 | Delay_ms_Mess(100); |
173 | holgerb | 44 | if(MessLuftdruck < 850) off = 0; |
45 | for(; off < 250;off++) |
||
1 | ingob | 46 | { |
47 | OCR0A = off; |
||
380 | hbuss | 48 | Delay_ms_Mess(50); |
1 | ingob | 49 | printf("."); |
1036 | hbuss | 50 | if(MessLuftdruck < 850) break; |
1 | ingob | 51 | } |
173 | holgerb | 52 | eeprom_write_byte(&EEPromArray[EEPROM_ADR_LAST_OFFSET], off); |
53 | DruckOffsetSetting = off; |
||
380 | hbuss | 54 | Delay_ms_Mess(300); |
1 | ingob | 55 | } |
56 | |||
918 | hbuss | 57 | void SucheGyroOffset(void) |
58 | { |
||
59 | unsigned char i, ready = 0; |
||
60 | GyroDefektN = 0; GyroDefektR = 0; GyroDefektG = 0; |
||
61 | for(i=140; i != 0; i--) |
||
62 | { |
||
921 | hbuss | 63 | if(ready == 3 && i > 10) i = 9; |
918 | hbuss | 64 | ready = 0; |
65 | if(AdWertNick < 1020) AnalogOffsetNick--; else if(AdWertNick > 1030) AnalogOffsetNick++; else ready++; |
||
66 | if(AdWertRoll < 1020) AnalogOffsetRoll--; else if(AdWertRoll > 1030) AnalogOffsetRoll++; else ready++; |
||
67 | if(AdWertGier < 1020) AnalogOffsetGier--; else if(AdWertGier > 1030) AnalogOffsetGier++; else ready++; |
||
68 | twi_state = 8; |
||
69 | i2c_start(); |
||
70 | if(AnalogOffsetNick < 10) { GyroDefektN = 1; AnalogOffsetNick = 10;}; if(AnalogOffsetNick > 245) { GyroDefektN = 1; AnalogOffsetNick = 245;}; |
||
71 | if(AnalogOffsetRoll < 10) { GyroDefektR = 1; AnalogOffsetRoll = 10;}; if(AnalogOffsetRoll > 245) { GyroDefektR = 1; AnalogOffsetRoll = 245;}; |
||
72 | if(AnalogOffsetGier < 10) { GyroDefektG = 1; AnalogOffsetGier = 10;}; if(AnalogOffsetGier > 245) { GyroDefektG = 1; AnalogOffsetGier = 245;}; |
||
73 | while(twi_state); |
||
74 | messanzahl_Druck = 0; |
||
75 | ANALOG_ON; |
||
76 | while(messanzahl_Druck == 0); |
||
77 | if(i<10) Delay_ms_Mess(10); |
||
78 | } |
||
921 | hbuss | 79 | Delay_ms_Mess(70); |
918 | hbuss | 80 | } |
1166 | hbuss | 81 | /* |
82 | |||
83 | 1 r |
||
84 | 2 g |
||
85 | 3 y |
||
86 | 4 n |
||
87 | 5 r |
||
88 | 6 z |
||
89 | 7 l |
||
90 | 8 n |
||
91 | 9 r |
||
92 | 10 x |
||
93 | 11 g |
||
94 | 12 n |
||
95 | 13 r |
||
96 | 14 u |
||
97 | 15 y |
||
98 | 16 n |
||
99 | 17 r |
||
100 | 18 x |
||
101 | 19 n |
||
102 | 20 r |
||
103 | 21 g |
||
104 | 22 y |
||
105 | 4 n |
||
106 | 5 r |
||
107 | 6 z |
||
108 | 7 l |
||
109 | 8 n |
||
110 | 9 r |
||
111 | 10 x |
||
112 | 11 g |
||
113 | 12 n |
||
114 | 13 r |
||
115 | 14 u |
||
116 | 15 y |
||
117 | 16 n |
||
118 | 17 r |
||
119 | 18 x |
||
120 | */ |
||
121 | #define FILTER 3 |
||
1 | ingob | 122 | |
123 | //####################################################################################### |
||
124 | // |
||
125 | SIGNAL(SIG_ADC) |
||
126 | //####################################################################################### |
||
127 | { |
||
128 | static unsigned char kanal=0,state = 0; |
||
1166 | hbuss | 129 | static signed int gier1, roll1, nick1; |
130 | static signed long nick_filter, roll_filter; |
||
131 | static signed int accy, accx; |
||
132 | // ANALOG_OFF; |
||
133 | switch(state++) |
||
134 | { |
||
135 | case 0: |
||
136 | J4High; |
||
137 | nick1 = ADC; |
||
138 | kanal = AD_ROLL; |
||
139 | break; |
||
140 | case 1: |
||
141 | roll1 = ADC; |
||
142 | kanal = AD_GIER; |
||
143 | break; |
||
144 | case 2: |
||
145 | gier1 = ADC; |
||
146 | kanal = AD_ACC_Y; |
||
147 | break; |
||
148 | case 3: |
||
149 | J5High; |
||
150 | Aktuell_ay = NeutralAccY - ADC; |
||
151 | accy = Aktuell_ay; |
||
152 | kanal = AD_NICK; |
||
153 | break; |
||
154 | case 4: |
||
155 | J4High; |
||
156 | nick1 += ADC; |
||
157 | kanal = AD_ROLL; |
||
158 | break; |
||
159 | case 5: |
||
160 | roll1 += ADC; |
||
161 | kanal = AD_ACC_Z; |
||
162 | break; |
||
163 | case 6: |
||
164 | AdWertAccHoch = (signed int) ADC - NeutralAccZ; |
||
165 | if(AdWertAccHoch > 1) |
||
166 | { |
||
167 | if(NeutralAccZ < 750) |
||
168 | { |
||
169 | NeutralAccZ += 0.02; |
||
170 | if(modell_fliegt < 500) NeutralAccZ += 0.1; |
||
171 | } |
||
172 | } |
||
173 | else if(AdWertAccHoch < -1) |
||
174 | { |
||
175 | if(NeutralAccZ > 550) |
||
176 | { |
||
177 | NeutralAccZ-= 0.02; |
||
178 | if(modell_fliegt < 500) NeutralAccZ -= 0.1; |
||
179 | } |
||
180 | } |
||
181 | messanzahl_AccHoch = 1; |
||
182 | Aktuell_az = ADC; |
||
183 | Mess_Integral_Hoch += AdWertAccHoch; // Integrieren |
||
184 | Mess_Integral_Hoch -= Mess_Integral_Hoch / 1024; // dämfen |
||
185 | kanal = AD_NICK; |
||
186 | break; |
||
187 | case 7: |
||
188 | J4High; |
||
189 | nick1 += ADC; |
||
190 | kanal = AD_ROLL; |
||
191 | break; |
||
192 | case 8: |
||
193 | roll1 += ADC; |
||
194 | kanal = AD_ACC_X; |
||
195 | break; |
||
196 | case 9: |
||
197 | Aktuell_ax = ADC - NeutralAccX; |
||
198 | accx = Aktuell_ax; |
||
199 | kanal = AD_GIER; |
||
200 | break; |
||
201 | case 10: |
||
202 | gier1 += ADC; |
||
203 | kanal = AD_NICK; |
||
204 | break; |
||
205 | case 11: |
||
206 | J4High; |
||
207 | nick1 += ADC; |
||
208 | kanal = AD_ROLL; |
||
209 | break; |
||
210 | case 12: |
||
211 | roll1 += ADC; |
||
212 | kanal = AD_UBAT; |
||
213 | break; |
||
214 | case 13: |
||
215 | UBat = (3 * UBat + ADC / 3) / 4;//(UBat + ((ADC * 39) / 256) + 19) / 2; |
||
216 | kanal = AD_ACC_Y; |
||
217 | break; |
||
218 | case 14: |
||
219 | J5High; |
||
220 | Aktuell_ay = NeutralAccY - ADC; |
||
221 | accy += Aktuell_ay; |
||
222 | kanal = AD_NICK; |
||
223 | break; |
||
224 | case 15: |
||
225 | J4High; |
||
226 | nick1 += ADC; |
||
227 | kanal = AD_ROLL; |
||
228 | break; |
||
229 | case 16: |
||
230 | roll1 += ADC; |
||
231 | kanal = AD_ACC_X; |
||
232 | break; |
||
233 | case 17: |
||
234 | Aktuell_ax = ADC - NeutralAccX; |
||
235 | accx += Aktuell_ax; |
||
236 | kanal = AD_NICK; |
||
237 | break; |
||
238 | case 18: |
||
239 | J4High; |
||
240 | nick1 += ADC; |
||
241 | kanal = AD_ROLL; |
||
242 | break; |
||
243 | case 19: |
||
244 | roll1 += ADC; |
||
245 | kanal = AD_GIER; |
||
246 | break; |
||
247 | case 20: |
||
248 | gier1 += ADC; |
||
249 | kanal = AD_ACC_Y; |
||
250 | break; |
||
251 | case 21: |
||
252 | J5High; |
||
253 | Aktuell_ay = NeutralAccY - ADC; |
||
254 | accy += Aktuell_ay; |
||
255 | kanal = AD_NICK; |
||
256 | break; |
||
257 | case 22: |
||
258 | J4High; |
||
259 | nick1 += ADC; |
||
260 | kanal = AD_ROLL; |
||
261 | break; |
||
262 | case 23: |
||
263 | roll1 += ADC; |
||
264 | kanal = AD_DRUCK; |
||
265 | break; |
||
266 | case 24: |
||
267 | tmpLuftdruck += ADC; |
||
268 | |||
269 | if(++messanzahl_Druck >= 5) |
||
270 | { |
||
271 | MessLuftdruck = ADC; |
||
272 | messanzahl_Druck = 0; |
||
273 | HoeheD = (7 * HoeheD + (int) Parameter_Luftdruck_D * (int)(255 * ExpandBaro + StartLuftdruck - tmpLuftdruck - HoehenWert))/8; // D-Anteil = neuerWert - AlterWert |
||
274 | Luftdruck = (tmpLuftdruck + 3 * Luftdruck) / 4; |
||
275 | HoehenWert = 255 * ExpandBaro + StartLuftdruck - Luftdruck; |
||
276 | tmpLuftdruck = 0; |
||
277 | } |
||
278 | kanal = AD_NICK; |
||
279 | break; |
||
280 | case 25: |
||
281 | J4High; |
||
282 | nick1 += ADC; |
||
283 | kanal = AD_ROLL; |
||
284 | break; |
||
285 | case 26: |
||
286 | roll1 += ADC; |
||
287 | kanal = AD_ACC_X; |
||
288 | break; |
||
289 | case 27: |
||
290 | Aktuell_ax = ADC - NeutralAccX; |
||
291 | accx += Aktuell_ax; |
||
292 | kanal = AD_GIER; |
||
293 | break; |
||
294 | case 28: |
||
295 | if(PlatinenVersion == 10) AdWertGier = (ADC + gier1 + 2) / 4; |
||
296 | else |
||
297 | if(PlatinenVersion == 20) AdWertGier = 2047 - (ADC + gier1 + 1) / 2; |
||
298 | else AdWertGier = (ADC + gier1 + 1) / 2; |
||
299 | kanal = AD_NICK; |
||
300 | break; |
||
301 | case 29: |
||
302 | J4High; |
||
303 | nick1 += ADC; |
||
304 | kanal = AD_ROLL; |
||
305 | break; |
||
306 | case 30: |
||
307 | roll1 += ADC; |
||
308 | kanal = AD_ACC_Y; |
||
309 | break; |
||
310 | case 31: |
||
311 | J5High; |
||
312 | Aktuell_ay = NeutralAccY - ADC; |
||
313 | AdWertAccRoll = (Aktuell_ay + accy); |
||
314 | kanal = AD_NICK; |
||
315 | break; |
||
316 | case 32: |
||
317 | J4High; |
||
318 | AdWertNick = (ADC + nick1 + 3) / 5; |
||
319 | nick_filter = (long) (1 * (long) nick_filter + 4 * (long)(ADC + nick1) + 1) / 2; |
||
320 | if(PlatinenVersion == 10) { AdWertNick /= 2;nick_filter /=2;} |
||
321 | HiResNick = nick_filter - 20 * AdNeutralNick; |
||
322 | AdWertNickFilter = (long)(3L * (long)AdWertNickFilter + HiResNick + 2) / 4; |
||
323 | DebugOut.Analog[21] = AdWertNickFilter / 4; |
||
324 | kanal = AD_ROLL; |
||
325 | break; |
||
326 | case 33: |
||
327 | AdWertRoll = (ADC + roll1 + 3) / 5; |
||
328 | roll_filter = (long)(1 * (long)roll_filter + 4 * (long)(ADC + roll1) + 1) / 2; |
||
329 | if(PlatinenVersion == 10) { AdWertRoll /= 2;roll_filter /=2;} |
||
330 | HiResRoll = roll_filter - 20 * AdNeutralRoll; |
||
331 | AdWertRollFilter = (long)(3L * (long)AdWertRollFilter + HiResRoll + 2) / 4; |
||
332 | DebugOut.Analog[22] = AdWertRollFilter / 4; |
||
333 | kanal = AD_ACC_X; |
||
334 | break; |
||
335 | case 34: |
||
336 | Aktuell_ax = ADC - NeutralAccX; |
||
337 | AdWertAccNick = (Aktuell_ax + accx); |
||
338 | kanal = AD_NICK; |
||
339 | state = 0; |
||
340 | AdReady = 1; |
||
341 | ZaehlMessungen++; |
||
342 | break; |
||
343 | default: |
||
344 | kanal = 0; |
||
345 | state = 0; |
||
346 | break; |
||
347 | } |
||
348 | ADMUX = kanal; |
||
349 | if(state != 0) ANALOG_ON; |
||
350 | J4Low; |
||
351 | J5Low; |
||
352 | } |
||
353 | |||
354 | /* |
||
355 | //####################################################################################### |
||
356 | // |
||
357 | SIGNAL(SIG_ADC) |
||
358 | //####################################################################################### |
||
359 | { |
||
360 | static unsigned char kanal=0,state = 0; |
||
361 | static signed int gier1, roll1, nick1, nick_filter, roll_filter; |
||
362 | static signed int accy, accx; |
||
363 | // ANALOG_OFF; |
||
364 | switch(state++) |
||
365 | { |
||
366 | case 0: |
||
367 | J4High; |
||
368 | nick1 = ADC; |
||
369 | kanal = AD_ROLL; |
||
370 | break; |
||
371 | case 1: |
||
372 | roll1 = ADC; |
||
373 | kanal = AD_GIER; |
||
374 | break; |
||
375 | case 2: |
||
376 | gier1 = ADC; |
||
377 | kanal = AD_ACC_Y; |
||
378 | break; |
||
379 | case 3: |
||
380 | Aktuell_ay = NeutralAccY - ADC; |
||
381 | accy = Aktuell_ay; |
||
382 | kanal = AD_NICK; |
||
383 | break; |
||
384 | case 4: |
||
385 | J4High; |
||
386 | nick1 += ADC; |
||
387 | kanal = AD_ROLL; |
||
388 | break; |
||
389 | case 5: |
||
390 | roll1 += ADC; |
||
391 | kanal = AD_ACC_Z; |
||
392 | break; |
||
393 | case 6: |
||
394 | AdWertAccHoch = (signed int) ADC - NeutralAccZ; |
||
395 | if(AdWertAccHoch > 1) |
||
396 | { |
||
397 | if(NeutralAccZ < 750) |
||
398 | { |
||
399 | NeutralAccZ += 0.02; |
||
400 | if(modell_fliegt < 500) NeutralAccZ += 0.1; |
||
401 | } |
||
402 | } |
||
403 | else if(AdWertAccHoch < -1) |
||
404 | { |
||
405 | if(NeutralAccZ > 550) |
||
406 | { |
||
407 | NeutralAccZ-= 0.02; |
||
408 | if(modell_fliegt < 500) NeutralAccZ -= 0.1; |
||
409 | } |
||
410 | } |
||
411 | messanzahl_AccHoch = 1; |
||
412 | Aktuell_az = ADC; |
||
413 | Mess_Integral_Hoch += AdWertAccHoch; // Integrieren |
||
414 | Mess_Integral_Hoch -= Mess_Integral_Hoch / 1024; // dämfen |
||
415 | kanal = AD_DRUCK; |
||
416 | break; |
||
417 | case 7: |
||
418 | tmpLuftdruck += ADC; |
||
419 | |||
420 | if(++messanzahl_Druck >= 5) |
||
421 | { |
||
422 | MessLuftdruck = ADC; |
||
423 | messanzahl_Druck = 0; |
||
424 | HoeheD = (7 * HoeheD + (int) Parameter_Luftdruck_D * (int)(255 * ExpandBaro + StartLuftdruck - tmpLuftdruck - HoehenWert))/8; // D-Anteil = neuerWert - AlterWert |
||
425 | Luftdruck = (tmpLuftdruck + 3 * Luftdruck) / 4; |
||
426 | HoehenWert = 255 * ExpandBaro + StartLuftdruck - Luftdruck; |
||
427 | tmpLuftdruck = 0; |
||
428 | } |
||
429 | kanal = AD_NICK; |
||
430 | break; |
||
431 | case 8: |
||
432 | J4High; |
||
433 | nick1 += ADC; |
||
434 | kanal = AD_ROLL; |
||
435 | break; |
||
436 | case 9: |
||
437 | roll1 += ADC; |
||
438 | kanal = AD_ACC_X; |
||
439 | break; |
||
440 | case 10: |
||
441 | Aktuell_ax = ADC - NeutralAccX; |
||
442 | accx = Aktuell_ax; |
||
443 | kanal = AD_GIER; |
||
444 | break; |
||
445 | case 11: |
||
446 | if(PlatinenVersion == 10) AdWertGier = (ADC + gier1) / 2; |
||
447 | else |
||
448 | if(PlatinenVersion == 20) AdWertGier = 2047 - (ADC + gier1); |
||
449 | else AdWertGier = (ADC + gier1); |
||
450 | kanal = AD_NICK; |
||
451 | break; |
||
452 | case 12: |
||
453 | J4High; |
||
454 | nick1 += ADC; |
||
455 | kanal = AD_ROLL; |
||
456 | break; |
||
457 | case 13: |
||
458 | roll1 += ADC; |
||
459 | kanal = AD_UBAT; |
||
460 | break; |
||
461 | case 14: |
||
462 | UBat = (3 * UBat + ADC / 3) / 4;//(UBat + ((ADC * 39) / 256) + 19) / 2; |
||
463 | kanal = AD_ACC_Y; |
||
464 | break; |
||
465 | case 15: |
||
466 | Aktuell_ay = NeutralAccY - ADC; |
||
467 | AdWertAccRoll = (Aktuell_ay + accy); |
||
468 | kanal = AD_NICK; |
||
469 | break; |
||
470 | case 16: |
||
471 | J4High; |
||
472 | // if(PlatinenVersion == 10) AdWertNick = (ADC + nick1) / 5; |
||
473 | // else AdWertNick = (5 * AdWertNick + 2*(ADC + nick1)) / 10; |
||
474 | AdWertNick = 2*(ADC + nick1) / 5; |
||
475 | nick_filter = (2 * nick_filter + 2 * (ADC + nick1)) / 3; |
||
476 | HiResNick = nick_filter - 5 * AdNeutralNick; |
||
477 | AdWertNickFilter = (long)(3L * (long)AdWertNickFilter + 4 * HiResNick) / 4; |
||
478 | DebugOut.Analog[21] = AdWertNickFilter / 4; |
||
479 | kanal = AD_ROLL; |
||
480 | break; |
||
481 | case 17: |
||
482 | // if(PlatinenVersion == 10) AdWertRoll = (ADC + roll1) / 5; |
||
483 | // else AdWertRoll = (5 * AdWertRoll + 2*(ADC + roll1)) / 10; |
||
484 | AdWertRoll = 2*(ADC + roll1) / 5; |
||
485 | roll_filter = (2 * roll_filter + 2 * (ADC + roll1)) / 3; |
||
486 | HiResRoll = roll_filter - 5 * AdNeutralRoll; |
||
487 | AdWertRollFilter = (long)(3 * (long)AdWertRollFilter + 4 * HiResRoll) / 4; |
||
488 | DebugOut.Analog[22] = AdWertRollFilter / 4; |
||
489 | kanal = AD_ACC_X; |
||
490 | break; |
||
491 | case 18: |
||
492 | Aktuell_ax = ADC - NeutralAccX; |
||
493 | AdWertAccNick = (Aktuell_ax + accx); |
||
494 | kanal = AD_NICK; |
||
495 | state = 0; |
||
496 | AdReady = 1; |
||
497 | ZaehlMessungen++; |
||
498 | J5High; |
||
499 | break; |
||
500 | default: |
||
501 | kanal = 0; |
||
502 | state = 0; |
||
503 | break; |
||
504 | } |
||
505 | ADMUX = kanal; |
||
506 | if(state != 0) ANALOG_ON; |
||
507 | J4Low; |
||
508 | J5Low; |
||
509 | } |
||
510 | */ |
||
511 | |||
512 | /* |
||
513 | //####################################################################################### |
||
514 | // |
||
515 | SIGNAL(SIG_ADC) |
||
516 | //####################################################################################### |
||
517 | { |
||
518 | static unsigned char kanal=0,state = 0; |
||
1155 | hbuss | 519 | static unsigned int gier1, roll1, nick1, accy, accx; |
1 | ingob | 520 | ANALOG_OFF; |
521 | switch(state++) |
||
522 | { |
||
523 | case 0: |
||
401 | hbuss | 524 | gier1 = ADC; |
1155 | hbuss | 525 | kanal = AD_ROLL; |
1 | ingob | 526 | ZaehlMessungen++; |
527 | break; |
||
528 | case 1: |
||
401 | hbuss | 529 | roll1 = ADC; |
1155 | hbuss | 530 | kanal = AD_NICK; |
1 | ingob | 531 | break; |
532 | case 2: |
||
401 | hbuss | 533 | nick1 = ADC; |
1155 | hbuss | 534 | kanal = AD_ACC_Y; |
1 | ingob | 535 | break; |
536 | case 3: |
||
1155 | hbuss | 537 | Aktuell_ay = NeutralAccY - ADC; |
538 | accy = Aktuell_ay; |
||
539 | kanal = AD_ACC_X; |
||
1 | ingob | 540 | break; |
541 | case 4: |
||
1155 | hbuss | 542 | Aktuell_ax = ADC - NeutralAccX; |
543 | accx = Aktuell_ax; |
||
544 | kanal = AD_GIER; |
||
1 | ingob | 545 | break; |
546 | case 5: |
||
1155 | hbuss | 547 | gier1 += ADC; |
548 | kanal = AD_ROLL; |
||
1 | ingob | 549 | break; |
550 | case 6: |
||
1155 | hbuss | 551 | roll1 += ADC; |
552 | kanal = AD_NICK; |
||
401 | hbuss | 553 | break; |
554 | case 7: |
||
1155 | hbuss | 555 | nick1 += ADC; |
556 | kanal = AD_UBAT; |
||
401 | hbuss | 557 | break; |
558 | case 8: |
||
1155 | hbuss | 559 | UBat = (3 * UBat + ADC / 3) / 4;//(UBat + ((ADC * 39) / 256) + 19) / 2; |
560 | kanal = AD_ACC_Z; |
||
401 | hbuss | 561 | break; |
562 | case 9: |
||
380 | hbuss | 563 | AdWertAccHoch = (signed int) ADC - NeutralAccZ; |
564 | if(AdWertAccHoch > 1) |
||
1 | ingob | 565 | { |
871 | hbuss | 566 | if(NeutralAccZ < 750) |
567 | { |
||
568 | NeutralAccZ += 0.02; |
||
569 | if(modell_fliegt < 500) NeutralAccZ += 0.1; |
||
570 | } |
||
1 | ingob | 571 | } |
380 | hbuss | 572 | else if(AdWertAccHoch < -1) |
1 | ingob | 573 | { |
871 | hbuss | 574 | if(NeutralAccZ > 550) |
575 | { |
||
576 | NeutralAccZ-= 0.02; |
||
577 | if(modell_fliegt < 500) NeutralAccZ -= 0.1; |
||
578 | } |
||
1 | ingob | 579 | } |
580 | messanzahl_AccHoch = 1; |
||
581 | Aktuell_az = ADC; |
||
380 | hbuss | 582 | Mess_Integral_Hoch += AdWertAccHoch; // Integrieren |
1 | ingob | 583 | Mess_Integral_Hoch -= Mess_Integral_Hoch / 1024; // dämfen |
1155 | hbuss | 584 | kanal = AD_GIER; |
1 | ingob | 585 | break; |
401 | hbuss | 586 | case 10: |
1155 | hbuss | 587 | gier1 += ADC; |
588 | kanal = AD_ROLL; |
||
589 | break; |
||
590 | case 11: |
||
591 | roll1 += ADC; |
||
592 | kanal = AD_NICK; |
||
593 | break; |
||
594 | case 12: |
||
595 | nick1 += ADC; |
||
596 | kanal = AD_DRUCK; |
||
597 | break; |
||
598 | case 13: |
||
1 | ingob | 599 | tmpLuftdruck += ADC; |
600 | if(++messanzahl_Druck >= 5) |
||
601 | { |
||
602 | MessLuftdruck = ADC; |
||
603 | messanzahl_Druck = 0; |
||
1036 | hbuss | 604 | HoeheD = (7 * HoeheD + (int) Parameter_Luftdruck_D * (int)(255 * ExpandBaro + StartLuftdruck - tmpLuftdruck - HoehenWert))/8; // D-Anteil = neuerWert - AlterWert |
1 | ingob | 605 | Luftdruck = (tmpLuftdruck + 3 * Luftdruck) / 4; |
1036 | hbuss | 606 | HoehenWert = 255 * ExpandBaro + StartLuftdruck - Luftdruck; |
1 | ingob | 607 | tmpLuftdruck = 0; |
608 | } |
||
1155 | hbuss | 609 | kanal = AD_ACC_Y; |
610 | break; |
||
611 | case 14: |
||
612 | Aktuell_ay = NeutralAccY - ADC; |
||
613 | AdWertAccRoll = (Aktuell_ay + accy); |
||
614 | kanal = AD_ACC_X; |
||
615 | break; |
||
616 | case 15: |
||
617 | Aktuell_ax = ADC - NeutralAccX; |
||
618 | AdWertAccNick = (Aktuell_ax + accx); |
||
619 | kanal = AD_GIER; |
||
620 | break; |
||
621 | case 16: |
||
622 | if(PlatinenVersion == 10) AdWertGier = (ADC + gier1) / 4; |
||
623 | else |
||
624 | if(PlatinenVersion == 20) AdWertGier = 2047 - (ADC + gier1)/2; |
||
625 | else AdWertGier = (ADC + gier1) / 2; |
||
626 | kanal = AD_ROLL; |
||
627 | break; |
||
628 | case 17: |
||
629 | if(PlatinenVersion == 10) AdWertRoll = (ADC + roll1) / 4; |
||
630 | else AdWertRoll = (ADC + roll1) / 2; |
||
631 | kanal = AD_NICK; |
||
632 | break; |
||
633 | case 18: |
||
634 | if(PlatinenVersion == 10) AdWertNick = (ADC + nick1) / 4; |
||
635 | else AdWertNick = (ADC + nick1) / 2; |
||
636 | kanal = AD_GIER; |
||
1 | ingob | 637 | state = 0; |
1155 | hbuss | 638 | AdReady = 1; |
1 | ingob | 639 | break; |
640 | default: |
||
641 | kanal = 0; |
||
642 | state = 0; |
||
643 | break; |
||
644 | } |
||
645 | ADMUX = kanal; |
||
380 | hbuss | 646 | if(state != 0) ANALOG_ON; |
1 | ingob | 647 | } |
1166 | hbuss | 648 | */ |
649 | |||
650 | |||
651 | |||
652 | |||
653 | |||
654 | |||
655 | |||
656 | |||
657 | |||
658 | |||
659 |