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