Subversion Repositories FlightCtrl

Rev

Rev 2367 | Rev 2370 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 2367 Rev 2369
1
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2
// + www.MikroKopter.com
2
// + www.MikroKopter.com
3
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
3
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
4
// + Software Nutzungsbedingungen (english version: see below)
4
// + Software Nutzungsbedingungen (english version: see below)
5
// + der Fa. HiSystems GmbH, Flachsmeerstrasse 2, 26802 Moormerland - nachfolgend Lizenzgeber genannt -
5
// + der Fa. HiSystems GmbH, Flachsmeerstrasse 2, 26802 Moormerland - nachfolgend Lizenzgeber genannt -
6
// + Der Lizenzgeber räumt dem Kunden ein nicht-ausschließliches, zeitlich und räumlich* unbeschränktes Recht ein, die im den
6
// + Der Lizenzgeber räumt dem Kunden ein nicht-ausschließliches, zeitlich und räumlich* unbeschränktes Recht ein, die im den
7
// + Mikrocontroller verwendete Firmware für die Hardware Flight-Ctrl, Navi-Ctrl, BL-Ctrl, MK3Mag & PC-Programm MikroKopter-Tool 
7
// + Mikrocontroller verwendete Firmware für die Hardware Flight-Ctrl, Navi-Ctrl, BL-Ctrl, MK3Mag & PC-Programm MikroKopter-Tool 
8
// + - nachfolgend Software genannt - nur für private Zwecke zu nutzen.
8
// + - nachfolgend Software genannt - nur für private Zwecke zu nutzen.
9
// + Der Einsatz dieser Software ist nur auf oder mit Produkten des Lizenzgebers zulässig.
9
// + Der Einsatz dieser Software ist nur auf oder mit Produkten des Lizenzgebers zulässig.
10
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
10
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
11
// + Die vom Lizenzgeber gelieferte Software ist urheberrechtlich geschützt. Alle Rechte an der Software sowie an sonstigen im
11
// + Die vom Lizenzgeber gelieferte Software ist urheberrechtlich geschützt. Alle Rechte an der Software sowie an sonstigen im
12
// + Rahmen der Vertragsanbahnung und Vertragsdurchführung überlassenen Unterlagen stehen im Verhältnis der Vertragspartner ausschließlich dem Lizenzgeber zu.
12
// + Rahmen der Vertragsanbahnung und Vertragsdurchführung überlassenen Unterlagen stehen im Verhältnis der Vertragspartner ausschließlich dem Lizenzgeber zu.
13
// + Die in der Software enthaltenen Copyright-Vermerke, Markenzeichen, andere Rechtsvorbehalte, Seriennummern sowie
13
// + Die in der Software enthaltenen Copyright-Vermerke, Markenzeichen, andere Rechtsvorbehalte, Seriennummern sowie
14
// + sonstige der Programmidentifikation dienenden Merkmale dürfen vom Kunden nicht verändert oder unkenntlich gemacht werden.
14
// + sonstige der Programmidentifikation dienenden Merkmale dürfen vom Kunden nicht verändert oder unkenntlich gemacht werden.
15
// + Der Kunde trifft angemessene Vorkehrungen für den sicheren Einsatz der Software. Er wird die Software gründlich auf deren
15
// + Der Kunde trifft angemessene Vorkehrungen für den sicheren Einsatz der Software. Er wird die Software gründlich auf deren
16
// + Verwendbarkeit zu dem von ihm beabsichtigten Zweck testen, bevor er diese operativ einsetzt.
16
// + Verwendbarkeit zu dem von ihm beabsichtigten Zweck testen, bevor er diese operativ einsetzt.
17
// + Die Haftung des Lizenzgebers wird - soweit gesetzlich zulässig - begrenzt in Höhe des typischen und vorhersehbaren
17
// + Die Haftung des Lizenzgebers wird - soweit gesetzlich zulässig - begrenzt in Höhe des typischen und vorhersehbaren
18
// + Schadens. Die gesetzliche Haftung bei Personenschäden und nach dem Produkthaftungsgesetz bleibt unberührt. Dem Lizenzgeber steht jedoch der Einwand 
18
// + Schadens. Die gesetzliche Haftung bei Personenschäden und nach dem Produkthaftungsgesetz bleibt unberührt. Dem Lizenzgeber steht jedoch der Einwand 
19
// + des Mitverschuldens offen.
19
// + des Mitverschuldens offen.
20
// + Der Kunde trifft angemessene Vorkehrungen für den Fall, dass die Software ganz oder teilweise nicht ordnungsgemäß arbeitet.
20
// + Der Kunde trifft angemessene Vorkehrungen für den Fall, dass die Software ganz oder teilweise nicht ordnungsgemäß arbeitet.
21
// + Er wird die Software gründlich auf deren Verwendbarkeit zu dem von ihm beabsichtigten Zweck testen, bevor er diese operativ einsetzt.
21
// + Er wird die Software gründlich auf deren Verwendbarkeit zu dem von ihm beabsichtigten Zweck testen, bevor er diese operativ einsetzt.
22
// + Der Kunde wird er seine Daten vor Einsatz der Software nach dem Stand der Technik sichern.
22
// + Der Kunde wird er seine Daten vor Einsatz der Software nach dem Stand der Technik sichern.
23
// + Der Kunde ist darüber unterrichtet, dass der Lizenzgeber seine Daten im zur Vertragsdurchführung erforderlichen Umfang
23
// + Der Kunde ist darüber unterrichtet, dass der Lizenzgeber seine Daten im zur Vertragsdurchführung erforderlichen Umfang
24
// + und auf Grundlage der Datenschutzvorschriften erhebt, speichert, verarbeitet und, sofern notwendig, an Dritte übermittelt.
24
// + und auf Grundlage der Datenschutzvorschriften erhebt, speichert, verarbeitet und, sofern notwendig, an Dritte übermittelt.
25
// + *) Die räumliche Nutzung bezieht sich nur auf den Einsatzort, nicht auf die Reichweite der programmierten Software.
25
// + *) Die räumliche Nutzung bezieht sich nur auf den Einsatzort, nicht auf die Reichweite der programmierten Software.
26
// + #### ENDE DER NUTZUNGSBEDINGUNGEN ####'
26
// + #### ENDE DER NUTZUNGSBEDINGUNGEN ####'
27
// +  Hinweis: Informationen über erweiterte Nutzungsrechte (wie z.B. Nutzung für nicht-private Zwecke) sind auf Anfrage per Email an info(@)hisystems.de verfügbar.
27
// +  Hinweis: Informationen über erweiterte Nutzungsrechte (wie z.B. Nutzung für nicht-private Zwecke) sind auf Anfrage per Email an info(@)hisystems.de verfügbar.
28
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
28
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
29
// + Software LICENSING TERMS
29
// + Software LICENSING TERMS
30
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
30
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
31
// + of HiSystems GmbH, Flachsmeerstrasse 2, 26802 Moormerland, Germany - the Licensor -
31
// + of HiSystems GmbH, Flachsmeerstrasse 2, 26802 Moormerland, Germany - the Licensor -
32
// + The Licensor grants the customer a non-exclusive license to use the microcontroller firmware of the Flight-Ctrl, Navi-Ctrl, BL-Ctrl, and MK3Mag hardware 
32
// + The Licensor grants the customer a non-exclusive license to use the microcontroller firmware of the Flight-Ctrl, Navi-Ctrl, BL-Ctrl, and MK3Mag hardware 
33
// + (the Software) exclusively for private purposes. The License is unrestricted with respect to time and territory*.
33
// + (the Software) exclusively for private purposes. The License is unrestricted with respect to time and territory*.
34
// + The Software may only be used with the Licensor's products.
34
// + The Software may only be used with the Licensor's products.
35
// + The Software provided by the Licensor is protected by copyright. With respect to the relationship between the parties to this
35
// + The Software provided by the Licensor is protected by copyright. With respect to the relationship between the parties to this
36
// + agreement, all rights pertaining to the Software and other documents provided during the preparation and execution of this
36
// + agreement, all rights pertaining to the Software and other documents provided during the preparation and execution of this
37
// + agreement shall be the property of the Licensor.
37
// + agreement shall be the property of the Licensor.
38
// + The information contained in the Software copyright notices, trademarks, other legal reservations, serial numbers and other
38
// + The information contained in the Software copyright notices, trademarks, other legal reservations, serial numbers and other
39
// + features that can be used to identify the program may not be altered or defaced by the customer.
39
// + features that can be used to identify the program may not be altered or defaced by the customer.
40
// + The customer shall be responsible for taking reasonable precautions
40
// + The customer shall be responsible for taking reasonable precautions
41
// + for the safe use of the Software. The customer shall test the Software thoroughly regarding its suitability for the
41
// + for the safe use of the Software. The customer shall test the Software thoroughly regarding its suitability for the
42
// + intended purpose before implementing it for actual operation. The Licensor's liability shall be limited to the extent of typical and
42
// + intended purpose before implementing it for actual operation. The Licensor's liability shall be limited to the extent of typical and
43
// + foreseeable damage to the extent permitted by law, notwithstanding statutory liability for bodily injury and product
43
// + foreseeable damage to the extent permitted by law, notwithstanding statutory liability for bodily injury and product
44
// + liability. However, the Licensor shall be entitled to the defense of contributory negligence.
44
// + liability. However, the Licensor shall be entitled to the defense of contributory negligence.
45
// + The customer will take adequate precautions in the case, that the software is not working properly. The customer will test
45
// + The customer will take adequate precautions in the case, that the software is not working properly. The customer will test
46
// + the software for his purpose before any operational usage. The customer will backup his data before using the software.
46
// + the software for his purpose before any operational usage. The customer will backup his data before using the software.
47
// + The customer understands that the Licensor collects, stores and processes, and, where required, forwards, customer data
47
// + The customer understands that the Licensor collects, stores and processes, and, where required, forwards, customer data
48
// + to third parties to the extent necessary for executing the agreement, subject to applicable data protection and privacy regulations.
48
// + to third parties to the extent necessary for executing the agreement, subject to applicable data protection and privacy regulations.
49
// + *) The territory aspect only refers to the place where the Software is used, not its programmed range.
49
// + *) The territory aspect only refers to the place where the Software is used, not its programmed range.
50
// + #### END OF LICENSING TERMS ####
50
// + #### END OF LICENSING TERMS ####
51
// + Note: For information on license extensions (e.g. commercial use), please contact us at info(@)hisystems.de.
51
// + Note: For information on license extensions (e.g. commercial use), please contact us at info(@)hisystems.de.
52
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
52
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
53
 
