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