Rev 21 | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
21 | user | 1 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
2 | // + Copyright (c) 04.2007 Holger Buss |
||
3 | // + only for non-profit use |
||
4 | // + www.MikroKopter.com |
||
5 | // + see the File "License.txt" for further Informations |
||
6 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
||
7 | |||
8 | #include "main.h" |
||
9 | |||
10 | volatile int Aktuell_Nick,Aktuell_Roll,Aktuell_Gier,Aktuell_ax, Aktuell_ay,Aktuell_az, UBat = 100; |
||
11 | volatile int AccumulateNick = 0, AccumulateRoll = 0, AccumulateGier = 0; |
||
12 | volatile int accumulate_AccRoll = 0,accumulate_AccNick = 0,accumulate_AccHoch = 0; |
||
13 | volatile char MessanzahlNick = 0, MessanzahlRoll = 0, MessanzahlGier = 0; |
||
14 | volatile char messanzahl_AccNick = 0, messanzahl_AccRoll = 0, messanzahl_AccHoch = 0; |
||
15 | volatile long Luftdruck = 32000; |
||
16 | volatile int StartLuftdruck; |
||
17 | volatile unsigned int MessLuftdruck = 1023; |
||
18 | unsigned char DruckOffsetSetting; |
||
19 | volatile int HoeheD = 0; |
||
20 | volatile char messanzahl_Druck; |
||
21 | volatile int tmpLuftdruck; |
||
22 | volatile unsigned int ZaehlMessungen = 0; |
||
23 | |||
24 | //####################################################################################### |
||
25 | // |
||
26 | void ADC_Init(void) |
||
27 | //####################################################################################### |
||
28 | { |
||
29 | ADMUX = 0;//Referenz ist extern |
||
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 |
||
32 | } |
||
33 | |||
34 | void SucheLuftruckOffset(void) |
||
35 | { |
||
36 | unsigned int off; |
||
37 | for(off=0; off < 250;off++) |
||
38 | { |
||
39 | OCR0A = off; |
||
40 | Delay_ms(50); |
||
41 | printf("."); |
||
42 | if(MessLuftdruck < 900) break; |
||
43 | } |
||
44 | DruckOffsetSetting = off; |
||
45 | Delay_ms(200); |
||
46 | } |
||
47 | |||
48 | |||
49 | //####################################################################################### |
||
50 | // |
||
51 | SIGNAL(SIG_ADC) |
||
52 | //####################################################################################### |
||
53 | { |
||
54 | static unsigned char kanal=0,state = 0; |
||
55 | signed int wert; |
||
56 | ANALOG_OFF; |
||
57 | switch(state++) |
||
58 | { |
||
59 | case 0: |
||
60 | wert = (signed int) AdNeutralGier - ADC; |
||
61 | AccumulateGier += wert; // |
||
62 | MessanzahlGier++; |
||
63 | Mess_Integral_Gier += wert;// / 16; |
||
64 | Mess_Integral_Gier2 += wert; |
||
65 | kanal = 1; |
||
66 | ZaehlMessungen++; |
||
67 | break; |
||
68 | case 1: |
||
69 | wert = (signed int) ADC - AdNeutralRoll; |
||
70 | Mess_IntegralRoll += wert; |
||
71 | Mess_IntegralRoll2 += wert; |
||
72 | if(ADC < 10) wert = -700; |
||
73 | if(ADC > 1000) wert = +700; |
||
74 | AccumulateRoll += wert; |
||
75 | MessanzahlRoll++; |
||
76 | kanal = 2; |
||
77 | break; |
||
78 | case 2: |
||
79 | wert = (signed int) ADC - AdNeutralNick; |
||
80 | Mess_IntegralNick += wert; |
||
81 | Mess_IntegralNick2 += wert; |
||
82 | if(ADC < 10) wert = -700; |
||
83 | if(ADC > 1000) wert = +700; |
||
84 | AccumulateNick += wert; |
||
85 | MessanzahlNick++; |
||
86 | kanal = 4; |
||
87 | break; |
||
88 | case 3: |
||
89 | UBat = (3 * UBat + ADC / 3) / 4;//(UBat + ((ADC * 39) / 256) + 19) / 2; |
||
90 | kanal = 6; |
||
91 | break; |
||
92 | case 4: |
||
93 | Aktuell_ay = NeutralAccY - ADC; |
||
94 | accumulate_AccRoll += Aktuell_ay; |
||
95 | messanzahl_AccRoll++; |
||
96 | kanal = 7; |
||
97 | break; |
||
98 | case 5: |
||
99 | Aktuell_ay = ADC - NeutralAccX; |
||
100 | accumulate_AccNick += Aktuell_ay; |
||
101 | messanzahl_AccNick++; |
||
102 | kanal = 5; |
||
103 | state = 6; |
||
104 | break; |
||
105 | case 6: |
||
106 | accumulate_AccHoch = (signed int) ADC - NeutralAccZ; |
||
107 | accumulate_AccHoch += abs(Aktuell_ay) / 4 + abs(Aktuell_ax) / 4; |
||
108 | if(accumulate_AccHoch > 1) |
||
109 | { |
||
110 | if(NeutralAccZ < 800) NeutralAccZ+= 0.02; |
||
111 | } |
||
112 | else if(accumulate_AccHoch < -1) |
||
113 | { |
||
114 | if(NeutralAccZ > 600) NeutralAccZ-= 0.02; |
||
115 | } |
||
116 | messanzahl_AccHoch = 1; |
||
117 | Aktuell_az = ADC; |
||
118 | Mess_Integral_Hoch += accumulate_AccHoch; // Integrieren |
||
119 | Mess_Integral_Hoch -= Mess_Integral_Hoch / 1024; // dämfen |
||
120 | // Mess_Integral_Hoch -= Mess_Integral_Hoch / 512; // dämfen |
||
121 | /* if(EE_Parameter.GlobalConfig & CFG_HOEHENREGELUNG) |
||
122 | { |
||
123 | kanal = 3; |
||
124 | state = 7; |
||
125 | } |
||
126 | else |
||
127 | { |
||
128 | kanal = 0; |
||
129 | state = 0; |
||
130 | }*/ |
||
131 | kanal = 3; |
||
132 | state = 7; |
||
133 | break; |
||
134 | case 7: |
||
135 | tmpLuftdruck += ADC; |
||
136 | if(++messanzahl_Druck >= 5) |
||
137 | { |
||
138 | MessLuftdruck = ADC; |
||
139 | messanzahl_Druck = 0; |
||
140 | HoeheD = (int)(StartLuftdruck - tmpLuftdruck - HoehenWert); // D-Anteil = neuerWert - AlterWert |
||
141 | Luftdruck = (tmpLuftdruck + 3 * Luftdruck) / 4; |
||
142 | HoehenWert = StartLuftdruck - Luftdruck; |
||
143 | tmpLuftdruck = 0; |
||
144 | } |
||
145 | kanal = 0; |
||
146 | state = 0; |
||
147 | break; |
||
148 | default: |
||
149 | kanal = 0; |
||
150 | state = 0; |
||
151 | break; |
||
152 | } |
||
153 | ADMUX = kanal; |
||
154 | ANALOG_ON; |
||
155 | } |