53
 
54
#include "main.h"
54
#include "main.h"
55
#include "eeprom.h"
55
#include "eeprom.h"
56
volatile int  Aktuell_Nick,Aktuell_Roll,Aktuell_Gier,Aktuell_ax, Aktuell_ay,Aktuell_az, UBat = 100;
56
volatile int  Aktuell_Nick,Aktuell_Roll,Aktuell_Gier,Aktuell_ax, Aktuell_ay,Aktuell_az, UBat = 100;
57
volatile int  AdWertNickFilter = 0, AdWertRollFilter = 0, AdWertGierFilter = 0;
57
volatile int  AdWertNickFilter = 0, AdWertRollFilter = 0, AdWertGierFilter = 0;
58
volatile int  HiResNick = 2500, HiResRoll = 2500;
58
volatile int  HiResNick = 2500, HiResRoll = 2500;
59
volatile int  AdWertNick = 0, AdWertRoll = 0, AdWertGier = 0;
59
volatile int  AdWertNick = 0, AdWertRoll = 0, AdWertGier = 0;
60
volatile int  AdWertAccRoll = 0,AdWertAccNick = 0,AdWertAccHoch = 0;
60
volatile int  AdWertAccRoll = 0,AdWertAccNick = 0,AdWertAccHoch = 0;
61
volatile long Luftdruck = 32000;
61
volatile long Luftdruck = 32000;
62
volatile long SummenHoehe = 0;
62
volatile long SummenHoehe = 0;
63
volatile long StartLuftdruck;
63
volatile long StartLuftdruck;
64
volatile unsigned int  MessLuftdruck = 1023;
64
volatile unsigned int  MessLuftdruck = 1023;
65
unsigned char DruckOffsetSetting;
65
unsigned char DruckOffsetSetting;
66
signed char ExpandBaro = 0;
66
signed char ExpandBaro = 0;
67
volatile int VarioMeter = 0;
67
volatile int VarioMeter = 0;
68
volatile unsigned int ZaehlMessungen = 0;
68
volatile unsigned int ZaehlMessungen = 0;
69
unsigned char AnalogOffsetNick = 115,AnalogOffsetRoll = 115,AnalogOffsetGier = 115;
69
unsigned char AnalogOffsetNick = 115,AnalogOffsetRoll = 115,AnalogOffsetGier = 115;
70
volatile unsigned char AdReady = 1;
70
volatile unsigned char AdReady = 1;
71
unsigned int BaroStep = 500;
71
unsigned int BaroStep = 500;
72
long ExpandBaroStep = 0;
72
long ExpandBaroStep = 0;
73
volatile long HoehenWertF = 0;
73
volatile long HoehenWertF = 0;
74
 
