Rev 1111 | Rev 1166 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 1111 | Rev 1155 | ||
---|---|---|---|
Line 4... | Line 4... | ||
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 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
Line 7... | Line 7... | ||
7 | 7 | ||
8 | #include "main.h" |
- | |
9 | 8 | #include "main.h" |
|
10 | 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; |
11 | volatile int AdWertNick = 0, AdWertRoll = 0, AdWertGier = 0; |
10 | volatile int AdWertNick = 0, AdWertRoll = 0, AdWertGier = 0; |
12 | volatile int AdWertAccRoll = 0,AdWertAccNick = 0,AdWertAccHoch = 0; |
11 | volatile int AdWertAccRoll = 0,AdWertAccNick = 0,AdWertAccHoch = 0; |
13 | volatile char MessanzahlNick = 0, MessanzahlRoll = 0, MessanzahlGier = 0; |
12 | volatile char MessanzahlNick = 0, MessanzahlRoll = 0, MessanzahlGier = 0; |
Line 21... | Line 20... | ||
21 | volatile char messanzahl_Druck; |
20 | volatile char messanzahl_Druck; |
22 | volatile int tmpLuftdruck; |
21 | volatile int tmpLuftdruck; |
23 | volatile unsigned int ZaehlMessungen = 0; |
22 | volatile unsigned int ZaehlMessungen = 0; |
24 | unsigned char AnalogOffsetNick = 115,AnalogOffsetRoll = 115,AnalogOffsetGier = 115; |
23 | unsigned char AnalogOffsetNick = 115,AnalogOffsetRoll = 115,AnalogOffsetGier = 115; |
25 | unsigned char GyroDefektN = 0,GyroDefektR = 0,GyroDefektG = 0; |
24 | unsigned char GyroDefektN = 0,GyroDefektR = 0,GyroDefektG = 0; |
- | 25 | unsigned char AdReady = 1; |
|
26 | //####################################################################################### |
26 | //####################################################################################### |
27 | // |
27 | // |
28 | void ADC_Init(void) |
28 | void ADC_Init(void) |
29 | //####################################################################################### |
29 | //####################################################################################### |
30 | { |
30 | { |
31 | ADMUX = 0;//Referenz ist extern |
31 | ADMUX = 0;//Referenz ist extern |
32 | ADCSRA=(1<<ADEN)|(1<<ADSC)|(1<<ADATE)|(1<<ADPS2)|(1<<ADPS1)|(1<<ADPS0)|(1<<ADIE); |
- | |
33 | //Free Running Mode, Division Factor 128, Interrupt on |
32 | ANALOG_ON; |
34 | } |
33 | } |
Line 35... | Line 34... | ||
35 | 34 | ||
36 | void SucheLuftruckOffset(void) |
35 | void SucheLuftruckOffset(void) |
37 | { |
36 | { |
Line 77... | Line 76... | ||
77 | if(i<10) Delay_ms_Mess(10); |
76 | if(i<10) Delay_ms_Mess(10); |
78 | } |
77 | } |
79 | Delay_ms_Mess(70); |
78 | Delay_ms_Mess(70); |
80 | } |
79 | } |
Line 81... | Line -... | ||
81 | - | ||
82 | 80 | ||
83 | //####################################################################################### |
81 | //####################################################################################### |
84 | // |
82 | // |
85 | SIGNAL(SIG_ADC) |
83 | SIGNAL(SIG_ADC) |
86 | //####################################################################################### |
84 | //####################################################################################### |
87 | { |
85 | { |
88 | static unsigned char kanal=0,state = 0; |
86 | static unsigned char kanal=0,state = 0; |
89 | static unsigned int gier1, roll1, nick1; |
87 | static unsigned int gier1, roll1, nick1, accy, accx; |
90 | ANALOG_OFF; |
88 | ANALOG_OFF; |
91 | switch(state++) |
89 | switch(state++) |
92 | { |
90 | { |
93 | case 0: |
91 | case 0: |
94 | gier1 = ADC; |
92 | gier1 = ADC; |
95 | kanal = 1; |
93 | kanal = AD_ROLL; |
96 | ZaehlMessungen++; |
94 | ZaehlMessungen++; |
97 | break; |
95 | break; |
98 | case 1: |
96 | case 1: |
99 | roll1 = ADC; |
97 | roll1 = ADC; |
100 | kanal = 2; |
98 | kanal = AD_NICK; |
101 | break; |
99 | break; |
102 | case 2: |
100 | case 2: |
103 | nick1 = ADC; |
101 | nick1 = ADC; |
104 | kanal = 4; |
102 | kanal = AD_ACC_Y; |
105 | break; |
103 | break; |
106 | case 3: |
104 | case 3: |
- | 105 | Aktuell_ay = NeutralAccY - ADC; |
|
107 | UBat = (3 * UBat + ADC / 3) / 4;//(UBat + ((ADC * 39) / 256) + 19) / 2; |
106 | accy = Aktuell_ay; |
108 | kanal = 6; |
107 | kanal = AD_ACC_X; |
109 | break; |
108 | break; |
110 | case 4: |
109 | case 4: |
111 | Aktuell_ay = NeutralAccY - ADC; |
110 | Aktuell_ax = ADC - NeutralAccX; |
112 | AdWertAccRoll = Aktuell_ay; |
111 | accx = Aktuell_ax; |
113 | kanal = 7; |
112 | kanal = AD_GIER; |
114 | break; |
113 | break; |
115 | case 5: |
- | |
116 | Aktuell_ax = ADC - NeutralAccX; |
114 | case 5: |
117 | AdWertAccNick = Aktuell_ax; |
115 | gier1 += ADC; |
118 | kanal = 0; |
116 | kanal = AD_ROLL; |
119 | break; |
117 | break; |
120 | case 6: |
- | |
121 | if(PlatinenVersion == 10) AdWertGier = (ADC + gier1) / 2; |
118 | case 6: |
122 | else |
- | |
123 | if(PlatinenVersion == 20) AdWertGier = 2047 - (ADC + gier1); |
- | |
124 | else AdWertGier = ADC + gier1; |
119 | roll1 += ADC; |
125 | kanal = 1; |
120 | kanal = AD_NICK; |
126 | break; |
121 | break; |
127 | case 7: |
- | |
128 | if(PlatinenVersion == 10) AdWertRoll = (ADC + roll1) / 2; |
122 | case 7: |
129 | else AdWertRoll = ADC + roll1; |
123 | nick1 += ADC; |
130 | kanal = 2; |
124 | kanal = AD_UBAT; |
131 | break; |
125 | break; |
132 | case 8: |
126 | case 8: |
133 | if(PlatinenVersion == 10) AdWertNick = (ADC + nick1) / 2; |
- | |
134 | else AdWertNick = ADC + nick1; |
- | |
135 | //AdWertNick = 0; |
- | |
136 | //AdWertNick += Poti2; |
127 | UBat = (3 * UBat + ADC / 3) / 4;//(UBat + ((ADC * 39) / 256) + 19) / 2; |
137 | kanal = 5; |
128 | kanal = AD_ACC_Z; |
138 | break; |
129 | break; |
139 | case 9: |
130 | case 9: |
140 | AdWertAccHoch = (signed int) ADC - NeutralAccZ; |
- | |
141 | // AdWertAccHoch += abs(Aktuell_ay) / 4 + abs(Aktuell_ax) / 4; |
131 | AdWertAccHoch = (signed int) ADC - NeutralAccZ; |
142 | if(AdWertAccHoch > 1) |
132 | if(AdWertAccHoch > 1) |
143 | { |
133 | { |
144 | if(NeutralAccZ < 750) |
134 | if(NeutralAccZ < 750) |
145 | { |
135 | { |
Line 157... | Line 147... | ||
157 | } |
147 | } |
158 | messanzahl_AccHoch = 1; |
148 | messanzahl_AccHoch = 1; |
159 | Aktuell_az = ADC; |
149 | Aktuell_az = ADC; |
160 | Mess_Integral_Hoch += AdWertAccHoch; // Integrieren |
150 | Mess_Integral_Hoch += AdWertAccHoch; // Integrieren |
161 | Mess_Integral_Hoch -= Mess_Integral_Hoch / 1024; // dämfen |
151 | Mess_Integral_Hoch -= Mess_Integral_Hoch / 1024; // dämfen |
162 | kanal = 3; |
152 | kanal = AD_GIER; |
163 | break; |
153 | break; |
164 | case 10: |
154 | case 10: |
- | 155 | gier1 += ADC; |
|
- | 156 | kanal = AD_ROLL; |
|
- | 157 | break; |
|
- | 158 | case 11: |
|
- | 159 | roll1 += ADC; |
|
- | 160 | kanal = AD_NICK; |
|
- | 161 | break; |
|
- | 162 | case 12: |
|
- | 163 | nick1 += ADC; |
|
- | 164 | kanal = AD_DRUCK; |
|
- | 165 | break; |
|
- | 166 | case 13: |
|
165 | tmpLuftdruck += ADC; |
167 | tmpLuftdruck += ADC; |
166 | if(++messanzahl_Druck >= 5) |
168 | if(++messanzahl_Druck >= 5) |
167 | { |
169 | { |
168 | MessLuftdruck = ADC; |
170 | MessLuftdruck = ADC; |
169 | messanzahl_Druck = 0; |
171 | messanzahl_Druck = 0; |
170 | HoeheD = (7 * HoeheD + (int) Parameter_Luftdruck_D * (int)(255 * ExpandBaro + StartLuftdruck - tmpLuftdruck - HoehenWert))/8; // D-Anteil = neuerWert - AlterWert |
172 | HoeheD = (7 * HoeheD + (int) Parameter_Luftdruck_D * (int)(255 * ExpandBaro + StartLuftdruck - tmpLuftdruck - HoehenWert))/8; // D-Anteil = neuerWert - AlterWert |
171 | Luftdruck = (tmpLuftdruck + 3 * Luftdruck) / 4; |
173 | Luftdruck = (tmpLuftdruck + 3 * Luftdruck) / 4; |
172 | HoehenWert = 255 * ExpandBaro + StartLuftdruck - Luftdruck; |
174 | HoehenWert = 255 * ExpandBaro + StartLuftdruck - Luftdruck; |
173 | tmpLuftdruck = 0; |
175 | tmpLuftdruck = 0; |
174 | } |
176 | } |
- | 177 | kanal = AD_ACC_Y; |
|
- | 178 | break; |
|
- | 179 | case 14: |
|
- | 180 | Aktuell_ay = NeutralAccY - ADC; |
|
- | 181 | AdWertAccRoll = (Aktuell_ay + accy); |
|
- | 182 | kanal = AD_ACC_X; |
|
- | 183 | break; |
|
- | 184 | case 15: |
|
- | 185 | Aktuell_ax = ADC - NeutralAccX; |
|
- | 186 | AdWertAccNick = (Aktuell_ax + accx); |
|
- | 187 | kanal = AD_GIER; |
|
- | 188 | break; |
|
- | 189 | case 16: |
|
- | 190 | if(PlatinenVersion == 10) AdWertGier = (ADC + gier1) / 4; |
|
- | 191 | else |
|
- | 192 | if(PlatinenVersion == 20) AdWertGier = 2047 - (ADC + gier1)/2; |
|
- | 193 | else AdWertGier = (ADC + gier1) / 2; |
|
175 | kanal = 0; |
194 | kanal = AD_ROLL; |
- | 195 | break; |
|
- | 196 | case 17: |
|
- | 197 | if(PlatinenVersion == 10) AdWertRoll = (ADC + roll1) / 4; |
|
- | 198 | else AdWertRoll = (ADC + roll1) / 2; |
|
- | 199 | kanal = AD_NICK; |
|
- | 200 | break; |
|
- | 201 | case 18: |
|
- | 202 | if(PlatinenVersion == 10) AdWertNick = (ADC + nick1) / 4; |
|
- | 203 | else AdWertNick = (ADC + nick1) / 2; |
|
- | 204 | kanal = AD_GIER; |
|
176 | state = 0; |
205 | state = 0; |
- | 206 | AdReady = 1; |
|
177 | break; |
207 | break; |
178 | default: |
208 | default: |
179 | kanal = 0; |
209 | kanal = 0; |
180 | state = 0; |
210 | state = 0; |
181 | break; |
211 | break; |