Rev 1168 | Rev 1173 | Go to most recent revision | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 1168 | Rev 1171 | ||
---|---|---|---|
1 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
2 | // + Copyright (c) 04.2007 Holger Buss |
2 | // + Copyright (c) 04.2007 Holger Buss |
3 | // + only for non-profit use |
3 | // + only for non-profit use |
4 | // + www.MikroKopter.com |
4 | // + www.MikroKopter.com |
5 | // + see the File "License.txt" for further Informations |
5 | // + see the File "License.txt" for further Informations |
6 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
6 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
7 | 7 | ||
8 | #include "main.h" |
8 | #include "main.h" |
9 | volatile int Aktuell_Nick,Aktuell_Roll,Aktuell_Gier,Aktuell_ax, Aktuell_ay,Aktuell_az, UBat = 100; |
9 | volatile int Aktuell_Nick,Aktuell_Roll,Aktuell_Gier,Aktuell_ax, Aktuell_ay,Aktuell_az, UBat = 100; |
10 | volatile int AdWertNickFilter = 0, AdWertRollFilter = 0, AdWertGierFilter = 0; |
10 | volatile int AdWertNickFilter = 0, AdWertRollFilter = 0, AdWertGierFilter = 0; |
11 | volatile int HiResNick = 2500, HiResRoll = 2500; |
11 | volatile int HiResNick = 2500, HiResRoll = 2500; |
12 | volatile int AdWertNick = 0, AdWertRoll = 0, AdWertGier = 0; |
12 | volatile int AdWertNick = 0, AdWertRoll = 0, AdWertGier = 0; |
13 | volatile int AdWertAccRoll = 0,AdWertAccNick = 0,AdWertAccHoch = 0; |
13 | volatile int AdWertAccRoll = 0,AdWertAccNick = 0,AdWertAccHoch = 0; |
14 | volatile char messanzahl_AccHoch = 0; |
14 | volatile char messanzahl_AccHoch = 0; |
15 | volatile long Luftdruck = 32000; |
15 | volatile long Luftdruck = 32000; |
16 | volatile int StartLuftdruck; |
16 | volatile int StartLuftdruck; |
17 | volatile unsigned int MessLuftdruck = 1023; |
17 | volatile unsigned int MessLuftdruck = 1023; |
18 | unsigned char DruckOffsetSetting; |
18 | unsigned char DruckOffsetSetting; |
19 | signed char ExpandBaro = 0; |
19 | signed char ExpandBaro = 0; |
20 | volatile int HoeheD = 0; |
20 | volatile int HoeheD = 0; |
21 | volatile char messanzahl_Druck; |
21 | volatile char messanzahl_Druck; |
22 | volatile int tmpLuftdruck; |
22 | volatile int tmpLuftdruck; |
23 | volatile unsigned int ZaehlMessungen = 0; |
23 | volatile unsigned int ZaehlMessungen = 0; |
24 | unsigned char AnalogOffsetNick = 115,AnalogOffsetRoll = 115,AnalogOffsetGier = 115; |
24 | unsigned char AnalogOffsetNick = 115,AnalogOffsetRoll = 115,AnalogOffsetGier = 115; |
25 | unsigned char GyroDefektN = 0,GyroDefektR = 0,GyroDefektG = 0; |
25 | unsigned char GyroDefektN = 0,GyroDefektR = 0,GyroDefektG = 0; |
26 | volatile unsigned char AdReady = 1; |
26 | volatile unsigned char AdReady = 1; |
27 | //####################################################################################### |
27 | //####################################################################################### |
28 | // |
28 | // |
29 | void ADC_Init(void) |
29 | void ADC_Init(void) |
30 | //####################################################################################### |
30 | //####################################################################################### |
31 | { |
31 | { |
32 | ADMUX = 0;//Referenz ist extern |
32 | ADMUX = 0;//Referenz ist extern |
33 | ANALOG_ON; |
33 | ANALOG_ON; |
34 | } |
34 | } |
35 | 35 | ||
36 | void SucheLuftruckOffset(void) |
36 | void SucheLuftruckOffset(void) |
37 | { |
37 | { |
38 | unsigned int off; |
38 | unsigned int off; |
39 | off = eeprom_read_byte(&EEPromArray[EEPROM_ADR_LAST_OFFSET]); |
39 | off = eeprom_read_byte(&EEPromArray[EEPROM_ADR_LAST_OFFSET]); |
40 | if(off > 20) off -= 10; |
40 | if(off > 20) off -= 10; |
41 | OCR0A = off; |
41 | OCR0A = off; |
42 | ExpandBaro = 0; |
42 | ExpandBaro = 0; |
43 | Delay_ms_Mess(100); |
43 | Delay_ms_Mess(100); |
44 | if(MessLuftdruck < 850) off = 0; |
44 | if(MessLuftdruck < 850) off = 0; |
45 | for(; off < 250;off++) |
45 | for(; off < 250;off++) |
46 | { |
46 | { |
47 | OCR0A = off; |
47 | OCR0A = off; |
48 | Delay_ms_Mess(50); |
48 | Delay_ms_Mess(50); |
49 | printf("."); |
49 | printf("."); |
50 | if(MessLuftdruck < 850) break; |
50 | if(MessLuftdruck < 850) break; |
51 | } |
51 | } |
52 | eeprom_write_byte(&EEPromArray[EEPROM_ADR_LAST_OFFSET], off); |
52 | eeprom_write_byte(&EEPromArray[EEPROM_ADR_LAST_OFFSET], off); |
53 | DruckOffsetSetting = off; |
53 | DruckOffsetSetting = off; |
54 | Delay_ms_Mess(300); |
54 | Delay_ms_Mess(300); |
55 | } |
55 | } |
56 | 56 | ||
57 | void SucheGyroOffset(void) |
57 | void SucheGyroOffset(void) |
58 | { |
58 | { |
59 | unsigned char i, ready = 0; |
59 | unsigned char i, ready = 0; |
60 | GyroDefektN = 0; GyroDefektR = 0; GyroDefektG = 0; |
60 | GyroDefektN = 0; GyroDefektR = 0; GyroDefektG = 0; |
61 | for(i=140; i != 0; i--) |
61 | for(i=140; i != 0; i--) |
62 | { |
62 | { |
63 | if(ready == 3 && i > 10) i = 9; |
63 | if(ready == 3 && i > 10) i = 9; |
64 | ready = 0; |
64 | ready = 0; |
65 | if(AdWertNick < 1020) AnalogOffsetNick--; else if(AdWertNick > 1030) AnalogOffsetNick++; else ready++; |
65 | if(AdWertNick < 1020) AnalogOffsetNick--; else if(AdWertNick > 1030) AnalogOffsetNick++; else ready++; |
66 | if(AdWertRoll < 1020) AnalogOffsetRoll--; else if(AdWertRoll > 1030) AnalogOffsetRoll++; 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++; |
67 | if(AdWertGier < 1020) AnalogOffsetGier--; else if(AdWertGier > 1030) AnalogOffsetGier++; else ready++; |
68 | twi_state = 8; |
68 | twi_state = 8; |
69 | i2c_start(); |
69 | i2c_start(); |
70 | if(AnalogOffsetNick < 10) { GyroDefektN = 1; AnalogOffsetNick = 10;}; if(AnalogOffsetNick > 245) { GyroDefektN = 1; AnalogOffsetNick = 245;}; |
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;}; |
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;}; |
72 | if(AnalogOffsetGier < 10) { GyroDefektG = 1; AnalogOffsetGier = 10;}; if(AnalogOffsetGier > 245) { GyroDefektG = 1; AnalogOffsetGier = 245;}; |
73 | while(twi_state); |
73 | while(twi_state); |
74 | messanzahl_Druck = 0; |
74 | messanzahl_Druck = 0; |
75 | ANALOG_ON; |
75 | ANALOG_ON; |
76 | while(messanzahl_Druck == 0); |
76 | while(messanzahl_Druck == 0); |
77 | if(i<10) Delay_ms_Mess(10); |
77 | if(i<10) Delay_ms_Mess(10); |
78 | } |
78 | } |
79 | Delay_ms_Mess(70); |
79 | Delay_ms_Mess(70); |
80 | } |
80 | } |
- | 81 | ||
- | 82 | /* |
|
- | 83 | 0 n |
|
- | 84 | 1 r |
|
- | 85 | 2 g |
|
- | 86 | 3 y |
|
- | 87 | 4 x |
|
- | 88 | 5 n |
|
- | 89 | 6 r |
|
- | 90 | 7 u |
|
- | 91 | 8 z |
|
- | 92 | 9 L |
|
- | 93 | 10 n |
|
- | 94 | 11 r |
|
- | 95 | 12 g |
|
- | 96 | 13 y |
|
- | 97 | 14 x |
|
- | 98 | 15 n |
|
- | 99 | 16 r |
|
- | 100 | 17 L |
|
- | 101 | */ |
|
- | 102 | ||
- | 103 | //####################################################################################### |
|
- | 104 | // |
|
- | 105 | SIGNAL(SIG_ADC) |
|
- | 106 | //####################################################################################### |
|
- | 107 | { |
|
- | 108 | static unsigned char kanal=0,state = 0; |
|
- | 109 | static signed int gier1, roll1, nick1, nick_filter, roll_filter; |
|
- | 110 | static signed int accy, accx; |
|
- | 111 | switch(state++) |
|
- | 112 | { |
|
- | 113 | case 0: |
|
- | 114 | nick1 = ADC; |
|
- | 115 | kanal = AD_ROLL; |
|
- | 116 | break; |
|
- | 117 | case 1: |
|
- | 118 | roll1 = ADC; |
|
- | 119 | kanal = AD_GIER; |
|
- | 120 | break; |
|
- | 121 | case 2: |
|
- | 122 | gier1 = ADC; |
|
- | 123 | kanal = AD_ACC_Y; |
|
- | 124 | break; |
|
- | 125 | case 3: |
|
- | 126 | Aktuell_ay = NeutralAccY - ADC; |
|
- | 127 | accy = Aktuell_ay; |
|
- | 128 | kanal = AD_ACC_X; |
|
- | 129 | break; |
|
- | 130 | case 4: |
|
- | 131 | Aktuell_ax = ADC - NeutralAccX; |
|
- | 132 | accx = Aktuell_ax; |
|
- | 133 | kanal = AD_NICK; |
|
- | 134 | break; |
|
- | 135 | case 5: |
|
- | 136 | nick1 += ADC; |
|
- | 137 | kanal = AD_ROLL; |
|
- | 138 | break; |
|
- | 139 | case 6: |
|
- | 140 | roll1 += ADC; |
|
- | 141 | kanal = AD_UBAT; |
|
- | 142 | break; |
|
- | 143 | case 7: |
|
- | 144 | UBat = (3 * UBat + ADC / 3) / 4; |
|
- | 145 | kanal = AD_ACC_Z; |
|
- | 146 | break; |
|
- | 147 | case 8: |
|
- | 148 | AdWertAccHoch = (signed int) ADC - NeutralAccZ; |
|
- | 149 | if(AdWertAccHoch > 1) |
|
- | 150 | { |
|
- | 151 | if(NeutralAccZ < 750) |
|
- | 152 | { |
|
- | 153 | NeutralAccZ += 0.02; |
|
- | 154 | if(modell_fliegt < 500) NeutralAccZ += 0.1; |
|
- | 155 | } |
|
- | 156 | } |
|
- | 157 | else if(AdWertAccHoch < -1) |
|
- | 158 | { |
|
- | 159 | if(NeutralAccZ > 550) |
|
- | 160 | { |
|
- | 161 | NeutralAccZ-= 0.02; |
|
- | 162 | if(modell_fliegt < 500) NeutralAccZ -= 0.1; |
|
- | 163 | } |
|
- | 164 | } |
|
- | 165 | messanzahl_AccHoch = 1; |
|
- | 166 | Aktuell_az = ADC; |
|
- | 167 | Mess_Integral_Hoch += AdWertAccHoch; // Integrieren |
|
- | 168 | Mess_Integral_Hoch -= Mess_Integral_Hoch / 1024; // dämfen |
|
- | 169 | kanal = AD_DRUCK; |
|
- | 170 | break; |
|
- | 171 | // "case 8:" fehlt hier absichtlich |
|
- | 172 | case 10: |
|
- | 173 | nick1 += ADC; |
|
- | 174 | kanal = AD_ROLL; |
|
- | 175 | break; |
|
- | 176 | case 11: |
|
- | 177 | roll1 += ADC; |
|
- | 178 | kanal = AD_GIER; |
|
- | 179 | break; |
|
- | 180 | case 12: |
|
- | 181 | if(PlatinenVersion == 10) AdWertGier = (ADC + gier1 + 1) / 2; |
|
- | 182 | else |
|
- | 183 | if(PlatinenVersion == 20) AdWertGier = 2047 - (ADC + gier1); |
|
- | 184 | else AdWertGier = (ADC + gier1); |
|
- | 185 | kanal = AD_ACC_Y; |
|
- | 186 | break; |
|
- | 187 | case 13: |
|
- | 188 | Aktuell_ay = NeutralAccY - ADC; |
|
- | 189 | AdWertAccRoll = (Aktuell_ay + accy); |
|
- | 190 | kanal = AD_ACC_X; |
|
- | 191 | break; |
|
- | 192 | case 14: |
|
- | 193 | Aktuell_ax = ADC - NeutralAccX; |
|
- | 194 | AdWertAccNick = (Aktuell_ax + accx); |
|
- | 195 | kanal = AD_NICK; |
|
- | 196 | break; |
|
- | 197 | case 15: |
|
- | 198 | nick1 += ADC; |
|
- | 199 | AdWertNick = nick1 / 2; |
|
- | 200 | nick_filter = (nick_filter + 4 * nick1) / 2; |
|
- | 201 | if(PlatinenVersion == 10) { AdWertNick /= 2;nick_filter /=2;} |
|
- | 202 | HiResNick = nick_filter - 8 * AdNeutralNick; |
|
- | 203 | AdWertNickFilter = (AdWertNickFilter + HiResNick) / 2; |
|
- | 204 | // DebugOut.Analog[21] = AdWertNickFilter / 4; |
|
- | 205 | kanal = AD_ROLL; |
|
- | 206 | break; |
|
- | 207 | case 16: |
|
- | 208 | roll1 += ADC; |
|
- | 209 | AdWertRoll = roll1 / 2; |
|
- | 210 | roll_filter = (roll_filter + 4 * roll1) / 2; |
|
- | 211 | if(PlatinenVersion == 10) { AdWertRoll /= 2;roll_filter /=2;} |
|
- | 212 | HiResRoll = roll_filter - 8 * AdNeutralRoll; |
|
- | 213 | AdWertRollFilter = (AdWertRollFilter + HiResRoll) / 2; |
|
- | 214 | // DebugOut.Analog[22] = AdWertRollFilter / 4; |
|
- | 215 | kanal = AD_DRUCK; |
|
- | 216 | break; |
|
- | 217 | case 17: |
|
- | 218 | state = 0; |
|
- | 219 | AdReady = 1; |
|
- | 220 | ZaehlMessungen++; |
|
- | 221 | // "break" fehlt hier absichtlich |
|
- | 222 | case 9: |
|
- | 223 | tmpLuftdruck += ADC; |
|
- | 224 | if(++messanzahl_Druck >= 5) |
|
- | 225 | { |
|
- | 226 | tmpLuftdruck /= 2; |
|
- | 227 | MessLuftdruck = ADC; |
|
- | 228 | messanzahl_Druck = 0; |
|
- | 229 | HoeheD = (31 * HoeheD + (int) Parameter_Luftdruck_D * (int)(255 * ExpandBaro + StartLuftdruck - tmpLuftdruck - HoehenWert))/32; // D-Anteil = neuerWert - AlterWert |
|
- | 230 | DebugOut.Analog[24] = 255 * ExpandBaro + StartLuftdruck - tmpLuftdruck; |
|
- | 231 | DebugOut.Analog[23] = HoeheD; |
|
- | 232 | Luftdruck = (tmpLuftdruck + 7 * Luftdruck + 4) / 8; |
|
- | 233 | HoehenWert = 255 * ExpandBaro + StartLuftdruck - Luftdruck; |
|
- | 234 | tmpLuftdruck /= 2; |
|
- | 235 | } |
|
- | 236 | kanal = AD_NICK; |
|
- | 237 | break; |
|
- | 238 | default: |
|
- | 239 | kanal = 0; state = 0; kanal = AD_NICK; |
|
- | 240 | break; |
|
- | 241 | } |
|
- | 242 | ADMUX = kanal; |
|
- | 243 | if(state != 0) ANALOG_ON; |
|
- | 244 | } |
|
- | 245 | ||
- | 246 | ||
- | 247 | ||
81 | 248 | /* |
|
82 | //####################################################################################### |
249 | //####################################################################################### |
83 | // |
250 | // |
84 | SIGNAL(SIG_ADC) |
251 | SIGNAL(SIG_ADC) |
85 | //####################################################################################### |
252 | //####################################################################################### |
86 | { |
253 | { |
87 | static unsigned char kanal=0,state = 0; |
254 | static unsigned char kanal=0,state = 0; |
88 | static signed int gier1, roll1, nick1; |
255 | static signed int gier1, roll1, nick1; |
89 | static signed long nick_filter, roll_filter; |
256 | static signed long nick_filter, roll_filter; |
90 | static signed int accy, accx; |
257 | static signed int accy, accx; |
91 | switch(state++) |
258 | switch(state++) |
92 | { |
259 | { |
93 | case 0: |
260 | case 0: |
94 | nick1 = ADC; |
261 | nick1 = ADC; |
95 | kanal = AD_ROLL; |
262 | kanal = AD_ROLL; |
96 | break; |
263 | break; |
97 | case 1: |
264 | case 1: |
98 | roll1 = ADC; |
265 | roll1 = ADC; |
99 | kanal = AD_GIER; |
266 | kanal = AD_GIER; |
100 | break; |
267 | break; |
101 | case 2: |
268 | case 2: |
102 | gier1 = ADC; |
269 | gier1 = ADC; |
103 | kanal = AD_ACC_Y; |
270 | kanal = AD_ACC_Y; |
104 | break; |
271 | break; |
105 | case 3: |
272 | case 3: |
106 | Aktuell_ay = NeutralAccY - ADC; |
273 | Aktuell_ay = NeutralAccY - ADC; |
107 | accy = Aktuell_ay; |
274 | accy = Aktuell_ay; |
108 | kanal = AD_NICK; |
275 | kanal = AD_NICK; |
109 | break; |
276 | break; |
110 | case 4: |
277 | case 4: |
111 | nick1 += ADC; |
278 | nick1 += ADC; |
112 | kanal = AD_ROLL; |
279 | kanal = AD_ROLL; |
113 | break; |
280 | break; |
114 | case 5: |
281 | case 5: |
115 | roll1 += ADC; |
282 | roll1 += ADC; |
116 | kanal = AD_ACC_Z; |
283 | kanal = AD_ACC_Z; |
117 | break; |
284 | break; |
118 | case 6: |
285 | case 6: |
119 | AdWertAccHoch = (signed int) ADC - NeutralAccZ; |
286 | AdWertAccHoch = (signed int) ADC - NeutralAccZ; |
120 | if(AdWertAccHoch > 1) |
287 | if(AdWertAccHoch > 1) |
121 | { |
288 | { |
122 | if(NeutralAccZ < 750) |
289 | if(NeutralAccZ < 750) |
123 | { |
290 | { |
124 | NeutralAccZ += 0.02; |
291 | NeutralAccZ += 0.02; |
125 | if(modell_fliegt < 500) NeutralAccZ += 0.1; |
292 | if(modell_fliegt < 500) NeutralAccZ += 0.1; |
126 | } |
293 | } |
127 | } |
294 | } |
128 | else if(AdWertAccHoch < -1) |
295 | else if(AdWertAccHoch < -1) |
129 | { |
296 | { |
130 | if(NeutralAccZ > 550) |
297 | if(NeutralAccZ > 550) |
131 | { |
298 | { |
132 | NeutralAccZ-= 0.02; |
299 | NeutralAccZ-= 0.02; |
133 | if(modell_fliegt < 500) NeutralAccZ -= 0.1; |
300 | if(modell_fliegt < 500) NeutralAccZ -= 0.1; |
134 | } |
301 | } |
135 | } |
302 | } |
136 | messanzahl_AccHoch = 1; |
303 | messanzahl_AccHoch = 1; |
137 | Aktuell_az = ADC; |
304 | Aktuell_az = ADC; |
138 | Mess_Integral_Hoch += AdWertAccHoch; // Integrieren |
305 | Mess_Integral_Hoch += AdWertAccHoch; // Integrieren |
139 | Mess_Integral_Hoch -= Mess_Integral_Hoch / 1024; // dämfen |
306 | Mess_Integral_Hoch -= Mess_Integral_Hoch / 1024; // dämfen |
140 | kanal = AD_NICK; |
307 | kanal = AD_NICK; |
141 | break; |
308 | break; |
142 | case 7: |
309 | case 7: |
143 | nick1 += ADC; |
310 | nick1 += ADC; |
144 | kanal = AD_ROLL; |
311 | kanal = AD_ROLL; |
145 | break; |
312 | break; |
146 | case 8: |
313 | case 8: |
147 | roll1 += ADC; |
314 | roll1 += ADC; |
148 | kanal = AD_ACC_X; |
315 | kanal = AD_ACC_X; |
149 | break; |
316 | break; |
150 | case 9: |
317 | case 9: |
151 | Aktuell_ax = ADC - NeutralAccX; |
318 | Aktuell_ax = ADC - NeutralAccX; |
152 | accx = Aktuell_ax; |
319 | accx = Aktuell_ax; |
153 | kanal = AD_GIER; |
320 | kanal = AD_GIER; |
154 | break; |
321 | break; |
155 | case 10: |
322 | case 10: |
156 | gier1 += ADC; |
323 | gier1 += ADC; |
157 | kanal = AD_NICK; |
324 | kanal = AD_NICK; |
158 | break; |
325 | break; |
159 | case 11: |
326 | case 11: |
160 | nick1 += ADC; |
327 | nick1 += ADC; |
161 | kanal = AD_ROLL; |
328 | kanal = AD_ROLL; |
162 | break; |
329 | break; |
163 | case 12: |
330 | case 12: |
164 | roll1 += ADC; |
331 | roll1 += ADC; |
165 | kanal = AD_UBAT; |
332 | kanal = AD_UBAT; |
166 | break; |
333 | break; |
167 | case 13: |
334 | case 13: |
168 | UBat = (3 * UBat + ADC / 3) / 4;//(UBat + ((ADC * 39) / 256) + 19) / 2; |
335 | UBat = (3 * UBat + ADC / 3) / 4;//(UBat + ((ADC * 39) / 256) + 19) / 2; |
169 | kanal = AD_ACC_Y; |
336 | kanal = AD_ACC_Y; |
170 | break; |
337 | break; |
171 | case 14: |
338 | case 14: |
172 | Aktuell_ay = NeutralAccY - ADC; |
339 | Aktuell_ay = NeutralAccY - ADC; |
173 | accy += Aktuell_ay; |
340 | accy += Aktuell_ay; |
174 | kanal = AD_NICK; |
341 | kanal = AD_NICK; |
175 | break; |
342 | break; |
176 | case 15: |
343 | case 15: |
177 | nick1 += ADC; |
344 | nick1 += ADC; |
178 | kanal = AD_ROLL; |
345 | kanal = AD_ROLL; |
179 | break; |
346 | break; |
180 | case 16: |
347 | case 16: |
181 | roll1 += ADC; |
348 | roll1 += ADC; |
182 | kanal = AD_ACC_X; |
349 | kanal = AD_ACC_X; |
183 | break; |
350 | break; |
184 | case 17: |
351 | case 17: |
185 | Aktuell_ax = ADC - NeutralAccX; |
352 | Aktuell_ax = ADC - NeutralAccX; |
186 | accx += Aktuell_ax; |
353 | accx += Aktuell_ax; |
187 | kanal = AD_NICK; |
354 | kanal = AD_NICK; |
188 | break; |
355 | break; |
189 | case 18: |
356 | case 18: |
190 | nick1 += ADC; |
357 | nick1 += ADC; |
191 | kanal = AD_ROLL; |
358 | kanal = AD_ROLL; |
192 | break; |
359 | break; |
193 | case 19: |
360 | case 19: |
194 | roll1 += ADC; |
361 | roll1 += ADC; |
195 | kanal = AD_GIER; |
362 | kanal = AD_GIER; |
196 | break; |
363 | break; |
197 | case 20: |
364 | case 20: |
198 | gier1 += ADC; |
365 | gier1 += ADC; |
199 | kanal = AD_ACC_Y; |
366 | kanal = AD_ACC_Y; |
200 | break; |
367 | break; |
201 | case 21: |
368 | case 21: |
202 | Aktuell_ay = NeutralAccY - ADC; |
369 | Aktuell_ay = NeutralAccY - ADC; |
203 | accy += Aktuell_ay; |
370 | accy += Aktuell_ay; |
204 | kanal = AD_NICK; |
371 | kanal = AD_NICK; |
205 | break; |
372 | break; |
206 | case 22: |
373 | case 22: |
207 | nick1 += ADC; |
374 | nick1 += ADC; |
208 | kanal = AD_ROLL; |
375 | kanal = AD_ROLL; |
209 | break; |
376 | break; |
210 | case 23: |
377 | case 23: |
211 | roll1 += ADC; |
378 | roll1 += ADC; |
212 | kanal = AD_DRUCK; |
379 | kanal = AD_DRUCK; |
213 | break; |
380 | break; |
214 | case 24: |
381 | case 24: |
215 | tmpLuftdruck += ADC; |
382 | tmpLuftdruck += ADC; |
216 | if(++messanzahl_Druck >= 5) |
383 | if(++messanzahl_Druck >= 5) |
217 | { |
384 | { |
218 | MessLuftdruck = ADC; |
385 | MessLuftdruck = ADC; |
219 | messanzahl_Druck = 0; |
386 | messanzahl_Druck = 0; |
220 | HoeheD = (7 * HoeheD + (int) Parameter_Luftdruck_D * (int)(255 * ExpandBaro + StartLuftdruck - tmpLuftdruck - HoehenWert)) / 8; // D-Anteil = neuerWert - AlterWert |
387 | HoeheD = (7 * HoeheD + (int) Parameter_Luftdruck_D * (int)(255 * ExpandBaro + StartLuftdruck - tmpLuftdruck - HoehenWert)) / 8; // D-Anteil = neuerWert - AlterWert |
221 | Luftdruck = (tmpLuftdruck + 3 * Luftdruck) / 4; |
388 | Luftdruck = (tmpLuftdruck + 3 * Luftdruck) / 4; |
222 | HoehenWert = 255 * ExpandBaro + StartLuftdruck - Luftdruck; |
389 | HoehenWert = 255 * ExpandBaro + StartLuftdruck - Luftdruck; |
223 | tmpLuftdruck = 0; |
390 | tmpLuftdruck = 0; |
224 | } |
391 | } |
225 | kanal = AD_NICK; |
392 | kanal = AD_NICK; |
226 | break; |
393 | break; |
227 | case 25: |
394 | case 25: |
228 | nick1 += ADC; |
395 | nick1 += ADC; |
229 | kanal = AD_ROLL; |
396 | kanal = AD_ROLL; |
230 | break; |
397 | break; |
231 | case 26: |
398 | case 26: |
232 | roll1 += ADC; |
399 | roll1 += ADC; |
233 | kanal = AD_ACC_X; |
400 | kanal = AD_ACC_X; |
234 | break; |
401 | break; |
235 | case 27: |
402 | case 27: |
236 | Aktuell_ax = ADC - NeutralAccX; |
403 | Aktuell_ax = ADC - NeutralAccX; |
237 | accx += Aktuell_ax; |
404 | accx += Aktuell_ax; |
238 | kanal = AD_GIER; |
405 | kanal = AD_GIER; |
239 | break; |
406 | break; |
240 | case 28: |
407 | case 28: |
241 | if(PlatinenVersion == 10) AdWertGier = (ADC + gier1 + 2) / 4; |
408 | if(PlatinenVersion == 10) AdWertGier = (ADC + gier1 + 2) / 4; |
242 | else |
409 | else |
243 | if(PlatinenVersion == 20) AdWertGier = 2047 - (ADC + gier1 + 1) / 2; |
410 | if(PlatinenVersion == 20) AdWertGier = 2047 - (ADC + gier1 + 1) / 2; |
244 | else AdWertGier = (ADC + gier1 + 1) / 2; |
411 | else AdWertGier = (ADC + gier1 + 1) / 2; |
245 | kanal = AD_NICK; |
412 | kanal = AD_NICK; |
246 | break; |
413 | break; |
247 | case 29: |
414 | case 29: |
248 | nick1 += ADC; |
415 | nick1 += ADC; |
249 | kanal = AD_ROLL; |
416 | kanal = AD_ROLL; |
250 | break; |
417 | break; |
251 | case 30: |
418 | case 30: |
252 | roll1 += ADC; |
419 | roll1 += ADC; |
253 | kanal = AD_ACC_Y; |
420 | kanal = AD_ACC_Y; |
254 | break; |
421 | break; |
255 | case 31: |
422 | case 31: |
256 | Aktuell_ay = NeutralAccY - ADC; |
423 | Aktuell_ay = NeutralAccY - ADC; |
257 | AdWertAccRoll = (Aktuell_ay + accy); |
424 | AdWertAccRoll = (Aktuell_ay + accy); |
258 | kanal = AD_NICK; |
425 | kanal = AD_NICK; |
259 | break; |
426 | break; |
260 | case 32: |
427 | case 32: |
261 | AdWertNick = (ADC + nick1 + 3) / 5; |
428 | AdWertNick = (ADC + nick1 + 3) / 5; |
262 | nick_filter = (long) (1 * (long) nick_filter + 4 * (long)(ADC + nick1) + 1) / 2; |
429 | nick_filter = (long) (1 * (long) nick_filter + 4 * (long)(ADC + nick1) + 1) / 2; |
263 | if(PlatinenVersion == 10) { AdWertNick /= 2;nick_filter /=2;} |
430 | if(PlatinenVersion == 10) { AdWertNick /= 2;nick_filter /=2;} |
264 | HiResNick = nick_filter - 20 * AdNeutralNick; |
431 | HiResNick = nick_filter - 20 * AdNeutralNick; |
265 | AdWertNickFilter = (long)(3L * (long)AdWertNickFilter + HiResNick + 2) / 4; |
432 | AdWertNickFilter = (long)(3L * (long)AdWertNickFilter + HiResNick + 2) / 4; |
266 | DebugOut.Analog[21] = AdWertNickFilter / 4; |
433 | DebugOut.Analog[21] = AdWertNickFilter / 4; |
267 | kanal = AD_ROLL; |
434 | kanal = AD_ROLL; |
268 | break; |
435 | break; |
269 | case 33: |
436 | case 33: |
270 | AdWertRoll = (ADC + roll1 + 3) / 5; |
437 | AdWertRoll = (ADC + roll1 + 3) / 5; |
271 | roll_filter = (long)(1 * (long)roll_filter + 4 * (long)(ADC + roll1) + 1) / 2; |
438 | roll_filter = (long)(1 * (long)roll_filter + 4 * (long)(ADC + roll1) + 1) / 2; |
272 | if(PlatinenVersion == 10) { AdWertRoll /= 2;roll_filter /=2;} |
439 | if(PlatinenVersion == 10) { AdWertRoll /= 2;roll_filter /=2;} |
273 | HiResRoll = roll_filter - 20 * AdNeutralRoll; |
440 | HiResRoll = roll_filter - 20 * AdNeutralRoll; |
274 | AdWertRollFilter = (long)(3L * (long)AdWertRollFilter + HiResRoll + 2) / 4; |
441 | AdWertRollFilter = (long)(3L * (long)AdWertRollFilter + HiResRoll + 2) / 4; |
275 | DebugOut.Analog[22] = AdWertRollFilter / 4; |
442 | DebugOut.Analog[22] = AdWertRollFilter / 4; |
276 | kanal = AD_ACC_X; |
443 | kanal = AD_ACC_X; |
277 | break; |
444 | break; |
278 | case 34: |
445 | case 34: |
279 | Aktuell_ax = ADC - NeutralAccX; |
446 | Aktuell_ax = ADC - NeutralAccX; |
280 | AdWertAccNick = (Aktuell_ax + accx); |
447 | AdWertAccNick = (Aktuell_ax + accx); |
281 | kanal = AD_NICK; |
448 | kanal = AD_NICK; |
282 | state = 0; |
449 | state = 0; |
283 | AdReady = 1; |
450 | AdReady = 1; |
284 | ZaehlMessungen++; |
451 | ZaehlMessungen++; |
285 | break; |
452 | break; |
286 | default: |
453 | default: |
287 | kanal = 0; |
454 | kanal = 0; |
288 | state = 0; |
455 | state = 0; |
289 | break; |
456 | break; |
290 | } |
457 | } |
291 | ADMUX = kanal; |
458 | ADMUX = kanal; |
292 | if(state != 0) ANALOG_ON; |
459 | if(state != 0) ANALOG_ON; |
293 | } |
460 | } |
294 | 461 | */ |
|
295 | 462 |