74
 
75
#if (defined(__AVR_ATmega1284__) || defined(__AVR_ATmega1284P__))
75
#if (defined(__AVR_ATmega1284__) || defined(__AVR_ATmega1284P__))
76
unsigned char CalAthmospheare = 16;
76
unsigned char CalAthmospheare = 16;
77
#endif
77
#endif
78
 
78
 
79
//#######################################################################################
79
//#######################################################################################
80
void ADC_Init(void)
80
void ADC_Init(void)
81
//#######################################################################################
81
//#######################################################################################
82
{
82
{
83
    ADMUX = 0;//Referenz ist extern
83
    ADMUX = 0;//Referenz ist extern
84
    ANALOG_ON;
84
    ANALOG_ON;
85
}
85
}
86
 
86
 
87
#define DESIRED_H_ADC 850
87
#define DESIRED_H_ADC 800
88
 
88
 
89
void CalcExpandBaroStep(void)
89
void CalcExpandBaroStep(void)
90
{
90
{
91
  if(ACC_AltitudeControl) ExpandBaroStep = BaroStep * (long)ExpandBaro;
91
  if(ACC_AltitudeControl) ExpandBaroStep = BaroStep * (long)ExpandBaro;
92
  else ExpandBaroStep = (16 * BaroStep) * (long)ExpandBaro - 4;
92
  else ExpandBaroStep = (16 * BaroStep) * (long)ExpandBaro - 4;
93
}
93
}
94
 
94
 
