Rev 1226 | Details | Compare with Previous | 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; |
||
1168 | hbuss | 26 | volatile 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; |
||
1219 | hbuss | 60 | int timeout; |
918 | hbuss | 61 | GyroDefektN = 0; GyroDefektR = 0; GyroDefektG = 0; |
1219 | hbuss | 62 | timeout = SetDelay(2000); |
918 | hbuss | 63 | for(i=140; i != 0; i--) |
64 | { |
||
921 | hbuss | 65 | if(ready == 3 && i > 10) i = 9; |
918 | hbuss | 66 | ready = 0; |
67 | if(AdWertNick < 1020) AnalogOffsetNick--; else if(AdWertNick > 1030) AnalogOffsetNick++; else ready++; |
||
68 | if(AdWertRoll < 1020) AnalogOffsetRoll--; else if(AdWertRoll > 1030) AnalogOffsetRoll++; else ready++; |
||
69 | if(AdWertGier < 1020) AnalogOffsetGier--; else if(AdWertGier > 1030) AnalogOffsetGier++; else ready++; |
||
70 | twi_state = 8; |
||
71 | i2c_start(); |
||
72 | if(AnalogOffsetNick < 10) { GyroDefektN = 1; AnalogOffsetNick = 10;}; if(AnalogOffsetNick > 245) { GyroDefektN = 1; AnalogOffsetNick = 245;}; |
||
73 | if(AnalogOffsetRoll < 10) { GyroDefektR = 1; AnalogOffsetRoll = 10;}; if(AnalogOffsetRoll > 245) { GyroDefektR = 1; AnalogOffsetRoll = 245;}; |
||
74 | if(AnalogOffsetGier < 10) { GyroDefektG = 1; AnalogOffsetGier = 10;}; if(AnalogOffsetGier > 245) { GyroDefektG = 1; AnalogOffsetGier = 245;}; |
||
1219 | hbuss | 75 | while(twi_state) if(CheckDelay(timeout)) {printf("\n\r DAC or I2C ERROR! Check I2C, 3Vref, DAC and BL-Ctrl"); break;} |
918 | hbuss | 76 | messanzahl_Druck = 0; |
77 | ANALOG_ON; |
||
78 | while(messanzahl_Druck == 0); |
||
79 | if(i<10) Delay_ms_Mess(10); |
||
80 | } |
||
921 | hbuss | 81 | Delay_ms_Mess(70); |
918 | hbuss | 82 | } |
1 | ingob | 83 | |
1286 | MartinR | 84 | /* // MartinR: so war es |
1171 | hbuss | 85 | |
86 | 1 r |
||
87 | 2 g |
||
88 | 3 y |
||
89 | 4 x |
||
90 | 5 n |
||
91 | 6 r |
||
92 | 7 u |
||
93 | 8 z |
||
94 | 9 L |
||
95 | 10 n |
||
96 | 11 r |
||
97 | 12 g |
||
98 | 13 y |
||
99 | 14 x |
||
100 | 15 n |
||
101 | 16 r |
||
102 | 17 L |
||
103 | */ |
||
104 | |||
1286 | MartinR | 105 | /* MartinR : geändert |
106 | |||
107 | 1 r |
||
108 | 2 g |
||
109 | 3 L |
||
110 | 4 n |
||
111 | 5 r |
||
112 | 6 y |
||
113 | 7 x |
||
114 | 8 n |
||
115 | 9 r |
||
116 | 10 g |
||
117 | 11 L |
||
118 | 12 n |
||
119 | 13 r |
||
120 | 14 u |
||
121 | 15 z |
||
122 | */ |
||
123 | |||
1 | ingob | 124 | //####################################################################################### |
125 | // |
||
126 | SIGNAL(SIG_ADC) |
||
127 | //####################################################################################### |
||
128 | { |
||
129 | static unsigned char kanal=0,state = 0; |
||
1171 | hbuss | 130 | static signed int gier1, roll1, nick1, nick_filter, roll_filter; |
1286 | MartinR | 131 | static signed int roll_alt1, roll_alt2, roll_alt3, nick_alt1, nick_alt2, nick_alt3; // MartinR: 4x Mittelung |
132 | //static signed int roll_alt1, nick_alt1; // MartinR: 2x Mittelung |
||
1171 | hbuss | 133 | static signed int accy, accx; |
1286 | MartinR | 134 | |
135 | /* // MartinR : so war es Anfang |
||
1171 | hbuss | 136 | switch(state++) |
137 | { |
||
138 | case 0: |
||
139 | nick1 = ADC; |
||
140 | kanal = AD_ROLL; |
||
141 | break; |
||
142 | case 1: |
||
143 | roll1 = ADC; |
||
144 | kanal = AD_GIER; |
||
145 | break; |
||
146 | case 2: |
||
147 | gier1 = ADC; |
||
148 | kanal = AD_ACC_Y; |
||
149 | break; |
||
150 | case 3: |
||
151 | Aktuell_ay = NeutralAccY - ADC; |
||
152 | accy = Aktuell_ay; |
||
153 | kanal = AD_ACC_X; |
||
154 | break; |
||
155 | case 4: |
||
156 | Aktuell_ax = ADC - NeutralAccX; |
||
157 | accx = Aktuell_ax; |
||
158 | kanal = AD_NICK; |
||
159 | break; |
||
160 | case 5: |
||
161 | nick1 += ADC; |
||
162 | kanal = AD_ROLL; |
||
163 | break; |
||
164 | case 6: |
||
165 | roll1 += ADC; |
||
166 | kanal = AD_UBAT; |
||
167 | break; |
||
168 | case 7: |
||
169 | UBat = (3 * UBat + ADC / 3) / 4; |
||
170 | kanal = AD_ACC_Z; |
||
171 | break; |
||
172 | case 8: |
||
173 | AdWertAccHoch = (signed int) ADC - NeutralAccZ; |
||
174 | if(AdWertAccHoch > 1) |
||
175 | { |
||
176 | if(NeutralAccZ < 750) |
||
177 | { |
||
178 | NeutralAccZ += 0.02; |
||
179 | if(modell_fliegt < 500) NeutralAccZ += 0.1; |
||
180 | } |
||
181 | } |
||
182 | else if(AdWertAccHoch < -1) |
||
183 | { |
||
184 | if(NeutralAccZ > 550) |
||
185 | { |
||
186 | NeutralAccZ-= 0.02; |
||
187 | if(modell_fliegt < 500) NeutralAccZ -= 0.1; |
||
188 | } |
||
189 | } |
||
190 | messanzahl_AccHoch = 1; |
||
191 | Aktuell_az = ADC; |
||
192 | Mess_Integral_Hoch += AdWertAccHoch; // Integrieren |
||
193 | Mess_Integral_Hoch -= Mess_Integral_Hoch / 1024; // dämfen |
||
194 | kanal = AD_DRUCK; |
||
195 | break; |
||
196 | // "case 8:" fehlt hier absichtlich |
||
197 | case 10: |
||
198 | nick1 += ADC; |
||
199 | kanal = AD_ROLL; |
||
200 | break; |
||
201 | case 11: |
||
202 | roll1 += ADC; |
||
203 | kanal = AD_GIER; |
||
204 | break; |
||
205 | case 12: |
||
206 | if(PlatinenVersion == 10) AdWertGier = (ADC + gier1 + 1) / 2; |
||
207 | else |
||
208 | if(PlatinenVersion == 20) AdWertGier = 2047 - (ADC + gier1); |
||
209 | else AdWertGier = (ADC + gier1); |
||
210 | kanal = AD_ACC_Y; |
||
211 | break; |
||
212 | case 13: |
||
213 | Aktuell_ay = NeutralAccY - ADC; |
||
214 | AdWertAccRoll = (Aktuell_ay + accy); |
||
215 | kanal = AD_ACC_X; |
||
216 | break; |
||
217 | case 14: |
||
218 | Aktuell_ax = ADC - NeutralAccX; |
||
219 | AdWertAccNick = (Aktuell_ax + accx); |
||
220 | kanal = AD_NICK; |
||
221 | break; |
||
222 | case 15: |
||
223 | nick1 += ADC; |
||
1173 | hbuss | 224 | if(PlatinenVersion == 10) nick1 *= 2; else nick1 *= 4; |
225 | AdWertNick = nick1 / 8; |
||
226 | nick_filter = (nick_filter + nick1) / 2; |
||
227 | HiResNick = nick_filter - AdNeutralNick; |
||
1171 | hbuss | 228 | AdWertNickFilter = (AdWertNickFilter + HiResNick) / 2; |
229 | kanal = AD_ROLL; |
||
230 | break; |
||
231 | case 16: |
||
232 | roll1 += ADC; |
||
1173 | hbuss | 233 | if(PlatinenVersion == 10) roll1 *= 2; else roll1 *= 4; |
234 | AdWertRoll = roll1 / 8; |
||
235 | roll_filter = (roll_filter + roll1) / 2; |
||
236 | HiResRoll = roll_filter - AdNeutralRoll; |
||
1171 | hbuss | 237 | AdWertRollFilter = (AdWertRollFilter + HiResRoll) / 2; |
238 | kanal = AD_DRUCK; |
||
239 | break; |
||
240 | case 17: |
||
241 | state = 0; |
||
242 | AdReady = 1; |
||
243 | ZaehlMessungen++; |
||
244 | // "break" fehlt hier absichtlich |
||
245 | case 9: |
||
246 | tmpLuftdruck += ADC; |
||
247 | if(++messanzahl_Druck >= 5) |
||
248 | { |
||
249 | tmpLuftdruck /= 2; |
||
250 | MessLuftdruck = ADC; |
||
251 | messanzahl_Druck = 0; |
||
252 | HoeheD = (31 * HoeheD + (int) Parameter_Luftdruck_D * (int)(255 * ExpandBaro + StartLuftdruck - tmpLuftdruck - HoehenWert))/32; // D-Anteil = neuerWert - AlterWert |
||
253 | Luftdruck = (tmpLuftdruck + 7 * Luftdruck + 4) / 8; |
||
254 | HoehenWert = 255 * ExpandBaro + StartLuftdruck - Luftdruck; |
||
255 | tmpLuftdruck /= 2; |
||
256 | } |
||
257 | kanal = AD_NICK; |
||
258 | break; |
||
259 | default: |
||
260 | kanal = 0; state = 0; kanal = AD_NICK; |
||
261 | break; |
||
262 | } |
||
1286 | MartinR | 263 | */ // MartinR : so war es Ende |
264 | // MartinR : geändert Anfang |
||
265 | |||
266 | switch(state++) |
||
267 | { |
||
268 | case 0: |
||
269 | nick1 = ADC; |
||
270 | kanal = AD_ROLL; |
||
271 | break; |
||
272 | case 1: |
||
273 | roll1 = ADC; |
||
274 | kanal = AD_GIER; |
||
275 | break; |
||
276 | |||
277 | case 2: |
||
278 | gier1 = ADC; |
||
279 | kanal = AD_DRUCK; |
||
280 | break; |
||
281 | case 3: |
||
282 | tmpLuftdruck += ADC; |
||
283 | messanzahl_Druck ++; |
||
284 | kanal = AD_NICK; |
||
285 | break; |
||
286 | |||
287 | case 4: |
||
288 | nick1 += ADC; |
||
289 | kanal = AD_ROLL; |
||
290 | break; |
||
291 | case 5: |
||
292 | roll1 += ADC; |
||
293 | kanal = AD_ACC_Y; |
||
294 | break; |
||
295 | |||
296 | case 6: |
||
297 | Aktuell_ay = NeutralAccY - ADC; |
||
298 | AdWertAccRoll = (Aktuell_ay + accy); |
||
299 | accy = Aktuell_ay; |
||
300 | kanal = AD_ACC_X; |
||
301 | break; |
||
302 | case 7: |
||
303 | Aktuell_ax = ADC - NeutralAccX; |
||
304 | AdWertAccNick = (Aktuell_ax + accx); |
||
305 | accx = Aktuell_ax; |
||
306 | kanal = AD_NICK; |
||
307 | break; |
||
308 | |||
309 | case 8: |
||
310 | nick1 += ADC; |
||
311 | kanal = AD_ROLL; |
||
312 | break; |
||
313 | case 9: |
||
314 | roll1 += ADC; |
||
315 | kanal = AD_GIER; |
||
316 | break; |
||
317 | |||
318 | case 10: |
||
319 | if(PlatinenVersion == 10) AdWertGier = (ADC + gier1 + 1) / 2; |
||
320 | else |
||
321 | if(PlatinenVersion == 20) AdWertGier = 2047 - (ADC + gier1); |
||
322 | else AdWertGier = (ADC + gier1); |
||
323 | kanal = AD_DRUCK; |
||
324 | break; |
||
325 | |||
326 | case 11: |
||
327 | |||
328 | // MartinR: neu |
||
329 | tmpLuftdruck += ADC; |
||
330 | //MessLuftdruck = tmpLuftdruck / 2; |
||
331 | MessLuftdruck = ADC; |
||
332 | |||
333 | if(++messanzahl_Druck >= 5) |
||
334 | { |
||
335 | tmpLuftdruck -= 2616L * ExpandBaro; // -523.19 counts per 10 counts offset step |
||
336 | tmpLuftdruck /= 2; |
||
337 | messanzahl_Druck = 0; |
||
338 | //HoeheD = (31 * HoeheD + (int) Parameter_Luftdruck_D * (int)((int)(StartLuftdruck - tmpLuftdruck) - HoehenWert))/32; // D-Anteil = neuerWert - AlterWert |
||
339 | Luftdruck = (tmpLuftdruck + 7 * Luftdruck + 4) / 8; |
||
340 | HoehenWert = StartLuftdruck - Luftdruck; |
||
341 | //tmpLuftdruck /= 2; |
||
342 | tmpLuftdruck = 0; |
||
343 | } |
||
344 | |||
345 | // Luftdruck = (tmpLuftdruck + 7 * Luftdruck + 4) / 8; |
||
346 | // HoehenWert = 255 * ExpandBaro + StartLuftdruck - Luftdruck; // MartinR: zu Höhenregler |
||
347 | |||
348 | kanal = AD_NICK; |
||
349 | break; |
||
350 | |||
351 | case 12: |
||
352 | nick1 += ADC; |
||
353 | //if(PlatinenVersion == 10) nick1 *= 2; else nick1 *= 4; // MartinR: so war es |
||
354 | //if(PlatinenVersion == 10) ; else nick1 *= 2; // MartinR: 2x Mittelung |
||
355 | if(PlatinenVersion == 10) nick1 /= 2; //else nick1 *= 1; // MartinR: 4x Mittelung |
||
356 | //AdWertNick = nick1 / 8; // MartinR: so war es |
||
357 | //AdWertNick = nick1 / 4; // MartinR: 2x Mittelung |
||
358 | AdWertNick = nick1 / 2; // MartinR: 4x Mittelung |
||
359 | |||
360 | // nick_filter = (nick_filter + nick1) / 2; // MartinR: so war es |
||
361 | //nick_filter = (nick_alt1 + nick1); // MartinR: anderer Nick-Filter: 2x Mittelung |
||
362 | nick_filter = (nick_alt3 +nick_alt2 +nick_alt1 + nick1); // MartinR: anderer Nick-Filter: 4x Mittelung |
||
363 | nick_alt3 = nick_alt2; // MartinR: anderer Nick-Filter |
||
364 | nick_alt2 = nick_alt1; // MartinR: anderer Nick-Filter |
||
365 | nick_alt1 = nick1; // MartinR: anderer Nick-Filter |
||
366 | |||
367 | HiResNick = nick_filter - AdNeutralNick; |
||
368 | //AdWertNickFilter = (AdWertNickFilter + HiResNick) / 2; // MartinR: so war es |
||
369 | AdWertNickFilter = HiResNick; // MartinR: Filter deaktiviert |
||
370 | kanal = AD_ROLL; |
||
371 | |||
372 | break; |
||
373 | case 13: |
||
374 | roll1 += ADC; |
||
375 | // if(PlatinenVersion == 10) roll1 *= 2; else roll1 *= 4; // MartinR: so war es |
||
376 | //if(PlatinenVersion == 10) ; else roll1 *= 2; // MartinR: 2x Mittelung |
||
377 | if(PlatinenVersion == 10) roll1 /= 2; //else roll1 *= 1; // MartinR: 4x Mittelung |
||
378 | // AdWertRoll = roll1 / 8; // MartinR: so war es |
||
379 | //AdWertRoll = roll1 / 4; // MartinR: 2x Mittelung |
||
380 | AdWertRoll = roll1 / 2; // MartinR: 4x Mittelung |
||
381 | |||
382 | //roll_filter = (roll_filter + roll1) / 2; // MartinR: so war es |
||
383 | //roll_filter = (roll_alt1 + roll1); // MartinR: anderer Nick-Filter: 2x Mittelung |
||
384 | roll_filter = (roll_alt3 + roll_alt2 + roll_alt1 + roll1); // MartinR: anderer Nick-Filter: 4x Mittelung |
||
385 | roll_alt3 = roll_alt2; // MartinR: anderer Nick-Filter |
||
386 | roll_alt2 = roll_alt1; // MartinR: anderer Nick-Filter |
||
387 | roll_alt1 = roll1; // MartinR: anderer Nick-Filter |
||
388 | |||
389 | HiResRoll = roll_filter - AdNeutralRoll; |
||
390 | //AdWertRollFilter = (AdWertRollFilter + HiResRoll) / 2; // MartinR: so war es |
||
391 | AdWertRollFilter = HiResRoll; // MartinR: Filter deaktiviert |
||
392 | |||
393 | kanal = AD_UBAT; |
||
394 | |||
395 | break; |
||
396 | |||
397 | case 14: |
||
398 | UBat = (3 * UBat + ADC / 3) / 4; |
||
399 | kanal = AD_ACC_Z; |
||
400 | break; |
||
401 | |||
402 | case 15: |
||
403 | // AdWertAccHoch = (signed int) ADC - NeutralAccZ; // MartinR : so war es |
||
404 | //AdWertAccHoch = ADC - NeutralAccZ; // MartinR: modifiziert für Tests |
||
405 | /* // MartinR: deaktiviert |
||
406 | |||
407 | if(AdWertAccHoch > 1) |
||
408 | { |
||
409 | if(NeutralAccZ < 750) |
||
410 | { |
||
411 | NeutralAccZ += 0.02; |
||
412 | if(modell_fliegt < 500) NeutralAccZ += 0.1; |
||
413 | } |
||
414 | } |
||
415 | else if(AdWertAccHoch < -1) |
||
416 | { |
||
417 | if(NeutralAccZ > 550) |
||
418 | { |
||
419 | NeutralAccZ -= 0.02; |
||
420 | if(modell_fliegt < 500) NeutralAccZ -= 0.1; |
||
421 | } |
||
422 | } |
||
423 | */ // MartinR: deaktiviert Ende |
||
424 | |||
425 | // messanzahl_AccHoch = 1; MartinR: deaktiviert, da nicht verwendet |
||
426 | |||
427 | Aktuell_az = (Aktuell_az + ADC) / 2; |
||
428 | AdWertAccHoch = Aktuell_az - NeutralAccZ; // MartinR: modifiziert für Tests |
||
429 | //Mess_Integral_Hoch += AdWertAccHoch; // Integrieren // MartinR: zu Höhenregler in fc.c verschoben |
||
430 | //Mess_Integral_Hoch -= Mess_Integral_Hoch / 1024; // dämfen // MartinR: zu Höhenregler in fc.c verschoben |
||
431 | |||
432 | AdReady = 1; |
||
433 | state = 0; |
||
434 | kanal = AD_NICK; |
||
435 | break; |
||
436 | |||
437 | default: |
||
438 | kanal = 0; state = 0; kanal = AD_NICK; |
||
439 | break; |
||
440 | } |
||
441 | |||
442 | // MartinR : geändert Ende |
||
443 | |||
444 | |||
1171 | hbuss | 445 | ADMUX = kanal; |
1286 | MartinR | 446 | // if(state != 0) ANALOG_ON; // MartinR : so war es: |
447 | // Bei jedem Reglerzyklus wurde nur der Ablauf der Reihenfolge der AD-Wandlungen angestoßen. |
||
448 | // Solange die Reihe nicht durchgelaufen ist, wurde nach jeder AD-Wandlung die nächste AD-Wandlung über ANALOG_ON gestartet. |
||
449 | |||
450 | // if(state != 0) ANALOG_START; // MartinR verschoben zu timer0 |
||
451 | |||
452 | } |
||
1171 | hbuss | 453 | |
454 | |||
455 | |||
456 | /* |
||
457 | //####################################################################################### |
||
458 | // |
||
459 | SIGNAL(SIG_ADC) |
||
460 | //####################################################################################### |
||
461 | { |
||
462 | static unsigned char kanal=0,state = 0; |
||
1166 | hbuss | 463 | static signed int gier1, roll1, nick1; |
464 | static signed long nick_filter, roll_filter; |
||
465 | static signed int accy, accx; |
||
466 | switch(state++) |
||
467 | { |
||
468 | case 0: |
||
469 | nick1 = ADC; |
||
470 | kanal = AD_ROLL; |
||
471 | break; |
||
472 | case 1: |
||
473 | roll1 = ADC; |
||
474 | kanal = AD_GIER; |
||
475 | break; |
||
476 | case 2: |
||
477 | gier1 = ADC; |
||
478 | kanal = AD_ACC_Y; |
||
479 | break; |
||
480 | case 3: |
||
481 | Aktuell_ay = NeutralAccY - ADC; |
||
482 | accy = Aktuell_ay; |
||
483 | kanal = AD_NICK; |
||
484 | break; |
||
485 | case 4: |
||
486 | nick1 += ADC; |
||
487 | kanal = AD_ROLL; |
||
488 | break; |
||
489 | case 5: |
||
490 | roll1 += ADC; |
||
491 | kanal = AD_ACC_Z; |
||
492 | break; |
||
493 | case 6: |
||
494 | AdWertAccHoch = (signed int) ADC - NeutralAccZ; |
||
495 | if(AdWertAccHoch > 1) |
||
496 | { |
||
497 | if(NeutralAccZ < 750) |
||
498 | { |
||
499 | NeutralAccZ += 0.02; |
||
500 | if(modell_fliegt < 500) NeutralAccZ += 0.1; |
||
501 | } |
||
502 | } |
||
503 | else if(AdWertAccHoch < -1) |
||
504 | { |
||
505 | if(NeutralAccZ > 550) |
||
506 | { |
||
507 | NeutralAccZ-= 0.02; |
||
508 | if(modell_fliegt < 500) NeutralAccZ -= 0.1; |
||
509 | } |
||
510 | } |
||
511 | messanzahl_AccHoch = 1; |
||
512 | Aktuell_az = ADC; |
||
513 | Mess_Integral_Hoch += AdWertAccHoch; // Integrieren |
||
514 | Mess_Integral_Hoch -= Mess_Integral_Hoch / 1024; // dämfen |
||
515 | kanal = AD_NICK; |
||
516 | break; |
||
517 | case 7: |
||
518 | nick1 += ADC; |
||
519 | kanal = AD_ROLL; |
||
520 | break; |
||
521 | case 8: |
||
522 | roll1 += ADC; |
||
523 | kanal = AD_ACC_X; |
||
524 | break; |
||
525 | case 9: |
||
526 | Aktuell_ax = ADC - NeutralAccX; |
||
527 | accx = Aktuell_ax; |
||
528 | kanal = AD_GIER; |
||
529 | break; |
||
530 | case 10: |
||
531 | gier1 += ADC; |
||
532 | kanal = AD_NICK; |
||
533 | break; |
||
534 | case 11: |
||
535 | nick1 += ADC; |
||
536 | kanal = AD_ROLL; |
||
537 | break; |
||
538 | case 12: |
||
539 | roll1 += ADC; |
||
540 | kanal = AD_UBAT; |
||
541 | break; |
||
542 | case 13: |
||
543 | UBat = (3 * UBat + ADC / 3) / 4;//(UBat + ((ADC * 39) / 256) + 19) / 2; |
||
544 | kanal = AD_ACC_Y; |
||
545 | break; |
||
546 | case 14: |
||
547 | Aktuell_ay = NeutralAccY - ADC; |
||
548 | accy += Aktuell_ay; |
||
549 | kanal = AD_NICK; |
||
550 | break; |
||
551 | case 15: |
||
552 | nick1 += ADC; |
||
553 | kanal = AD_ROLL; |
||
554 | break; |
||
555 | case 16: |
||
556 | roll1 += ADC; |
||
557 | kanal = AD_ACC_X; |
||
558 | break; |
||
559 | case 17: |
||
560 | Aktuell_ax = ADC - NeutralAccX; |
||
561 | accx += Aktuell_ax; |
||
562 | kanal = AD_NICK; |
||
563 | break; |
||
564 | case 18: |
||
565 | nick1 += ADC; |
||
566 | kanal = AD_ROLL; |
||
567 | break; |
||
568 | case 19: |
||
569 | roll1 += ADC; |
||
570 | kanal = AD_GIER; |
||
571 | break; |
||
572 | case 20: |
||
573 | gier1 += ADC; |
||
574 | kanal = AD_ACC_Y; |
||
575 | break; |
||
576 | case 21: |
||
577 | Aktuell_ay = NeutralAccY - ADC; |
||
578 | accy += Aktuell_ay; |
||
579 | kanal = AD_NICK; |
||
580 | break; |
||
581 | case 22: |
||
582 | nick1 += ADC; |
||
583 | kanal = AD_ROLL; |
||
584 | break; |
||
585 | case 23: |
||
586 | roll1 += ADC; |
||
587 | kanal = AD_DRUCK; |
||
588 | break; |
||
589 | case 24: |
||
590 | tmpLuftdruck += ADC; |
||
591 | if(++messanzahl_Druck >= 5) |
||
592 | { |
||
593 | MessLuftdruck = ADC; |
||
594 | messanzahl_Druck = 0; |
||
1167 | hbuss | 595 | HoeheD = (7 * HoeheD + (int) Parameter_Luftdruck_D * (int)(255 * ExpandBaro + StartLuftdruck - tmpLuftdruck - HoehenWert)) / 8; // D-Anteil = neuerWert - AlterWert |
1166 | hbuss | 596 | Luftdruck = (tmpLuftdruck + 3 * Luftdruck) / 4; |
597 | HoehenWert = 255 * ExpandBaro + StartLuftdruck - Luftdruck; |
||
598 | tmpLuftdruck = 0; |
||
599 | } |
||
600 | kanal = AD_NICK; |
||
601 | break; |
||
602 | case 25: |
||
603 | nick1 += ADC; |
||
604 | kanal = AD_ROLL; |
||
605 | break; |
||
606 | case 26: |
||
607 | roll1 += ADC; |
||
608 | kanal = AD_ACC_X; |
||
609 | break; |
||
610 | case 27: |
||
611 | Aktuell_ax = ADC - NeutralAccX; |
||
612 | accx += Aktuell_ax; |
||
613 | kanal = AD_GIER; |
||
614 | break; |
||
615 | case 28: |
||
616 | if(PlatinenVersion == 10) AdWertGier = (ADC + gier1 + 2) / 4; |
||
617 | else |
||
618 | if(PlatinenVersion == 20) AdWertGier = 2047 - (ADC + gier1 + 1) / 2; |
||
619 | else AdWertGier = (ADC + gier1 + 1) / 2; |
||
620 | kanal = AD_NICK; |
||
621 | break; |
||
622 | case 29: |
||
623 | nick1 += ADC; |
||
624 | kanal = AD_ROLL; |
||
625 | break; |
||
626 | case 30: |
||
627 | roll1 += ADC; |
||
628 | kanal = AD_ACC_Y; |
||
629 | break; |
||
630 | case 31: |
||
631 | Aktuell_ay = NeutralAccY - ADC; |
||
632 | AdWertAccRoll = (Aktuell_ay + accy); |
||
633 | kanal = AD_NICK; |
||
634 | break; |
||
635 | case 32: |
||
636 | AdWertNick = (ADC + nick1 + 3) / 5; |
||
637 | nick_filter = (long) (1 * (long) nick_filter + 4 * (long)(ADC + nick1) + 1) / 2; |
||
638 | if(PlatinenVersion == 10) { AdWertNick /= 2;nick_filter /=2;} |
||
639 | HiResNick = nick_filter - 20 * AdNeutralNick; |
||
640 | AdWertNickFilter = (long)(3L * (long)AdWertNickFilter + HiResNick + 2) / 4; |
||
641 | DebugOut.Analog[21] = AdWertNickFilter / 4; |
||
642 | kanal = AD_ROLL; |
||
643 | break; |
||
644 | case 33: |
||
645 | AdWertRoll = (ADC + roll1 + 3) / 5; |
||
646 | roll_filter = (long)(1 * (long)roll_filter + 4 * (long)(ADC + roll1) + 1) / 2; |
||
647 | if(PlatinenVersion == 10) { AdWertRoll /= 2;roll_filter /=2;} |
||
648 | HiResRoll = roll_filter - 20 * AdNeutralRoll; |
||
649 | AdWertRollFilter = (long)(3L * (long)AdWertRollFilter + HiResRoll + 2) / 4; |
||
650 | DebugOut.Analog[22] = AdWertRollFilter / 4; |
||
651 | kanal = AD_ACC_X; |
||
652 | break; |
||
653 | case 34: |
||
654 | Aktuell_ax = ADC - NeutralAccX; |
||
655 | AdWertAccNick = (Aktuell_ax + accx); |
||
656 | kanal = AD_NICK; |
||
657 | state = 0; |
||
658 | AdReady = 1; |
||
659 | ZaehlMessungen++; |
||
660 | break; |
||
661 | default: |
||
662 | kanal = 0; |
||
663 | state = 0; |
||
664 | break; |
||
665 | } |
||
666 | ADMUX = kanal; |
||
667 | if(state != 0) ANALOG_ON; |
||
668 | } |
||
1171 | hbuss | 669 | */ |