Rev 966 | Go to most recent revision | Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
838 | MikeW | 1 | /* |
2 | Copyright 2008, by Michael Walter |
||
3 | |||
4 | All functions written by Michael Walter are free software and can be redistributed and/or modified under the terms of the GNU Lesser |
||
5 | General Public License as published by the Free Software Foundation. This program is distributed in the hope that it will be useful, but |
||
6 | WITHOUT ANY WARRANTY, without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
||
7 | See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public |
||
8 | License along with this program. If not, see <http://www.gnu.org/licenses/>. |
||
9 | |||
10 | Please note: The software is based on the framework provided by H. Buss and I. Busker in their Mikrokopter projekt. All functions that |
||
11 | are not written by Michael Walter are under the license by H. Buss and I. Busker (license_buss.txt) published by www.mikrokopter.de |
||
12 | unless it is stated otherwise. |
||
13 | */ |
||
14 | |||
15 | #include "main.h" |
||
16 | #include "KalmanFc.h" |
||
17 | |||
18 | int UBat = 100; |
||
19 | int AdWertNick = 0, AdWertRoll = 0, AdWertGier = 0; |
||
20 | int AdWertAccRoll = 0,AdWertAccNick = 0,AdWertAccHoch = 0; |
||
21 | int AdWertNick_Raw = 0, AdWertRoll_Raw = 0, AdWertGier_Raw = 0; |
||
22 | int AdWertAccRoll_Raw = 0,AdWertAccNick_Raw = 0,AdWertAccHoch_Raw = 0; |
||
23 | |||
24 | int AccumulatedACC_X = 0, AccumulatedACC_Y = 0, AccumulatedACC_Z = 0, AccumulatedAirPressure = 0; |
||
25 | int AccumulatedACC_X_cnt = 0, AccumulatedACC_Y_cnt = 0, AccumulatedACC_Z_cnt = 0, AccumulatedAirPressure_cnt = 0; |
||
26 | int AccumulatedRoll_X = 0, AccumulatedRoll_Y = 0, AccumulatedRoll_Z = 0; |
||
27 | int AccumulatedRoll_X_cnt = 0, AccumulatedRoll_Y_cnt = 0, AccumulatedRoll_Z_cnt = 0; |
||
28 | |||
29 | unsigned int AdWertAirPressure_Raw = 1023; |
||
30 | |||
31 | /* **************************************************************************** |
||
32 | Functionname: ADC_Init */ /*! |
||
33 | Description: |
||
34 | |||
35 | @return void |
||
36 | @pre - |
||
37 | @post - |
||
38 | @author H. Buss / I. Busker |
||
39 | **************************************************************************** */ |
||
40 | void ADC_Init(void) |
||
41 | { |
||
42 | ADMUX = 0;//Referenz ist extern |
||
43 | ADCSRA=(1<<ADEN)|(1<<ADSC)|(1<<ADATE)|(1<<ADPS2)|(1<<ADPS1)|(1<<ADPS0)|(1<<ADIE); |
||
44 | //Free Running Mode, Division Factor 128, Interrupt on |
||
45 | } |
||
46 | |||
47 | /* **************************************************************************** |
||
48 | Functionname: SucheLuftruckOffset */ /*! |
||
49 | Description: |
||
50 | |||
51 | @return void |
||
52 | @pre - |
||
53 | @post - |
||
54 | @author H. Buss / I. Busker |
||
55 | **************************************************************************** */ |
||
56 | void SucheLuftruckOffset(void) |
||
57 | { |
||
58 | unsigned int off; |
||
59 | off = eeprom_read_byte(&EEPromArray[EEPROM_ADR_LAST_OFFSET]); |
||
60 | if(off > 20) off -= 10; |
||
61 | OCR0A = off; |
||
62 | Delay_ms_Mess(100); |
||
63 | if(AdWertAirPressure_Raw < 850) off = 0; |
||
64 | for(; off < 250;off++) |
||
65 | { |
||
66 | OCR0A = off; |
||
67 | Delay_ms_Mess(50); |
||
68 | printf("."); |
||
69 | if(AdWertAirPressure_Raw < 900) break; |
||
70 | } |
||
71 | eeprom_write_byte(&EEPromArray[EEPROM_ADR_LAST_OFFSET], off); |
||
72 | Delay_ms_Mess(300); |
||
73 | } |
||
74 | |||
75 | /* **************************************************************************** |
||
76 | Functionname: SIGNAL */ /*! |
||
77 | Description: |
||
78 | |||
79 | @return void |
||
80 | @pre - |
||
81 | @post - |
||
82 | @author Michael Walter |
||
83 | **************************************************************************** */ |
||
84 | SIGNAL(SIG_ADC) |
||
85 | { |
||
86 | static unsigned char kanal=0,state = 0; |
||
87 | ANALOG_OFF; |
||
88 | switch(state++) |
||
89 | { |
||
90 | case 0: |
||
91 | AdWertGier = ADC; |
||
92 | AdWertGier_Raw = AdWertGier; |
||
93 | AccumulatedRoll_Z += (ADC - AdNeutralGier); |
||
94 | AccumulatedRoll_Z_cnt++; |
||
95 | kanal = 1; |
||
96 | break; |
||
97 | case 1: |
||
98 | AdWertRoll = ADC; |
||
99 | AdWertRoll_Raw = AdWertRoll; |
||
100 | AccumulatedRoll_X += (ADC - AdNeutralRoll); |
||
101 | AccumulatedRoll_X_cnt++; |
||
102 | kanal = 2; |
||
103 | break; |
||
104 | case 2: |
||
105 | AdWertNick = ADC; |
||
106 | AdWertNick_Raw = AdWertNick; |
||
107 | AccumulatedRoll_Y += (ADC - AdNeutralNick); |
||
108 | AccumulatedRoll_Y_cnt++; |
||
109 | kanal = 4; |
||
110 | break; |
||
111 | case 3: |
||
112 | UBat = (3 * UBat + ADC / 3) / 4; |
||
113 | kanal = 6; |
||
114 | break; |
||
115 | case 4: |
||
116 | AdWertAccRoll = NeutralAccY - ADC; |
||
117 | AdWertAccRoll_Raw = ADC; |
||
118 | AccumulatedACC_Y += (NeutralAccY - ADC); |
||
119 | AccumulatedACC_Y_cnt++; |
||
120 | kanal = 7; |
||
121 | break; |
||
122 | case 5: |
||
123 | AdWertAccNick = ADC - NeutralAccX; |
||
124 | AdWertAccNick_Raw = ADC; |
||
125 | AccumulatedACC_X += (ADC - NeutralAccX); |
||
126 | AccumulatedACC_X_cnt++; |
||
127 | kanal = 5; |
||
128 | break; |
||
129 | case 6: |
||
130 | AdWertAccHoch = (ADC - (NeutralAccX + NeutralAccY) / 2); |
||
131 | AdWertAccHoch_Raw = ADC; |
||
132 | AccumulatedACC_Z += (ADC - NeutralAccZ); |
||
133 | AccumulatedACC_Z_cnt++; |
||
134 | kanal = 3; |
||
135 | break; |
||
136 | case 7: |
||
137 | AdWertAirPressure_Raw = ADC; |
||
138 | AccumulatedAirPressure += ADC; |
||
139 | AccumulatedAirPressure_cnt++; |
||
140 | kanal = 0; |
||
141 | state = 0; |
||
142 | break; |
||
143 | default: |
||
144 | kanal = 0; |
||
145 | state = 0; |
||
146 | break; |
||
147 | } |
||
148 | ADMUX = kanal; |
||
149 | ANALOG_ON; |
||
150 | } |