Subversion Repositories FlightCtrl

Rev

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

Rev 2426 Rev 2471
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 = 150;
56
volatile int  Aktuell_Nick,Aktuell_Roll,Aktuell_Gier,Aktuell_ax, Aktuell_ay,Aktuell_az, UBat = 150;
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
long HoehenWertF = 0;
-
 
74
long HoehenWert_Mess = 0;
74
#if (defined(__AVR_ATmega1284__) || defined(__AVR_ATmega1284P__))
75
#if (defined(__AVR_ATmega1284__) || defined(__AVR_ATmega1284P__))
-
 
76
long HoehenWertF_Mess = 0;
75
unsigned char CalAthmospheare = 16;
77
unsigned char CalAthmospheare = 16;
76
unsigned char AD_ACC_Y = 6;
78
unsigned char AD_ACC_Y = 6;
77
unsigned char AD_ACC_X = 7;
79
unsigned char AD_ACC_X = 7;
78
#endif
80
#endif
79
 
81
 
80
//#######################################################################################
82
//#######################################################################################
81
void ADC_Init(void)
83
void ADC_Init(void)
82
//#######################################################################################
84
//#######################################################################################
83
{
85
{
84
    ADMUX = 0;//Referenz ist extern
86
    ADMUX = 0;//Referenz ist extern
85
    ANALOG_ON;
87
    ANALOG_ON;
86
}
88
}
87
 
89
 
88
#define DESIRED_H_ADC 800
90
#define DESIRED_H_ADC 800
89
 
91
 
90
void CalcExpandBaroStep(void)
92
void CalcExpandBaroStep(void)
91
{
93
{
92
  if(ACC_AltitudeControl) ExpandBaroStep = BaroStep * (long)ExpandBaro;
94
  if(ACC_AltitudeControl) ExpandBaroStep = BaroStep * (long)ExpandBaro;
93
  else ExpandBaroStep = (16 * BaroStep) * (long)ExpandBaro - 4;
95
  else ExpandBaroStep = (16 * BaroStep) * (long)ExpandBaro - 4;
94
}
96
}
95
 
97
 
96
void SucheLuftruckOffset(void)
98
void SucheLuftruckOffset(void)
97
{
99
{
98
 unsigned int off;
100
 unsigned int off;
99
 ExpandBaro = 0;
101
 ExpandBaro = 0;
100
 CalcExpandBaroStep();
102
 CalcExpandBaroStep();
101
  off = GetParamByte(PID_PRESSURE_OFFSET);
103
  off = GetParamByte(PID_PRESSURE_OFFSET);
102
  if(off < 240) off += 10;
104
  if(off < 240) off += 10;
103
  OCR0A = off;
105
  OCR0A = off;
104
  OCR0B = 255-off;
106
  OCR0B = 255-off;
105
  Delay_ms_Mess(150);
107
  Delay_ms_Mess(150);
106
  if(MessLuftdruck > DESIRED_H_ADC) off = 240;
108
  if(MessLuftdruck > DESIRED_H_ADC) off = 240;
107
  for(; off > 5; off--)
109
  for(; off > 5; off--)
108
   {
110
   {
109
    OCR0A = off;
111
    OCR0A = off;
110
    OCR0B = 255-off;
112
    OCR0B = 255-off;
111
    Delay_ms_Mess(100);
113
    Delay_ms_Mess(100);
112
    printf(".");
114
    printf(".");
113
    if(MessLuftdruck > DESIRED_H_ADC) break;
115
    if(MessLuftdruck > DESIRED_H_ADC) break;
114
   }
116
   }
115
   DruckOffsetSetting = off;
117
   DruckOffsetSetting = off;
116
   SetParamByte(PID_PRESSURE_OFFSET, off);
118
   SetParamByte(PID_PRESSURE_OFFSET, off);
117
 if((EE_Parameter.GlobalConfig & CFG_HOEHENREGELUNG) && (DruckOffsetSetting < 10 || DruckOffsetSetting >= 230)) VersionInfo.HardwareError[0] |= FC_ERROR0_PRESSURE;
119
 if((EE_Parameter.GlobalConfig & CFG_HOEHENREGELUNG) && (DruckOffsetSetting < 10 || DruckOffsetSetting >= 230)) VersionInfo.HardwareError[0] |= FC_ERROR0_PRESSURE;
118
 
120
 
119
#if (defined(__AVR_ATmega1284__) || defined(__AVR_ATmega1284P__))
121
#if (defined(__AVR_ATmega1284__) || defined(__AVR_ATmega1284P__))
120
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
122
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
121
// + correction of the altitude error in higher altitudes
123
// + correction of the altitude error in higher altitudes
122
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
124
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
123
 CalAthmospheare = 16;
125
 CalAthmospheare = 16;
124
 if(ACC_AltitudeControl)
126
 if(ACC_AltitudeControl)
125
  {
127
  {
126
   if(PlatinenVersion < 23) { if(off < 140) CalAthmospheare += (160 - off) / 26; }
128
   if(PlatinenVersion < 23) { if(off < 140) CalAthmospheare += (160 - off) / 26; }
127
   else { if(off < 170) CalAthmospheare += (188 - off) / 19; }
129
   else { if(off < 170) CalAthmospheare += (188 - off) / 19; }
128
  }
130
  }
129
 Luftdruck = MessLuftdruck * CalAthmospheare;
131
 Luftdruck = MessLuftdruck * CalAthmospheare;
130
#endif
132
#endif
131
 Delay_ms_Mess(300);
133
 Delay_ms_Mess(300);
132
}
134
}
133
 