95
void SucheLuftruckOffset(void)
95
void SucheLuftruckOffset(void)
96
{
96
{
97
 unsigned int off;
97
 unsigned int off;
98
 ExpandBaro = 0;
98
 ExpandBaro = 0;
99
 CalcExpandBaroStep();
99
 CalcExpandBaroStep();
100
  off = GetParamByte(PID_PRESSURE_OFFSET);
100
  off = GetParamByte(PID_PRESSURE_OFFSET);
101
  if(off > 20) off -= 10;
101
  if(off < 240) off += 10;
102
  OCR0A = off;
102
  OCR0A = off;
103
  OCR0B = 255-off;
103
  OCR0B = 255-off;
104
  Delay_ms_Mess(150);
104
  Delay_ms_Mess(150);
105
  if(MessLuftdruck < DESIRED_H_ADC) off = 0;
105
  if(MessLuftdruck > DESIRED_H_ADC) off = 240;
106
  for(; off < 250;off++)
106
  for(; off > 5; off--)
107
   {
107
   {
108
   OCR0A = off;
108
    OCR0A = off;
109
   OCR0B = 255-off;
109
    OCR0B = 255-off;
110
   Delay_ms_Mess(100);
110
    Delay_ms_Mess(100);
111
   printf(".");
111
    printf(".");
112
   if(MessLuftdruck < DESIRED_H_ADC) break;
112
    if(MessLuftdruck > DESIRED_H_ADC) break;
113
   }
113
   }
114
   DruckOffsetSetting = off;
114
   DruckOffsetSetting = off;
115
   SetParamByte(PID_PRESSURE_OFFSET, off);
115
   SetParamByte(PID_PRESSURE_OFFSET, off);
116
 if((EE_Parameter.GlobalConfig & CFG_HOEHENREGELUNG) && (DruckOffsetSetting < 5 || DruckOffsetSetting >= 245)) VersionInfo.HardwareError[0] |= FC_ERROR0_PRESSURE;
116
 if((EE_Parameter.GlobalConfig & CFG_HOEHENREGELUNG) && (DruckOffsetSetting < 10 || DruckOffsetSetting >= 230)) VersionInfo.HardwareError[0] |= FC_ERROR0_PRESSURE;
117
 
117
 
118
#if (defined(__AVR_ATmega1284__) || defined(__AVR_ATmega1284P__))
118
#if (defined(__AVR_ATmega1284__) || defined(__AVR_ATmega1284P__))
119
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
119
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
120
// + correction of the altitude error in higher altitudes
120
// + correction of the altitude error in higher altitudes
121
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
121
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
122
 CalAthmospheare = 16;
122
 CalAthmospheare = 16;
123
 if(ACC_AltitudeControl)
123
 if(ACC_AltitudeControl)
124
  {
124
  {
125
   if(PlatinenVersion < 23) { if(off < 140) CalAthmospheare += (160 - off) / 26; }
125
   if(PlatinenVersion < 23) { if(off < 140) CalAthmospheare += (160 - off) / 26; }
126
   else { if(off < 170) CalAthmospheare += (188 - off) / 19; }
126
   else { if(off < 170) CalAthmospheare += (188 - off) / 19; }
127
  }
127
  }
128
 Luftdruck = MessLuftdruck * CalAthmospheare;
128
 Luftdruck = MessLuftdruck * CalAthmospheare;
129
#endif
129
#endif
130
 Delay_ms_Mess(300);
130
 Delay_ms_Mess(300);
131
}
131
}
132
 
132
 
133
 
133
 
134
void SucheGyroOffset(void)
134
void SucheGyroOffset(void)
135
{
135
{
136
 unsigned char i, ready = 0;
136
 unsigned char i, ready = 0;
137
 int timeout;
137
 int timeout;
138
 timeout = SetDelay(2000);
138
 timeout = SetDelay(2000);
139
 for(i=140; i != 0; i--)
139
 for(i=140; i != 0; i--)
140
  {
140
  {
141
   if(ready == 3 && i > 10) i = 9;
141
   if(ready == 3 && i > 10) i = 9;
142
   ready = 0;
142
   ready = 0;
143
   if(AdWertNick < 1020) AnalogOffsetNick--; else if(AdWertNick > 1030) AnalogOffsetNick++; else ready++;
143
   if(AdWertNick < 1020) AnalogOffsetNick--; else if(AdWertNick > 1030) AnalogOffsetNick++; else ready++;
144
   if(AdWertRoll < 1020) AnalogOffsetRoll--; else if(AdWertRoll > 1030) AnalogOffsetRoll++; else ready++;
144
   if(AdWertRoll < 1020) AnalogOffsetRoll--; else if(AdWertRoll > 1030) AnalogOffsetRoll++; else ready++;
145
   if(AdWertGier < 1020) AnalogOffsetGier--; else if(AdWertGier > 1030) AnalogOffsetGier++; else ready++;
145
   if(AdWertGier < 1020) AnalogOffsetGier--; else if(AdWertGier > 1030) AnalogOffsetGier++; else ready++;
146
   I2C_Start(TWI_STATE_GYRO_OFFSET_TX);
146
   I2C_Start(TWI_STATE_GYRO_OFFSET_TX);
147
   if(AnalogOffsetNick < 10)  { VersionInfo.HardwareError[0] |= FC_ERROR0_GYRO_NICK; AnalogOffsetNick = 10;}; if(AnalogOffsetNick > 245) { VersionInfo.HardwareError[0] |= FC_ERROR0_GYRO_NICK; AnalogOffsetNick = 245;};
147
   if(AnalogOffsetNick < 10)  { VersionInfo.HardwareError[0] |= FC_ERROR0_GYRO_NICK; AnalogOffsetNick = 10;}; if(AnalogOffsetNick > 245) { VersionInfo.HardwareError[0] |= FC_ERROR0_GYRO_NICK; AnalogOffsetNick = 245;};
148
   if(AnalogOffsetRoll < 10)  { VersionInfo.HardwareError[0] |= FC_ERROR0_GYRO_ROLL; AnalogOffsetRoll = 10;}; if(AnalogOffsetRoll > 245) { VersionInfo.HardwareError[0] |= FC_ERROR0_GYRO_ROLL; AnalogOffsetRoll = 245;};
148
   if(AnalogOffsetRoll < 10)  { VersionInfo.HardwareError[0] |= FC_ERROR0_GYRO_ROLL; AnalogOffsetRoll = 10;}; if(AnalogOffsetRoll > 245) { VersionInfo.HardwareError[0] |= FC_ERROR0_GYRO_ROLL; AnalogOffsetRoll = 245;};
149
   if(AnalogOffsetGier < 10)  { VersionInfo.HardwareError[0] |= FC_ERROR0_GYRO_YAW;  AnalogOffsetGier = 10;}; if(AnalogOffsetGier > 245) { VersionInfo.HardwareError[0] |= FC_ERROR0_GYRO_YAW;  AnalogOffsetGier = 245;};
149
   if(AnalogOffsetGier < 10)  { VersionInfo.HardwareError[0] |= FC_ERROR0_GYRO_YAW;  AnalogOffsetGier = 10;}; if(AnalogOffsetGier > 245) { VersionInfo.HardwareError[0] |= FC_ERROR0_GYRO_YAW;  AnalogOffsetGier = 245;};
150
   while(twi_state) if(CheckDelay(timeout)) {printf("\n\r DAC or I2C ERROR! Check I2C, 3Vref, DAC and BL-Ctrl"); break;}
150
   while(twi_state) if(CheckDelay(timeout)) {printf("\n\r DAC or I2C ERROR! Check I2C, 3Vref, DAC and BL-Ctrl"); break;}
151
   AdReady = 0;
151
   AdReady = 0;
152
   ANALOG_ON;
152
   ANALOG_ON;
153
   while(!AdReady);
153
   while(!AdReady);
154
   if(i<10) Delay_ms_Mess(10);
154
   if(i<10) Delay_ms_Mess(10);
155
  }
155
  }
156
   Delay_ms_Mess(70);
156
   Delay_ms_Mess(70);
157
}
157
}
158
 
