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