135
 
134
/*
136
/*
135
void SucheGyroOffset(void)
137
void SucheGyroOffset(void)
136
{
138
{
137
 unsigned char i, ready = 0;
139
 unsigned char i, ready = 0;
138
 int timeout;
140
 int timeout;
139
 timeout = SetDelay(2000);
141
 timeout = SetDelay(2000);
140
 for(i=140; i != 0; i--)
142
 for(i=140; i != 0; i--)
141
  {
143
  {
142
   if(ready == 3 && i > 10) i = 9;
144
   if(ready == 3 && i > 10) i = 9;
143
   ready = 0;
145
   ready = 0;
144
   if(AdWertNick < 1020) AnalogOffsetNick--; else if(AdWertNick > 1030) AnalogOffsetNick++; else ready++;
146
   if(AdWertNick < 1020) AnalogOffsetNick--; else if(AdWertNick > 1030) AnalogOffsetNick++; else ready++;
145
   if(AdWertRoll < 1020) AnalogOffsetRoll--; else if(AdWertRoll > 1030) AnalogOffsetRoll++; else ready++;
147
   if(AdWertRoll < 1020) AnalogOffsetRoll--; else if(AdWertRoll > 1030) AnalogOffsetRoll++; else ready++;
146
   if(AdWertGier < 1020) AnalogOffsetGier--; else if(AdWertGier > 1030) AnalogOffsetGier++; else ready++;
148
   if(AdWertGier < 1020) AnalogOffsetGier--; else if(AdWertGier > 1030) AnalogOffsetGier++; else ready++;
147
   I2C_Start(TWI_STATE_GYRO_OFFSET_TX);
149
   I2C_Start(TWI_STATE_GYRO_OFFSET_TX);
148
   if(AnalogOffsetNick < 10)  { VersionInfo.HardwareError[0] |= FC_ERROR0_GYRO_NICK; AnalogOffsetNick = 10;}; if(AnalogOffsetNick > 245) { VersionInfo.HardwareError[0] |= FC_ERROR0_GYRO_NICK; AnalogOffsetNick = 245;};
150
   if(AnalogOffsetNick < 10)  { VersionInfo.HardwareError[0] |= FC_ERROR0_GYRO_NICK; AnalogOffsetNick = 10;}; if(AnalogOffsetNick > 245) { VersionInfo.HardwareError[0] |= FC_ERROR0_GYRO_NICK; AnalogOffsetNick = 245;};
149
   if(AnalogOffsetRoll < 10)  { VersionInfo.HardwareError[0] |= FC_ERROR0_GYRO_ROLL; AnalogOffsetRoll = 10;}; if(AnalogOffsetRoll > 245) { VersionInfo.HardwareError[0] |= FC_ERROR0_GYRO_ROLL; AnalogOffsetRoll = 245;};
151
   if(AnalogOffsetRoll < 10)  { VersionInfo.HardwareError[0] |= FC_ERROR0_GYRO_ROLL; AnalogOffsetRoll = 10;}; if(AnalogOffsetRoll > 245) { VersionInfo.HardwareError[0] |= FC_ERROR0_GYRO_ROLL; AnalogOffsetRoll = 245;};
150
   if(AnalogOffsetGier < 10)  { VersionInfo.HardwareError[0] |= FC_ERROR0_GYRO_YAW;  AnalogOffsetGier = 10;}; if(AnalogOffsetGier > 245) { VersionInfo.HardwareError[0] |= FC_ERROR0_GYRO_YAW;  AnalogOffsetGier = 245;};
152
   if(AnalogOffsetGier < 10)  { VersionInfo.HardwareError[0] |= FC_ERROR0_GYRO_YAW;  AnalogOffsetGier = 10;}; if(AnalogOffsetGier > 245) { VersionInfo.HardwareError[0] |= FC_ERROR0_GYRO_YAW;  AnalogOffsetGier = 245;};
151
   while(twi_state) if(CheckDelay(timeout)) {printf("\n\r DAC or I2C ERROR! Check I2C, 3Vref, DAC and BL-Ctrl"); break;}
153
   while(twi_state) if(CheckDelay(timeout)) {printf("\n\r DAC or I2C ERROR! Check I2C, 3Vref, DAC and BL-Ctrl"); break;}
152
   AdReady = 0;
154
   AdReady = 0;
153
   ANALOG_ON;
155
   ANALOG_ON;
154
   while(!AdReady);
156
   while(!AdReady);
155
   if(i<10) Delay_ms_Mess(10);
157
   if(i<10) Delay_ms_Mess(10);
156
  }
158
  }
157
   Delay_ms_Mess(70);
159
   Delay_ms_Mess(70);
158
}
160
}
159
*/
161
*/
160
/*
162
/*
161
0  n
163
0  n
162
1  r
164
1  r
163
2     g
165
2     g
164
3     y
166
3     y
165
4     x
167
4     x
166
5  n
168
5  n
167
6  r
169
6  r
168
7     u
170
7     u
169
8     z
171
8     z
170
9     L
172
9     L
171
10 n
173
10 n
172
11 r
174
11 r
173
12    g
175
12    g
174
13    y
176
13    y
175
14    x
177
14    x
176
15 n
178
15 n
177
16 r
179
16 r
178
17    L
180
17    L
179
*/
181
*/
180
 
