Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
889 | Nick666 | 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 AdWertNick = 0, AdWertRoll = 0, AdWertGier = 0; |
||
12 | volatile int AdWertAccRoll = 0,AdWertAccNick = 0,AdWertAccHoch = 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 unsigned int ZaehlMessungen = 0; |
||
21 | |||
22 | //####################################################################################### |
||
23 | // |
||
24 | void ADC_Init(void) |
||
25 | //####################################################################################### |
||
26 | { |
||
27 | ADMUX = 0;//Referenz ist extern |
||
28 | ADCSRA=(1<<ADEN)|(1<<ADSC)|(1<<ADPS2)|(1<<ADPS1)|(1<<ADPS0)|(1<<ADIE); |
||
29 | //Single Conversion, Division Factor 128, Interrupt on |
||
30 | } |
||
31 | |||
32 | void SucheLuftruckOffset(void) |
||
33 | { |
||
34 | unsigned int off; |
||
35 | off = eeprom_read_byte(&EEPromArray[EEPROM_ADR_LAST_OFFSET]); |
||
36 | if(off > 20) off -= 10; |
||
37 | OCR0A = off; |
||
38 | Delay_ms_Mess(100); |
||
39 | if(MessLuftdruck < 850) off = 0; |
||
40 | for(; off < 250;off++) |
||
41 | { |
||
42 | OCR0A = off; |
||
43 | Delay_ms_Mess(50); |
||
44 | printf("."); |
||
45 | if(MessLuftdruck < 900) break; |
||
46 | } |
||
47 | eeprom_write_byte(&EEPromArray[EEPROM_ADR_LAST_OFFSET], off); |
||
48 | DruckOffsetSetting = off; |
||
49 | Delay_ms_Mess(300); |
||
50 | } |
||
51 | |||
52 | |||
53 | //####################################################################################### |
||
54 | // |
||
55 | SIGNAL(SIG_ADC) |
||
56 | //####################################################################################### |
||
57 | { |
||
902 | Nick666 | 58 | static char messanzahl_Druck; |
59 | static int tmpLuftdruck; |
||
889 | Nick666 | 60 | static unsigned char state = 0; |
61 | static unsigned int gier1, roll1, nick1; |
||
62 | |||
63 | switch(state++) |
||
64 | { |
||
65 | case 0: |
||
66 | gier1 = ADC; |
||
67 | ADMUX = 1; |
||
68 | ZaehlMessungen++; |
||
69 | break; |
||
70 | case 1: |
||
71 | roll1 = ADC; |
||
72 | ADMUX = 2; |
||
73 | break; |
||
74 | case 2: |
||
75 | nick1 = ADC; |
||
76 | ADMUX = 4; |
||
77 | break; |
||
78 | case 3: |
||
79 | UBat = (3 * UBat + ADC / 3) / 4;//(UBat + ((ADC * 39) / 256) + 19) / 2; |
||
80 | ADMUX = 6; |
||
81 | break; |
||
82 | case 4: |
||
83 | Aktuell_ay = acc_neutral.Y - ADC; |
||
84 | AdWertAccRoll = Aktuell_ay; |
||
85 | ADMUX = 7; |
||
86 | break; |
||
87 | case 5: |
||
88 | Aktuell_ax = ADC - acc_neutral.X; |
||
89 | AdWertAccNick = Aktuell_ax; |
||
90 | ADMUX = 0; |
||
91 | break; |
||
92 | case 6: |
||
93 | if(PlatinenVersion == 10) AdWertGier = (ADC + gier1) / 2; |
||
94 | else AdWertGier = ADC + gier1; |
||
95 | ADMUX = 1; |
||
96 | break; |
||
97 | case 7: |
||
98 | if(PlatinenVersion == 10) AdWertRoll = (ADC + roll1) / 2; |
||
99 | else AdWertRoll = ADC + roll1; |
||
100 | ADMUX = 2; |
||
101 | break; |
||
102 | case 8: |
||
103 | if(PlatinenVersion == 10) AdWertNick = (ADC + nick1) / 2; |
||
902 | Nick666 | 104 | else AdWertNick = ADC + nick1; |
889 | Nick666 | 105 | ADMUX = 5; |
106 | break; |
||
107 | case 9: |
||
108 | AdWertAccHoch = (signed int) ADC - acc_neutral.Z; |
||
109 | // AdWertAccHoch += abs(Aktuell_ay) / 4 + abs(Aktuell_ax) / 4; |
||
110 | if(AdWertAccHoch > 1) |
||
111 | { |
||
112 | if(acc_neutral.Z < 750) |
||
113 | { |
||
114 | acc_neutral.Z += 0.02; |
||
115 | if(modell_fliegt < 500) acc_neutral.Z += 0.1; |
||
116 | } |
||
117 | } |
||
118 | else if(AdWertAccHoch < -1) |
||
119 | { |
||
120 | if(acc_neutral.Z > 550) |
||
121 | { |
||
122 | acc_neutral.Z-= 0.02; |
||
123 | if(modell_fliegt < 500) acc_neutral.Z -= 0.1; |
||
124 | } |
||
125 | } |
||
126 | messanzahl_AccHoch = 1; |
||
127 | Aktuell_az = ADC; |
||
128 | Mess_Integral_Hoch += AdWertAccHoch; // Integrieren |
||
902 | Nick666 | 129 | Mess_Integral_Hoch -= Mess_Integral_Hoch / 1024; // dämpfen |
889 | Nick666 | 130 | ADMUX = 3; |
131 | break; |
||
132 | case 10: |
||
133 | tmpLuftdruck += ADC; |
||
134 | if(++messanzahl_Druck >= 5) |
||
135 | { |
||
136 | MessLuftdruck = ADC; |
||
137 | messanzahl_Druck = 0; |
||
138 | HoeheD = (7 * HoeheD + (int) Parameter_Luftdruck_D * (int)(StartLuftdruck - tmpLuftdruck - HoehenWert))/8; // D-Anteil = neuerWert - AlterWert |
||
139 | Luftdruck = (tmpLuftdruck + 3 * Luftdruck) / 4; |
||
140 | HoehenWert = StartLuftdruck - Luftdruck; |
||
141 | tmpLuftdruck = 0; |
||
142 | } |
||
143 | ADMUX = 0; |
||
144 | state = 0; |
||
145 | break; |
||
146 | default: |
||
147 | ADMUX = 0; |
||
148 | state = 0; |
||
149 | break; |
||
150 | } |
||
893 | Nick666 | 151 | |
152 | if(state != 0) ADC_START; |
||
889 | Nick666 | 153 | } |