158
 
159
/*
159
/*
160
0  n
160
0  n
161
1  r
161
1  r
162
2     g
162
2     g
163
3     y
163
3     y
164
4     x
164
4     x
165
5  n
165
5  n
166
6  r
166
6  r
167
7     u
167
7     u
168
8     z
168
8     z
169
9     L
169
9     L
170
10 n
170
10 n
171
11 r
171
11 r
172
12    g
172
12    g
173
13    y
173
13    y
174
14    x
174
14    x
175
15 n
175
15 n
176
16 r
176
16 r
177
17    L
177
17    L
178
*/
178
*/
179
 
179
 
180
 
180
 
181
//#######################################################################################
181
//#######################################################################################
182
//
182
//
183
ISR(ADC_vect)
183
ISR(ADC_vect)
184
//#######################################################################################
184
//#######################################################################################
185
{
185
{
186
    static unsigned char kanal=0,state = 0;
186
    static unsigned char kanal=0,state = 0;
187
        static signed int subcount = 0;
187
        static signed int subcount = 0;
188
    static signed int gier1, roll1, nick1, nick_filter, roll_filter;
188
    static signed int gier1, roll1, nick1, nick_filter, roll_filter;
189
        static signed int accy, accx;
189
        static signed int accy, accx;
190
        static long tmpLuftdruck = 0;
190
        static long tmpLuftdruck = 0;
191
        static char messanzahl_Druck = 0;
191
        static char messanzahl_Druck = 0;
192
    switch(state++)
192
    switch(state++)
193
        {
193
        {
194
        case 0:
194
        case 0:
195
            nick1 = ADC;
195
            nick1 = ADC;
196
            kanal = AD_ROLL;
196
            kanal = AD_ROLL;
197
            break;
197
            break;
198
        case 1:
198
        case 1:
199
            roll1 = ADC;
199
            roll1 = ADC;
200
                    kanal = AD_GIER;
200
                    kanal = AD_GIER;
201
            break;
201
            break;
202
        case 2:
202
        case 2:
203
            gier1 = ADC;
203
            gier1 = ADC;
204
            kanal = AD_ACC_Y;
204
            kanal = AD_ACC_Y;
205
            break;
205
            break;
206
        case 3:
206
        case 3:
207
            Aktuell_ay = NeutralAccY - ADC;
207
            Aktuell_ay = NeutralAccY - ADC;
208
            accy = Aktuell_ay;
208
            accy = Aktuell_ay;
209
                    kanal = AD_ACC_X;
209
                    kanal = AD_ACC_X;
210
            break;
210
            break;
211
        case 4:
211
        case 4:
212
            Aktuell_ax = ADC - NeutralAccX;
212
            Aktuell_ax = ADC - NeutralAccX;
213
            accx =  Aktuell_ax;
213
            accx =  Aktuell_ax;
214
            kanal = AD_NICK;
214
            kanal = AD_NICK;
215
            break;
215
            break;
216
        case 5:
216
        case 5:
217
            nick1 += ADC;
217
            nick1 += ADC;
218
            kanal = AD_ROLL;
218
            kanal = AD_ROLL;
219
            break;
219
            break;
220
        case 6:
220
        case 6:
221
            roll1 += ADC;
221
            roll1 += ADC;
222
            kanal = AD_UBAT;
222
            kanal = AD_UBAT;
223
            break;
223
            break;
224
        case 7:
224
        case 7:
225
#if (defined(__AVR_ATmega1284__) || defined(__AVR_ATmega1284P__))
225
#if (defined(__AVR_ATmega1284__) || defined(__AVR_ATmega1284P__))
226
            if(EE_Parameter.ExtraConfig & CFG_3_3V_REFERENCE) UBat = (3 * UBat + (11 * ADC) / 30) / 4; // there were some single FC2.1 with 3.3V reference
226
            if(EE_Parameter.ExtraConfig & CFG_3_3V_REFERENCE) UBat = (3 * UBat + (11 * ADC) / 30) / 4; // there were some single FC2.1 with 3.3V reference
227
                        else  
227
                        else  
228
#endif
228
#endif
229
                        UBat = (3 * UBat + ADC / 3) / 4;
229
                        UBat = (3 * UBat + ADC / 3) / 4;
230
                    kanal = AD_ACC_Z;
230
                    kanal = AD_ACC_Z;
231
            break;
231
            break;
232
       case 8:
232
       case 8:
233
                         Aktuell_az = ADC;
233
                         Aktuell_az = ADC;
234
                         AdWertAccHoch = Aktuell_az - NeutralAccZ - (int) NeutralAccZfine;
234
                         AdWertAccHoch = Aktuell_az - NeutralAccZ - (int) NeutralAccZfine;
235
                     if(!ACC_AltitudeControl) // The Offset must be corrected, because of the ACC-Drift from vibrations
235
                     if(!ACC_AltitudeControl) // The Offset must be corrected, because of the ACC-Drift from vibrations
236
                     {
236
                     {
237
                      if(AdWertAccHoch > 1)
237
                      if(AdWertAccHoch > 1)
238
               {
238
               {
239
                if(NeutralAccZ < 750)
239
                if(NeutralAccZ < 750)
240
                 {
240
                 {
241
                  subcount += 5;
241
                  subcount += 5;
242
                  if(modell_fliegt < 500) subcount += 10;
242
                  if(modell_fliegt < 500) subcount += 10;
243
                  if(subcount > 100) { NeutralAccZ++; subcount -= 100;}
243
                  if(subcount > 100) { NeutralAccZ++; subcount -= 100;}
244
                 }
244
                 }
245
               }
245
               }
246
               else if(AdWertAccHoch < -1)
246
               else if(AdWertAccHoch < -1)
247
               {
247
               {
248
                if(NeutralAccZ > 550)
248
                if(NeutralAccZ > 550)
249
                 {
249
                 {
250
                  subcount -= 5;
250
                  subcount -= 5;
251
                  if(modell_fliegt < 500) subcount -= 10;
251
                  if(modell_fliegt < 500) subcount -= 10;
252
                  if(subcount < -100) { NeutralAccZ--; subcount += 100;}
252
                  if(subcount < -100) { NeutralAccZ--; subcount += 100;}
253
                 }
253
                 }
254
               }
254
               }
255
             }
255
             }
256
#if (defined(__AVR_ATmega1284__) || defined(__AVR_ATmega1284P__))
256
#if (defined(__AVR_ATmega1284__) || defined(__AVR_ATmega1284P__))
257
                         else
257
                         else
258
                         if(CosAttitude > 8192 - 50) // horizontal leveled within 6°
258
                         if(CosAttitude > 8192 - 50) // horizontal leveled within 6°
259
                     {
259
                     {
260
                      if(AdWertAccHoch > 1)
260
                      if(AdWertAccHoch > 1)
261
               {
261
               {
262
                  if(++subcount > 5000)
262
                  if(++subcount > 5000)
263
                                   {
263
                                   {
264
                    if(NeutralAccZfine < 6) NeutralAccZfine++;
264
                    if(NeutralAccZfine < 6) NeutralAccZfine++;
265
                                        subcount -= 5000;
265
                                        subcount -= 5000;
266
                                   }
266
                                   }
267
               }
267
               }
268
               else
268
               else
269
                           if(AdWertAccHoch < -1)
269
                           if(AdWertAccHoch < -1)
270
               {
270
               {
271
                  if(--subcount < -5000)
271
                  if(--subcount < -5000)
272
                                   {
272
                                   {
273
                    if(NeutralAccZfine > -6) NeutralAccZfine--;
273
                    if(NeutralAccZfine > -6) NeutralAccZfine--;
274
                                        subcount += 5000;
274
                                        subcount += 5000;
275
                                   }
275
                                   }
276
               }
276
               }
277
             }
277
             }
278
#endif
278
#endif
279
            Mess_Integral_Hoch += AdWertAccHoch;      // Integrieren
279
            Mess_Integral_Hoch += AdWertAccHoch;      // Integrieren
280
            Mess_Integral_Hoch -= Mess_Integral_Hoch / 1024; // dämfen
280
            Mess_Integral_Hoch -= Mess_Integral_Hoch / 1024; // dämfen
281
                kanal = AD_DRUCK;
281
                kanal = AD_DRUCK;
282
            break;
282
            break;
283
   // "case 9:" fehlt hier absichtlich
283
   // "case 9:" fehlt hier absichtlich
284
        case 10:
284
        case 10:
285
            nick1 += ADC;
285
            nick1 += ADC;
286
            kanal = AD_ROLL;
286
            kanal = AD_ROLL;
287
            break;
287
            break;
288
        case 11:
288
        case 11:
289
            roll1 += ADC;
289
            roll1 += ADC;
290
                    kanal = AD_GIER;
290
                    kanal = AD_GIER;
291
            break;
291
            break;
292
        case 12:
292
        case 12:
293
            if(PlatinenVersion == 10)  AdWertGier = (ADC + gier1 + 1) / 2;
293
            if(PlatinenVersion == 10)  AdWertGier = (ADC + gier1 + 1) / 2;
294
            else
294
            else
295
            if(PlatinenVersion >= 20)  AdWertGier = 2047 - (ADC + gier1);
295
            if(PlatinenVersion >= 20)  AdWertGier = 2047 - (ADC + gier1);
296
                        else                                       AdWertGier = (ADC + gier1);
296
                        else                                       AdWertGier = (ADC + gier1);
297
            kanal = AD_ACC_Y;
297
            kanal = AD_ACC_Y;
298
            break;
298
            break;
299
        case 13:
299
        case 13:
300
            Aktuell_ay = NeutralAccY - ADC;
300
            Aktuell_ay = NeutralAccY - ADC;
301
            AdWertAccRoll = (Aktuell_ay + accy);
301
            AdWertAccRoll = (Aktuell_ay + accy);
302
            kanal = AD_ACC_X;
302
            kanal = AD_ACC_X;
303
            break;
303
            break;
304
        case 14:
304
        case 14:
305
            Aktuell_ax = ADC - NeutralAccX;
305
            Aktuell_ax = ADC - NeutralAccX;
306
            AdWertAccNick =  (Aktuell_ax + accx);
306
            AdWertAccNick =  (Aktuell_ax + accx);
307
            kanal = AD_NICK;
307
            kanal = AD_NICK;
308
            break;
308
            break;
309
        case 15:
309
        case 15:
310
            nick1 += ADC;
310
            nick1 += ADC;
311
            if(PlatinenVersion == 10) nick1 *= 2; else nick1 *= 4;
311
            if(PlatinenVersion == 10) nick1 *= 2; else nick1 *= 4;
312
            AdWertNick = nick1 / 8;
312
            AdWertNick = nick1 / 8;
313
            nick_filter = (nick_filter + nick1) / 2;
313
            nick_filter = (nick_filter + nick1) / 2;
314
            HiResNick = nick_filter - AdNeutralNick;
314
            HiResNick = nick_filter - AdNeutralNick;
315
            AdWertNickFilter = (AdWertNickFilter + HiResNick) / 2;
315
            AdWertNickFilter = (AdWertNickFilter + HiResNick) / 2;
316
            kanal = AD_ROLL;
316
            kanal = AD_ROLL;
317
            break;
317
            break;
318
        case 16:
318
        case 16:
319
            roll1 += ADC;
319
            roll1 += ADC;
320
            if(PlatinenVersion == 10) roll1 *= 2; else roll1 *= 4;
320
            if(PlatinenVersion == 10) roll1 *= 2; else roll1 *= 4;
321
            AdWertRoll = roll1 / 8;
321
            AdWertRoll = roll1 / 8;
322
            roll_filter = (roll_filter + roll1) / 2;
322
            roll_filter = (roll_filter + roll1) / 2;
323
            HiResRoll = roll_filter - AdNeutralRoll;
323
            HiResRoll = roll_filter - AdNeutralRoll;
324
            AdWertRollFilter = (AdWertRollFilter + HiResRoll) / 2;
324
            AdWertRollFilter = (AdWertRollFilter + HiResRoll) / 2;
325
                kanal = AD_DRUCK;
325
                kanal = AD_DRUCK;
326
            break;
326
            break;
327
        case 17:
327
        case 17:
328
#if (defined(__AVR_ATmega1284__) || defined(__AVR_ATmega1284P__))
328
#if (defined(__AVR_ATmega1284__) || defined(__AVR_ATmega1284P__))
329
                        if(ACC_AltitudeControl)                
329
                        if(ACC_AltitudeControl)                
330
                        {
330
                        {
331
                         HoehenWertF = (ACC_AltitudeFusion(0) + SA_FILTER/2)/SA_FILTER; // cm
331
                         HoehenWertF = (ACC_AltitudeFusion(0) + SA_FILTER/2)/SA_FILTER; // cm
332
            }
332
            }
333
                        else HoehenWertF = HoehenWert;
333
                        else HoehenWertF = HoehenWert;
334
#else 
334
#else 
335
                        HoehenWertF = HoehenWert;
335
                        HoehenWertF = HoehenWert;
336
#endif
336
#endif
337
                       
337
                       
338
            state = 0;
338
            state = 0;
339
                        AdReady = 1;
339
                        AdReady = 1;
340
            ZaehlMessungen++;
340
            ZaehlMessungen++;
341
            // "break" fehlt hier absichtlich
341
            // "break" fehlt hier absichtlich
342
        case 9:
342
        case 9:
343
                MessLuftdruck = ADC;
343
                MessLuftdruck = ADC;
344
#if (defined(__AVR_ATmega1284__) || defined(__AVR_ATmega1284P__))
344
#if (defined(__AVR_ATmega1284__) || defined(__AVR_ATmega1284P__))
345
                        if(ACC_AltitudeControl)                
345
                        if(ACC_AltitudeControl)                
346
                        {
346
                        {
347
//                              ExpandBaroStep = BaroStep * (long)ExpandBaro; // wird in fc.c aufgerufen
347
//                              ExpandBaroStep = BaroStep * (long)ExpandBaro; // wird in fc.c aufgerufen
348
//                              tmpLuftdruck = MessLuftdruck - BaroStep * (long)ExpandBaro;  // -523 counts per offset step
348
//                              tmpLuftdruck = MessLuftdruck - BaroStep * (long)ExpandBaro;  // -523 counts per offset step
349
                                tmpLuftdruck = MessLuftdruck - ExpandBaroStep;  // -523 counts per offset step
349
                                tmpLuftdruck = MessLuftdruck - ExpandBaroStep;  // -523 counts per offset step
350
                                Luftdruck -= Luftdruck / CalAthmospheare; // 16
350
                                Luftdruck -= Luftdruck / CalAthmospheare; // 16
351
                                Luftdruck += tmpLuftdruck;
351
                                Luftdruck += tmpLuftdruck;
352
                                HoehenWert = StartLuftdruck - Luftdruck;        // cm
352
                                HoehenWert = StartLuftdruck - Luftdruck;        // cm
353
                        }
353
                        }
354
                        else
354
                        else
355
#endif
355
#endif
356
            {   // old version (until FC V2.1)
356
            {   // old version (until FC V2.1)
357
                                tmpLuftdruck += MessLuftdruck;
357
                                tmpLuftdruck += MessLuftdruck;
358
                                if(++messanzahl_Druck >= 16) // war bis 0.86 "18"
358
                                if(++messanzahl_Druck >= 16) // war bis 0.86 "18"
359
                                {
359
                                {
360
                            signed int tmp;
360
                            signed int tmp;
361
//                              Luftdruck = (7 * Luftdruck + tmpLuftdruck - (16 * BaroStep) * (long)ExpandBaro + 4) / 8;  // -523.19 counts per 10 counts offset step
361
//                              Luftdruck = (7 * Luftdruck + tmpLuftdruck - (16 * BaroStep) * (long)ExpandBaro + 4) / 8;  // -523.19 counts per 10 counts offset step
362
//                              ExpandBaroStep = (16 * BaroStep) * (long)ExpandBaro - 4; // wird in fc.c aufgerufen
362
//                              ExpandBaroStep = (16 * BaroStep) * (long)ExpandBaro - 4; // wird in fc.c aufgerufen
363
                                Luftdruck = (7 * Luftdruck + tmpLuftdruck - ExpandBaroStep) / 8;  // -523.19 counts per 10 counts offset step
363
                                Luftdruck = (7 * Luftdruck + tmpLuftdruck - ExpandBaroStep) / 8;  // -523.19 counts per 10 counts offset step
364
                                HoehenWert = StartLuftdruck - Luftdruck;
364
                                HoehenWert = StartLuftdruck - Luftdruck;
365
                                SummenHoehe -= SummenHoehe/SM_FILTER;
365
                                SummenHoehe -= SummenHoehe/SM_FILTER;
366
                                SummenHoehe += HoehenWert;
366
                                SummenHoehe += HoehenWert;
367
                                tmp = (HoehenWert - SummenHoehe/SM_FILTER);
367
                                tmp = (HoehenWert - SummenHoehe/SM_FILTER);
368
                                if(tmp > 1024) tmp = 1024;      else if(tmp < -1024) tmp = -1024;
368
                                if(tmp > 1024) tmp = 1024;      else if(tmp < -1024) tmp = -1024;
369
                if(abs(VarioMeter) > 700) VarioMeter = (15 * VarioMeter + 8 * tmp)/16;
369
                if(abs(VarioMeter) > 700) VarioMeter = (15 * VarioMeter + 8 * tmp)/16;
370
                                else VarioMeter = (31 * VarioMeter + 8 * tmp)/32;
370
                                else VarioMeter = (31 * VarioMeter + 8 * tmp)/32;
371
                tmpLuftdruck /= 2;
371
                tmpLuftdruck /= 2;
372
                messanzahl_Druck = 16/2;
372
                messanzahl_Druck = 16/2;
373
                                }
373
                                }
374
                        }
374
                        }
375
            kanal = AD_NICK;
375
            kanal = AD_NICK;
376
            break;
376
            break;
377
        default:
377
        default:
378
            kanal = 0; state = 0; kanal = AD_NICK;
378
            kanal = 0; state = 0; kanal = AD_NICK;
379
            break;
379
            break;
380
        }
380
        }
381
    ADMUX = kanal;
381
    ADMUX = kanal;
382
    if(state != 0) ANALOG_ON;
382
    if(state != 0) ANALOG_ON;
383
}
383
}
384
 
384
 
385
 
385