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