182
 
181
 
183
 
182
//#######################################################################################
184
//#######################################################################################
183
//
185
//
184
ISR(ADC_vect)
186
ISR(ADC_vect)
185
//#######################################################################################
187
//#######################################################################################
186
{
188
{
187
    static unsigned char kanal=0,state = 0;
189
    static unsigned char kanal=0,state = 0;
188
        static signed int subcount = 0;
190
        static signed int subcount = 0;
189
    static signed int gier1, roll1, nick1, nick_filter, roll_filter;
191
    static signed int gier1, roll1, nick1, nick_filter, roll_filter;
190
        static signed int accy, accx;
192
        static signed int accy, accx;
191
        static long tmpLuftdruck = 0;
193
        static long tmpLuftdruck = 0;
192
        static char messanzahl_Druck = 0;
194
        static char messanzahl_Druck = 0;
193
    switch(state++)
195
    switch(state++)
194
        {
196
        {
195
        case 0:
197
        case 0:
196
            nick1 = ADC;
198
            nick1 = ADC;
197
            kanal = AD_ROLL;
199
            kanal = AD_ROLL;
198
            break;
200
            break;
199
        case 1:
201
        case 1:
200
            roll1 = ADC;
202
            roll1 = ADC;
201
                    kanal = AD_GIER;
203
                    kanal = AD_GIER;
202
            break;
204
            break;
203
        case 2:
205
        case 2:
204
            gier1 = ADC;
206
            gier1 = ADC;
205
            kanal = AD_ACC_Y;
207
            kanal = AD_ACC_Y;
206
            break;
208
            break;
207
        case 3:
209
        case 3:
208
            Aktuell_ay = NeutralAccY - ADC;
210
            Aktuell_ay = NeutralAccY - ADC;
209
            accy = Aktuell_ay;
211
            accy = Aktuell_ay;
210
                    kanal = AD_ACC_X;
212
                    kanal = AD_ACC_X;
211
            break;
213
            break;
212
        case 4:
214
        case 4:
213
            Aktuell_ax = ADC - NeutralAccX;
215
            Aktuell_ax = ADC - NeutralAccX;
214
            accx =  Aktuell_ax;
216
            accx =  Aktuell_ax;
215
            kanal = AD_NICK;
217
            kanal = AD_NICK;
216
            break;
218
            break;
217
        case 5:
219
        case 5:
218
            nick1 += ADC;
220
            nick1 += ADC;
219
            kanal = AD_ROLL;
221
            kanal = AD_ROLL;
220
            break;
222
            break;
221
        case 6:
223
        case 6:
222
            roll1 += ADC;
224
            roll1 += ADC;
223
            kanal = AD_UBAT;
225
            kanal = AD_UBAT;
224
            break;
226
            break;
225
        case 7:
227
        case 7:
226
#if (defined(__AVR_ATmega1284__) || defined(__AVR_ATmega1284P__))
228
#if (defined(__AVR_ATmega1284__) || defined(__AVR_ATmega1284P__))
227
            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
229
            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
228
                        else  
230
                        else  
229
#endif
231
#endif
230
                         {
232
                         {
231
                          static unsigned int tmpVoltage = 0;
233
                          static unsigned int tmpVoltage = 0;
232
                          if(!tmpVoltage) tmpVoltage = (10 * ADC);
234
                          if(!tmpVoltage) tmpVoltage = (10 * ADC);
233
                          if(tmpVoltage <= (10 * ADC)) tmpVoltage += 2; else tmpVoltage -= 2;
235
                          if(tmpVoltage <= (10 * ADC)) tmpVoltage += 2; else tmpVoltage -= 2;
234
              UBat = tmpVoltage / 31;
236
              UBat = tmpVoltage / 31;
235
                         }
237
                         }
236
                    kanal = AD_ACC_Z;
238
                    kanal = AD_ACC_Z;
237
            break;
239
            break;
238
       case 8:
240
       case 8:
239
                         Aktuell_az = ADC;
241
                         Aktuell_az = ADC;
240
                         AdWertAccHoch = Aktuell_az - NeutralAccZ - (int) NeutralAccZfine;
242
                         AdWertAccHoch = Aktuell_az - NeutralAccZ - (int) NeutralAccZfine;
241
                     if(!ACC_AltitudeControl) // The Offset must be corrected, because of the ACC-Drift from vibrations
243
                     if(!ACC_AltitudeControl) // The Offset must be corrected, because of the ACC-Drift from vibrations
242
                     {
244
                     {
243
                      if(AdWertAccHoch > 1)
245
                      if(AdWertAccHoch > 1)
244
               {
246
               {
245
                if(NeutralAccZ < 750)
247
                if(NeutralAccZ < 750)
246
                 {
248
                 {
247
                  subcount += 5;
249
                  subcount += 5;
248
                  if(modell_fliegt < 500) subcount += 10;
250
                  if(modell_fliegt < 500) subcount += 10;
249
                  if(subcount > 100) { NeutralAccZ++; subcount -= 100;}
251
                  if(subcount > 100) { NeutralAccZ++; subcount -= 100;}
250
                 }
252
                 }
251
               }
253
               }
252
               else if(AdWertAccHoch < -1)
254
               else if(AdWertAccHoch < -1)
253
               {
255
               {
254
                if(NeutralAccZ > 550)
256
                if(NeutralAccZ > 550)
255
                 {
257
                 {
256
                  subcount -= 5;
258
                  subcount -= 5;
257
                  if(modell_fliegt < 500) subcount -= 10;
259
                  if(modell_fliegt < 500) subcount -= 10;
258
                  if(subcount < -100) { NeutralAccZ--; subcount += 100;}
260
                  if(subcount < -100) { NeutralAccZ--; subcount += 100;}
259
                 }
261
                 }
260
               }
262
               }
261
             }
263
             }
262
#if (defined(__AVR_ATmega1284__) || defined(__AVR_ATmega1284P__))
264
#if (defined(__AVR_ATmega1284__) || defined(__AVR_ATmega1284P__))
263
                         else
265
                         else
264
                         if(CosAttitude > 8192 - 50) // horizontal leveled within 6°
266
                         if(CosAttitude > 8192 - 50) // horizontal leveled within 6°
265
                     {
267
                     {
266
                      if(AdWertAccHoch > 1)
268
                      if(AdWertAccHoch > 1)
267
               {
269
               {
268
                  if(++subcount > 5000)
270
                  if(++subcount > 5000)
269
                                   {
271
                                   {
270
                    if(NeutralAccZfine < 6) NeutralAccZfine++;
272
                    if(NeutralAccZfine < 6) NeutralAccZfine++;
271
                                        subcount -= 5000;
273
                                        subcount -= 5000;
272
                                   }
274
                                   }
273
               }
275
               }
274
               else
276
               else
275
                           if(AdWertAccHoch < -1)
277
                           if(AdWertAccHoch < -1)
276
               {
278
               {
277
                  if(--subcount < -5000)
279
                  if(--subcount < -5000)
278
                                   {
280
                                   {
279
                    if(NeutralAccZfine > -6) NeutralAccZfine--;
281
                    if(NeutralAccZfine > -6) NeutralAccZfine--;
280
                                        subcount += 5000;
282
                                        subcount += 5000;
281
                                   }
283
                                   }
282
               }
284
               }
283
             }
285
             }
284
#endif
286
#endif
285
            Mess_Integral_Hoch += AdWertAccHoch;      // Integrieren
287
            Mess_Integral_Hoch += AdWertAccHoch;      // Integrieren
286
            Mess_Integral_Hoch -= Mess_Integral_Hoch / 1024; // dämfen
288
            Mess_Integral_Hoch -= Mess_Integral_Hoch / 1024; // dämfen
287
                kanal = AD_DRUCK;
289
                kanal = AD_DRUCK;
288
            break;
290
            break;
289
   // "case 9:" fehlt hier absichtlich
291
   // "case 9:" fehlt hier absichtlich
290
        case 10:
292
        case 10:
291
            nick1 += ADC;
293
            nick1 += ADC;
292
            kanal = AD_ROLL;
294
            kanal = AD_ROLL;
293
            break;
295
            break;
294
        case 11:
296
        case 11:
295
            roll1 += ADC;
297
            roll1 += ADC;
296
                    kanal = AD_GIER;
298
                    kanal = AD_GIER;
297
            break;
299
            break;
298
        case 12:
300
        case 12:
299
/*            if(PlatinenVersion == 10)  AdWertGier = (ADC + gier1 + 1) / 2;
301
/*            if(PlatinenVersion == 10)  AdWertGier = (ADC + gier1 + 1) / 2;
300
            else
302
            else
301
            if(PlatinenVersion >= 20)  AdWertGier = 2047 - (ADC + gier1);
303
            if(PlatinenVersion >= 20)  AdWertGier = 2047 - (ADC + gier1);
302
                        else                                       AdWertGier = (ADC + gier1);
304
                        else                                       AdWertGier = (ADC + gier1);
303
*/
305
*/
304
                        AdWertGier = 2047 - (ADC + gier1);
306
                        AdWertGier = 2047 - (ADC + gier1);
305
            kanal = AD_ACC_Y;
307
            kanal = AD_ACC_Y;
306
            break;
308
            break;
307
        case 13:
309
        case 13:
308
            Aktuell_ay = NeutralAccY - ADC;
310
            Aktuell_ay = NeutralAccY - ADC;
309
            AdWertAccRoll = (Aktuell_ay + accy);
311
            AdWertAccRoll = (Aktuell_ay + accy);
310
            kanal = AD_ACC_X;
312
            kanal = AD_ACC_X;
311
            break;
313
            break;
312
        case 14:
314
        case 14:
313
            Aktuell_ax = ADC - NeutralAccX;
315
            Aktuell_ax = ADC - NeutralAccX;
314
            AdWertAccNick =  (Aktuell_ax + accx);
316
            AdWertAccNick =  (Aktuell_ax + accx);
315
            kanal = AD_NICK;
317
            kanal = AD_NICK;
316
            break;
318
            break;
317
        case 15:
319
        case 15:
318
            nick1 += ADC;
320
            nick1 += ADC;
319
            //if(PlatinenVersion == 10) nick1 *= 2; else 
321
            //if(PlatinenVersion == 10) nick1 *= 2; else 
320
                        nick1 *= 4;
322
                        nick1 *= 4;
321
            AdWertNick = nick1 / 8;
323
            AdWertNick = nick1 / 8;
322
            nick_filter = (nick_filter + nick1) / 2;
324
            nick_filter = (nick_filter + nick1) / 2;
323
            HiResNick = nick_filter - AdNeutralNick;
325
            HiResNick = nick_filter - AdNeutralNick;
324
            AdWertNickFilter = (AdWertNickFilter + HiResNick) / 2;
326
            AdWertNickFilter = (AdWertNickFilter + HiResNick) / 2;
325
            kanal = AD_ROLL;
327
            kanal = AD_ROLL;
326
            break;
328
            break;
327
        case 16:
329
        case 16:
328
            roll1 += ADC;
330
            roll1 += ADC;
329
            //if(PlatinenVersion == 10) roll1 *= 2; else 
331
            //if(PlatinenVersion == 10) roll1 *= 2; else 
330
                        roll1 *= 4;
332
                        roll1 *= 4;
331
            AdWertRoll = roll1 / 8;
333
            AdWertRoll = roll1 / 8;
332
            roll_filter = (roll_filter + roll1) / 2;
334
            roll_filter = (roll_filter + roll1) / 2;
333
            HiResRoll = roll_filter - AdNeutralRoll;
335
            HiResRoll = roll_filter - AdNeutralRoll;
334
            AdWertRollFilter = (AdWertRollFilter + HiResRoll) / 2;
336
            AdWertRollFilter = (AdWertRollFilter + HiResRoll) / 2;
335
                kanal = AD_DRUCK;
337
                kanal = AD_DRUCK;
336
            break;
338
            break;
337
        case 17:
339
        case 17:
338
#if (defined(__AVR_ATmega1284__) || defined(__AVR_ATmega1284P__))
340
#if (defined(__AVR_ATmega1284__) || defined(__AVR_ATmega1284P__))
339
                        if(ACC_AltitudeControl)                
341
                        if(ACC_AltitudeControl)                
340
                        {
342
                        {
341
                         HoehenWertF = (ACC_AltitudeFusion(0) + SA_FILTER/2)/SA_FILTER; // cm
343
                         HoehenWertF_Mess = (ACC_AltitudeFusion(0) + SA_FILTER/2)/SA_FILTER;    // cm
342
            }
344
            }
343
                        else HoehenWertF = HoehenWert;
345
                        else HoehenWertF_Mess = HoehenWert;
344
#else 
-
 
345
                        HoehenWertF = HoehenWert;
-
 
346
#endif
346
#endif
347
                       
-
 
348
            state = 0;
347
            state = 0;
349
                        AdReady = 1;
348
                        AdReady = 1;
350
            ZaehlMessungen++;
349
            ZaehlMessungen++;
351
            // "break" fehlt hier absichtlich
350
            // "break" fehlt hier absichtlich
352
        case 9:
351
        case 9:
353
                MessLuftdruck = ADC;
352
                MessLuftdruck = ADC;
354
#if (defined(__AVR_ATmega1284__) || defined(__AVR_ATmega1284P__))
353
#if (defined(__AVR_ATmega1284__) || defined(__AVR_ATmega1284P__))
355
                        if(ACC_AltitudeControl)                
354
                        if(ACC_AltitudeControl)                
356
                        {
355
                        {
357
//                              ExpandBaroStep = BaroStep * (long)ExpandBaro; // wird in fc.c aufgerufen
356
//                              ExpandBaroStep = BaroStep * (long)ExpandBaro; // wird in fc.c aufgerufen
358
//                              tmpLuftdruck = MessLuftdruck - BaroStep * (long)ExpandBaro;  // -523 counts per offset step
357
//                              tmpLuftdruck = MessLuftdruck - BaroStep * (long)ExpandBaro;  // -523 counts per offset step
359
                                tmpLuftdruck = MessLuftdruck - ExpandBaroStep;  // -523 counts per offset step
358
                                tmpLuftdruck = MessLuftdruck - ExpandBaroStep;  // -523 counts per offset step
360
                                Luftdruck -= Luftdruck / CalAthmospheare; // 16
359
                                Luftdruck -= Luftdruck / CalAthmospheare; // 16
361
                                Luftdruck += tmpLuftdruck;
360
                                Luftdruck += tmpLuftdruck;
362
                                HoehenWert = StartLuftdruck - Luftdruck;        // cm
361
                                HoehenWert_Mess = StartLuftdruck - Luftdruck;   // cm
363
                        }
362
                        }
364
                        else
363
                        else
365
#endif
364
#endif
366
            {   // old version (until FC V2.1)
365
            {   // old version (until FC V2.1)
367
                                tmpLuftdruck += MessLuftdruck;
366
                                tmpLuftdruck += MessLuftdruck;
368
                                if(++messanzahl_Druck >= 16) // war bis 0.86 "18"
367
                                if(++messanzahl_Druck >= 16) // war bis 0.86 "18"
369
                                {
368
                                {
370
                            signed int tmp;
369
                            signed int tmp;
371
//                              Luftdruck = (7 * Luftdruck + tmpLuftdruck - (16 * BaroStep) * (long)ExpandBaro + 4) / 8;  // -523.19 counts per 10 counts offset step
370
//                              Luftdruck = (7 * Luftdruck + tmpLuftdruck - (16 * BaroStep) * (long)ExpandBaro + 4) / 8;  // -523.19 counts per 10 counts offset step
372
//                              ExpandBaroStep = (16 * BaroStep) * (long)ExpandBaro - 4; // wird in fc.c aufgerufen
371
//                              ExpandBaroStep = (16 * BaroStep) * (long)ExpandBaro - 4; // wird in fc.c aufgerufen
373
                                Luftdruck = (7 * Luftdruck + tmpLuftdruck - ExpandBaroStep) / 8;  // -523.19 counts per 10 counts offset step
372
                                Luftdruck = (7 * Luftdruck + tmpLuftdruck - ExpandBaroStep) / 8;  // -523.19 counts per 10 counts offset step
374
                                HoehenWert = StartLuftdruck - Luftdruck;
373
                                HoehenWert_Mess = StartLuftdruck - Luftdruck;
375
                                SummenHoehe -= SummenHoehe/SM_FILTER;
374
                                SummenHoehe -= SummenHoehe/SM_FILTER;
376
                                SummenHoehe += HoehenWert;
375
                                SummenHoehe += HoehenWert_Mess;
377
                                tmp = (HoehenWert - SummenHoehe/SM_FILTER);
376
                                tmp = (HoehenWert_Mess - SummenHoehe/SM_FILTER);
378
                                if(tmp > 1024) tmp = 1024;      else if(tmp < -1024) tmp = -1024;
377
                                if(tmp > 1024) tmp = 1024;      else if(tmp < -1024) tmp = -1024;
379
                if(abs(VarioMeter) > 700) VarioMeter = (15 * VarioMeter + 8 * tmp)/16;
378
                if(abs(VarioMeter) > 700) VarioMeter = (15 * VarioMeter + 8 * tmp)/16;
380
                                else VarioMeter = (31 * VarioMeter + 8 * tmp)/32;
379
                                else VarioMeter = (31 * VarioMeter + 8 * tmp)/32;
381
                tmpLuftdruck /= 2;
380
                tmpLuftdruck /= 2;
382
                messanzahl_Druck = 16/2;
381
                messanzahl_Druck = 16/2;
383
                                }
382
                                }
384
                        }
383
                        }
385
            kanal = AD_NICK;
384
            kanal = AD_NICK;
386
            break;
385
            break;
387
        default:
386
        default:
388
            kanal = 0; state = 0; kanal = AD_NICK;
387
            kanal = 0; state = 0; kanal = AD_NICK;
389
            break;
388
            break;
390
        }
389
        }
391
    ADMUX = kanal;
390
    ADMUX = kanal;
392
    if(state != 0) ANALOG_ON;
391
    if(state != 0) ANALOG_ON;
393
}
392
}
394
 
393
 
395
 
394