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