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