Rev 401 | Rev 515 | Go to most recent revision | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 401 | Rev 492 | ||
---|---|---|---|
1 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
1 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
2 | // + Copyright (c) 04.2007 Holger Buss |
2 | // + Copyright (c) 04.2007 Holger Buss |
3 | // + only for non-profit use |
3 | // + only for non-profit use |
4 | // + www.MikroKopter.com |
4 | // + www.MikroKopter.com |
5 | // + see the File "License.txt" for further Informations |
5 | // + see the File "License.txt" for further Informations |
6 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
6 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
7 | 7 | ||
8 | #include "main.h" |
8 | #include "main.h" |
9 | 9 | ||
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 AdWertNick = 0, AdWertRoll = 0, AdWertGier = 0; |
11 | volatile int AdWertNick = 0, AdWertRoll = 0, AdWertGier = 0; |
12 | volatile int AdWertAccRoll = 0,AdWertAccNick = 0,AdWertAccHoch = 0; |
12 | volatile int AdWertAccRoll = 0,AdWertAccNick = 0,AdWertAccHoch = 0; |
13 | volatile char MessanzahlNick = 0, MessanzahlRoll = 0, MessanzahlGier = 0; |
13 | volatile char MessanzahlNick = 0, MessanzahlRoll = 0, MessanzahlGier = 0; |
14 | volatile char messanzahl_AccNick = 0, messanzahl_AccRoll = 0, messanzahl_AccHoch = 0; |
14 | volatile char messanzahl_AccNick = 0, messanzahl_AccRoll = 0, 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 | volatile int HoeheD = 0; |
19 | volatile int HoeheD = 0; |
20 | volatile char messanzahl_Druck; |
20 | volatile char messanzahl_Druck; |
21 | volatile int tmpLuftdruck; |
21 | volatile int tmpLuftdruck; |
22 | volatile unsigned int ZaehlMessungen = 0; |
22 | volatile unsigned int ZaehlMessungen = 0; |
23 | 23 | ||
24 | //####################################################################################### |
24 | //####################################################################################### |
25 | // |
25 | // |
26 | void ADC_Init(void) |
26 | void ADC_Init(void) |
27 | //####################################################################################### |
27 | //####################################################################################### |
28 | { |
28 | { |
29 | ADMUX = 0;//Referenz ist extern |
29 | ADMUX = 0;//Referenz ist extern |
30 | ADCSRA=(1<<ADEN)|(1<<ADSC)|(1<<ADATE)|(1<<ADPS2)|(1<<ADPS1)|(1<<ADPS0)|(1<<ADIE); |
30 | ADCSRA=(1<<ADEN)|(1<<ADSC)|(1<<ADATE)|(1<<ADPS2)|(1<<ADPS1)|(1<<ADPS0)|(1<<ADIE); |
31 | //Free Running Mode, Division Factor 128, Interrupt on |
31 | //Free Running Mode, Division Factor 128, Interrupt on |
32 | } |
32 | } |
33 | 33 | ||
34 | void SucheLuftruckOffset(void) |
34 | void SucheLuftruckOffset(void) |
35 | { |
35 | { |
36 | unsigned int off; |
36 | unsigned int off; |
37 | off = eeprom_read_byte(&EEPromArray[EEPROM_ADR_LAST_OFFSET]); |
37 | off = eeprom_read_byte(&EEPromArray[EEPROM_ADR_LAST_OFFSET]); |
38 | if(off > 20) off -= 10; |
38 | if(off > 20) off -= 10; |
39 | OCR0A = off; |
39 | OCR0A = off; |
40 | Delay_ms_Mess(100); |
40 | Delay_ms_Mess(100); |
41 | if(MessLuftdruck < 850) off = 0; |
41 | if(MessLuftdruck < 850) off = 0; |
42 | for(; off < 250;off++) |
42 | for(; off < 250;off++) |
43 | { |
43 | { |
44 | OCR0A = off; |
44 | OCR0A = off; |
45 | Delay_ms_Mess(50); |
45 | Delay_ms_Mess(50); |
46 | printf("."); |
46 | printf("."); |
47 | if(MessLuftdruck < 900) break; |
47 | if(MessLuftdruck < 900) break; |
48 | } |
48 | } |
49 | eeprom_write_byte(&EEPromArray[EEPROM_ADR_LAST_OFFSET], off); |
49 | eeprom_write_byte(&EEPromArray[EEPROM_ADR_LAST_OFFSET], off); |
50 | DruckOffsetSetting = off; |
50 | DruckOffsetSetting = off; |
51 | Delay_ms_Mess(300); |
51 | Delay_ms_Mess(300); |
52 | } |
52 | } |
53 | 53 | ||
54 | 54 | ||
55 | //####################################################################################### |
55 | //####################################################################################### |
56 | // |
56 | // |
57 | SIGNAL(SIG_ADC) |
57 | SIGNAL(SIG_ADC) |
58 | //####################################################################################### |
58 | //####################################################################################### |
59 | { |
59 | { |
60 | static unsigned char kanal=0,state = 0; |
60 | static unsigned char kanal=0,state = 0; |
61 | static unsigned int gier1, roll1, nick1; |
61 | static unsigned int gier1, roll1, nick1; |
62 | ANALOG_OFF; |
62 | ANALOG_OFF; |
63 | switch(state++) |
63 | switch(state++) |
64 | { |
64 | { |
65 | case 0: |
65 | case 0: |
66 | gier1 = ADC; |
66 | gier1 = ADC; |
67 | kanal = 1; |
67 | kanal = 1; |
68 | ZaehlMessungen++; |
68 | ZaehlMessungen++; |
69 | break; |
69 | break; |
70 | case 1: |
70 | case 1: |
71 | roll1 = ADC; |
71 | roll1 = ADC; |
72 | kanal = 2; |
72 | kanal = 2; |
73 | break; |
73 | break; |
74 | case 2: |
74 | case 2: |
75 | nick1 = ADC; |
75 | nick1 = ADC; |
76 | kanal = 4; |
76 | kanal = 4; |
77 | break; |
77 | break; |
78 | case 3: |
78 | case 3: |
79 | UBat = (3 * UBat + ADC / 3) / 4;//(UBat + ((ADC * 39) / 256) + 19) / 2; |
79 | UBat = (3 * UBat + ADC / 3) / 4;//(UBat + ((ADC * 39) / 256) + 19) / 2; |
80 | kanal = 6; |
80 | kanal = 6; |
81 | break; |
81 | break; |
82 | case 4: |
82 | case 4: |
83 | Aktuell_ay = NeutralAccY - ADC; |
83 | Aktuell_ay = NeutralAccY - ADC; |
84 | AdWertAccRoll = Aktuell_ay; |
84 | AdWertAccRoll = Aktuell_ay; |
85 | kanal = 7; |
85 | kanal = 7; |
86 | break; |
86 | break; |
87 | case 5: |
87 | case 5: |
88 | Aktuell_ax = ADC - NeutralAccX; |
88 | Aktuell_ax = ADC - NeutralAccX; |
89 | AdWertAccNick = Aktuell_ax; |
89 | AdWertAccNick = Aktuell_ax; |
90 | kanal = 0; |
90 | kanal = 0; |
91 | break; |
91 | break; |
92 | case 6: |
92 | case 6: |
93 | if(PlatinenVersion == 10) AdWertGier = (ADC + gier1) / 2; |
93 | if(PlatinenVersion == 10) AdWertGier = (ADC + gier1) / 2; |
94 | else AdWertGier = ADC + gier1; |
94 | else AdWertGier = ADC + gier1; |
95 | kanal = 1; |
95 | kanal = 1; |
96 | break; |
96 | break; |
97 | case 7: |
97 | case 7: |
98 | if(PlatinenVersion == 10) AdWertRoll = (ADC + roll1) / 2; |
98 | if(PlatinenVersion == 10) AdWertRoll = (ADC + roll1) / 2; |
99 | else AdWertRoll = ADC + roll1; |
99 | else AdWertRoll = ADC + roll1; |
100 | kanal = 2; |
100 | kanal = 2; |
101 | break; |
101 | break; |
102 | case 8: |
102 | case 8: |
103 | if(PlatinenVersion == 10) AdWertNick = (ADC + nick1) / 2; |
103 | if(PlatinenVersion == 10) AdWertNick = (ADC + nick1) / 2; |
104 | else AdWertNick = ADC + nick1; |
104 | else AdWertNick = ADC + nick1; |
- | 105 | //AdWertNick = 0; |
|
- | 106 | //AdWertNick += Poti2; |
|
105 | kanal = 5; |
107 | kanal = 5; |
106 | break; |
108 | break; |
107 | case 9: |
109 | case 9: |
108 | AdWertAccHoch = (signed int) ADC - NeutralAccZ; |
110 | AdWertAccHoch = (signed int) ADC - NeutralAccZ; |
109 | AdWertAccHoch += abs(Aktuell_ay) / 4 + abs(Aktuell_ax) / 4; |
111 | AdWertAccHoch += abs(Aktuell_ay) / 4 + abs(Aktuell_ax) / 4; |
110 | if(AdWertAccHoch > 1) |
112 | if(AdWertAccHoch > 1) |
111 | { |
113 | { |
112 | if(NeutralAccZ < 800) NeutralAccZ+= 0.02; |
114 | if(NeutralAccZ < 800) NeutralAccZ+= 0.02; |
113 | } |
115 | } |
114 | else if(AdWertAccHoch < -1) |
116 | else if(AdWertAccHoch < -1) |
115 | { |
117 | { |
116 | if(NeutralAccZ > 600) NeutralAccZ-= 0.02; |
118 | if(NeutralAccZ > 600) NeutralAccZ-= 0.02; |
117 | } |
119 | } |
118 | messanzahl_AccHoch = 1; |
120 | messanzahl_AccHoch = 1; |
119 | Aktuell_az = ADC; |
121 | Aktuell_az = ADC; |
120 | Mess_Integral_Hoch += AdWertAccHoch; // Integrieren |
122 | Mess_Integral_Hoch += AdWertAccHoch; // Integrieren |
121 | Mess_Integral_Hoch -= Mess_Integral_Hoch / 1024; // dämfen |
123 | Mess_Integral_Hoch -= Mess_Integral_Hoch / 1024; // dämfen |
122 | kanal = 3; |
124 | kanal = 3; |
123 | break; |
125 | break; |
124 | case 10: |
126 | case 10: |
125 | tmpLuftdruck += ADC; |
127 | tmpLuftdruck += ADC; |
126 | if(++messanzahl_Druck >= 5) |
128 | if(++messanzahl_Druck >= 5) |
127 | { |
129 | { |
128 | MessLuftdruck = ADC; |
130 | MessLuftdruck = ADC; |
129 | messanzahl_Druck = 0; |
131 | messanzahl_Druck = 0; |
130 | HoeheD = (int)(StartLuftdruck - tmpLuftdruck - HoehenWert); // D-Anteil = neuerWert - AlterWert |
132 | HoeheD = (int)(StartLuftdruck - tmpLuftdruck - HoehenWert); // D-Anteil = neuerWert - AlterWert |
131 | Luftdruck = (tmpLuftdruck + 3 * Luftdruck) / 4; |
133 | Luftdruck = (tmpLuftdruck + 3 * Luftdruck) / 4; |
132 | HoehenWert = StartLuftdruck - Luftdruck; |
134 | HoehenWert = StartLuftdruck - Luftdruck; |
133 | tmpLuftdruck = 0; |
135 | tmpLuftdruck = 0; |
134 | } |
136 | } |
135 | kanal = 0; |
137 | kanal = 0; |
136 | state = 0; |
138 | state = 0; |
137 | break; |
139 | break; |
138 | default: |
140 | default: |
139 | kanal = 0; |
141 | kanal = 0; |
140 | state = 0; |
142 | state = 0; |
141 | break; |
143 | break; |
142 | } |
144 | } |
143 | ADMUX = kanal; |
145 | ADMUX = kanal; |
144 | if(state != 0) ANALOG_ON; |
146 | if(state != 0) ANALOG_ON; |
145 | } |
147 | } |
146 | 148 |