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