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