Rev 2176 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 2176 | Rev 2177 | ||
---|---|---|---|
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 int StartLuftdruck; |
63 | volatile int 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 | 71 | ||
72 | //####################################################################################### |
72 | //####################################################################################### |
73 | void ADC_Init(void) |
73 | void ADC_Init(void) |
74 | //####################################################################################### |
74 | //####################################################################################### |
75 | { |
75 | { |
76 | ADMUX = 0;//Referenz ist extern |
76 | ADMUX = 0;//Referenz ist extern |
77 | ANALOG_ON; |
77 | ANALOG_ON; |
78 | } |
78 | } |
79 | 79 | ||
80 | #define DESIRED_H_ADC 800 |
80 | #define DESIRED_H_ADC 800 |
81 | 81 | ||
82 | void SucheLuftruckOffset(void) |
82 | void SucheLuftruckOffset(void) |
83 | { |
83 | { |
84 | unsigned int off; |
84 | unsigned int off; |
85 | ExpandBaro = 0; |
85 | ExpandBaro = 0; |
86 | 86 | ||
87 | #if (defined(__AVR_ATmega1284__) || defined(__AVR_ATmega1284P__)) |
87 | #if (defined(__AVR_ATmega1284__) || defined(__AVR_ATmega1284P__)) |
88 | { |
88 | { |
89 | unsigned char off2; |
89 | unsigned char off2; |
90 | OCR0A = 150; |
90 | OCR0A = 150; |
91 | off2 = GetParamByte(PID_PRESSURE_OFFSET); |
91 | off2 = GetParamByte(PID_PRESSURE_OFFSET); |
92 | if(off2 < 230) off2 += 10; |
92 | if(off2 < 230) off2 += 10; |
93 | OCR0B = off2; |
93 | OCR0B = off2; |
94 | Delay_ms_Mess(100); |
94 | Delay_ms_Mess(100); |
95 | if(MessLuftdruck > DESIRED_H_ADC) off2 = 240; |
95 | if(MessLuftdruck > DESIRED_H_ADC) off2 = 240; |
96 | for(; off2 >= 5; off2 -= 5) |
96 | for(; off2 >= 5; off2 -= 5) |
97 | { |
97 | { |
98 | OCR0B = off2; |
98 | OCR0B = off2; |
99 | Delay_ms_Mess(50); |
99 | Delay_ms_Mess(50); |
100 | printf("*"); |
100 | printf("*"); |
101 | if(MessLuftdruck > DESIRED_H_ADC) break; |
101 | if(MessLuftdruck > DESIRED_H_ADC) break; |
102 | } |
102 | } |
103 | SetParamByte(PID_PRESSURE_OFFSET, off2); |
103 | SetParamByte(PID_PRESSURE_OFFSET, off2); |
104 | if(off2 >= 15) off = 140; else off = 0; |
104 | if(off2 >= 15) off = 140; else off = 0; |
105 | for(; off < 250;off++) |
105 | for(; off < 250;off++) |
106 | { |
106 | { |
107 | OCR0A = off; |
107 | OCR0A = off; |
108 | Delay_ms_Mess(50); |
108 | Delay_ms_Mess(50); |
109 | printf("."); |
109 | printf("."); |
110 | if(MessLuftdruck < DESIRED_H_ADC) break; |
110 | if(MessLuftdruck < DESIRED_H_ADC) break; |
111 | } |
111 | } |
112 | DruckOffsetSetting = off; |
112 | DruckOffsetSetting = off; |
113 | } |
113 | } |
114 | #else |
114 | #else |
115 | off = GetParamByte(PID_PRESSURE_OFFSET); |
115 | off = GetParamByte(PID_PRESSURE_OFFSET); |
116 | if(off > 20) off -= 10; |
116 | if(off > 20) off -= 10; |
117 | OCR0A = off; |
117 | OCR0A = off; |
118 | Delay_ms_Mess(100); |
118 | Delay_ms_Mess(100); |
119 | if(MessLuftdruck < DESIRED_H_ADC) off = 0; |
119 | if(MessLuftdruck < DESIRED_H_ADC) off = 0; |
120 | for(; off < 250;off++) |
120 | for(; off < 250;off++) |
121 | { |
121 | { |
122 | OCR0A = off; |
122 | OCR0A = off; |
123 | Delay_ms_Mess(50); |
123 | Delay_ms_Mess(50); |
124 | printf("."); |
124 | printf("."); |
125 | if(MessLuftdruck < DESIRED_H_ADC) break; |
125 | if(MessLuftdruck < DESIRED_H_ADC) break; |
126 | } |
126 | } |
127 | DruckOffsetSetting = off; |
127 | DruckOffsetSetting = off; |
128 | SetParamByte(PID_PRESSURE_OFFSET, off); |
128 | SetParamByte(PID_PRESSURE_OFFSET, off); |
129 | #endif |
129 | #endif |
130 | if((EE_Parameter.GlobalConfig & CFG_HOEHENREGELUNG) && (DruckOffsetSetting < 10 || DruckOffsetSetting >= 245)) VersionInfo.HardwareError[0] |= FC_ERROR0_PRESSURE; |
130 | if((EE_Parameter.GlobalConfig & CFG_HOEHENREGELUNG) && (DruckOffsetSetting < 10 || DruckOffsetSetting >= 245)) VersionInfo.HardwareError[0] |= FC_ERROR0_PRESSURE; |
131 | OCR0A = off; |
131 | OCR0A = off; |
132 | Delay_ms_Mess(300); |
132 | Delay_ms_Mess(300); |
133 | } |
133 | } |
134 | 134 | ||
135 | 135 | ||
136 | void SucheGyroOffset(void) |
136 | void SucheGyroOffset(void) |
137 | { |
137 | { |
138 | unsigned char i, ready = 0; |
138 | unsigned char i, ready = 0; |
139 | int timeout; |
139 | int timeout; |
140 | timeout = SetDelay(2000); |
140 | timeout = SetDelay(2000); |
141 | for(i=140; i != 0; i--) |
141 | for(i=140; i != 0; i--) |
142 | { |
142 | { |
143 | if(ready == 3 && i > 10) i = 9; |
143 | if(ready == 3 && i > 10) i = 9; |
144 | ready = 0; |
144 | ready = 0; |
145 | if(AdWertNick < 1020) AnalogOffsetNick--; else if(AdWertNick > 1030) AnalogOffsetNick++; else ready++; |
145 | if(AdWertNick < 1020) AnalogOffsetNick--; else if(AdWertNick > 1030) AnalogOffsetNick++; else ready++; |
146 | if(AdWertRoll < 1020) AnalogOffsetRoll--; else if(AdWertRoll > 1030) AnalogOffsetRoll++; else ready++; |
146 | if(AdWertRoll < 1020) AnalogOffsetRoll--; else if(AdWertRoll > 1030) AnalogOffsetRoll++; else ready++; |
147 | if(AdWertGier < 1020) AnalogOffsetGier--; else if(AdWertGier > 1030) AnalogOffsetGier++; else ready++; |
147 | if(AdWertGier < 1020) AnalogOffsetGier--; else if(AdWertGier > 1030) AnalogOffsetGier++; else ready++; |
148 | I2C_Start(TWI_STATE_GYRO_OFFSET_TX); |
148 | I2C_Start(TWI_STATE_GYRO_OFFSET_TX); |
149 | 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(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(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(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(AnalogOffsetGier < 10) { VersionInfo.HardwareError[0] |= FC_ERROR0_GYRO_YAW; AnalogOffsetGier = 10;}; if(AnalogOffsetGier > 245) { VersionInfo.HardwareError[0] |= FC_ERROR0_GYRO_YAW; AnalogOffsetGier = 245;}; |
151 | 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 | while(twi_state) if(CheckDelay(timeout)) {printf("\n\r DAC or I2C ERROR! Check I2C, 3Vref, DAC and BL-Ctrl"); break;} |
152 | while(twi_state) if(CheckDelay(timeout)) {printf("\n\r DAC or I2C ERROR! Check I2C, 3Vref, DAC and BL-Ctrl"); break;} |
153 | AdReady = 0; |
153 | AdReady = 0; |
154 | ANALOG_ON; |
154 | ANALOG_ON; |
155 | while(!AdReady); |
155 | while(!AdReady); |
156 | if(i<10) Delay_ms_Mess(10); |
156 | if(i<10) Delay_ms_Mess(10); |
157 | } |
157 | } |
158 | Delay_ms_Mess(70); |
158 | Delay_ms_Mess(70); |
159 | } |
159 | } |
160 | 160 | ||
161 | /* |
161 | /* |
162 | 0 n |
162 | 0 n |
163 | 1 r |
163 | 1 r |
164 | 2 g |
164 | 2 g |
165 | 3 y |
165 | 3 y |
166 | 4 x |
166 | 4 x |
167 | 5 n |
167 | 5 n |
168 | 6 r |
168 | 6 r |
169 | 7 u |
169 | 7 u |
170 | 8 z |
170 | 8 z |
171 | 9 L |
171 | 9 L |
172 | 10 n |
172 | 10 n |
173 | 11 r |
173 | 11 r |
174 | 12 g |
174 | 12 g |
175 | 13 y |
175 | 13 y |
176 | 14 x |
176 | 14 x |
177 | 15 n |
177 | 15 n |
178 | 16 r |
178 | 16 r |
179 | 17 L |
179 | 17 L |
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 char subcount = 0; |
188 | //static signed char subcount = 0; // MartinR: wird nicht mehr benötigt, da deaktiviert |
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 | UBat = (3 * UBat + ADC / 3) / 4; |
230 | UBat = (3 * UBat + ADC / 3) / 4; |
231 | kanal = AD_ACC_Z; |
231 | kanal = AD_ACC_Z; |
232 | break; |
232 | break; |
233 | case 8: |
233 | case 8: |
234 | AdWertAccHoch = (signed int) ADC - NeutralAccZ; |
234 | AdWertAccHoch = (signed int) ADC - NeutralAccZ; |
- | 235 | ||
- | 236 | /* // MartinR: deaktivieren Anfang |
|
- | 237 | |
|
235 | if(AdWertAccHoch > 1) |
238 | if(AdWertAccHoch > 1) |
236 | { |
239 | { |
237 | if(NeutralAccZ < 750) |
240 | if(NeutralAccZ < 750) |
238 | { |
241 | { |
239 | subcount += 5; |
242 | subcount += 5; |
240 | if(modell_fliegt < 500) subcount += 10; |
243 | if(modell_fliegt < 500) subcount += 10; |
241 | } |
244 | } |
242 | if(subcount > 100) { NeutralAccZ++; subcount -= 100;} |
245 | if(subcount > 100) { NeutralAccZ++; subcount -= 100;} |
243 | } |
246 | } |
244 | else if(AdWertAccHoch < -1) |
247 | else if(AdWertAccHoch < -1) |
245 | { |
248 | { |
246 | if(NeutralAccZ > 550) |
249 | if(NeutralAccZ > 550) |
247 | { |
250 | { |
248 | subcount -= 5; |
251 | subcount -= 5; |
249 | if(modell_fliegt < 500) subcount -= 10; |
252 | if(modell_fliegt < 500) subcount -= 10; |
250 | if(subcount < -100) { NeutralAccZ--; subcount += 100;} |
253 | if(subcount < -100) { NeutralAccZ--; subcount += 100;} |
251 | } |
254 | } |
252 | } |
255 | } |
- | 256 | |
|
- | 257 | */ // MartinR: deaktivieren Ende |
|
- | 258 | ||
253 | // messanzahl_AccHoch = 1; |
259 | //messanzahl_AccHoch = 1; |
254 | Aktuell_az = ADC; |
260 | Aktuell_az = ADC; |
255 | Mess_Integral_Hoch += AdWertAccHoch; // Integrieren |
261 | Mess_Integral_Hoch += AdWertAccHoch; // Integrieren |
256 | Mess_Integral_Hoch -= Mess_Integral_Hoch / 1024; // dämfen |
262 | Mess_Integral_Hoch -= Mess_Integral_Hoch / 1024; // dämfen |
257 | kanal = AD_DRUCK; |
263 | kanal = AD_DRUCK; |
258 | break; |
264 | break; |
259 | // "case 9:" fehlt hier absichtlich |
265 | // "case 9:" fehlt hier absichtlich |
260 | case 10: |
266 | case 10: |
261 | nick1 += ADC; |
267 | nick1 += ADC; |
262 | kanal = AD_ROLL; |
268 | kanal = AD_ROLL; |
263 | break; |
269 | break; |
264 | case 11: |
270 | case 11: |
265 | roll1 += ADC; |
271 | roll1 += ADC; |
266 | kanal = AD_GIER; |
272 | kanal = AD_GIER; |
267 | break; |
273 | break; |
268 | case 12: |
274 | case 12: |
269 | if(PlatinenVersion == 10) AdWertGier = (ADC + gier1 + 1) / 2; |
275 | if(PlatinenVersion == 10) AdWertGier = (ADC + gier1 + 1) / 2; |
270 | else |
276 | else |
271 | if(PlatinenVersion >= 20) AdWertGier = 2047 - (ADC + gier1); |
277 | if(PlatinenVersion >= 20) AdWertGier = 2047 - (ADC + gier1); |
272 | else AdWertGier = (ADC + gier1); |
278 | else AdWertGier = (ADC + gier1); |
273 | kanal = AD_ACC_Y; |
279 | kanal = AD_ACC_Y; |
274 | break; |
280 | break; |
275 | case 13: |
281 | case 13: |
276 | Aktuell_ay = NeutralAccY - ADC; |
282 | Aktuell_ay = NeutralAccY - ADC; |
277 | AdWertAccRoll = (Aktuell_ay + accy); |
283 | AdWertAccRoll = (Aktuell_ay + accy); |
278 | kanal = AD_ACC_X; |
284 | kanal = AD_ACC_X; |
279 | break; |
285 | break; |
280 | case 14: |
286 | case 14: |
281 | Aktuell_ax = ADC - NeutralAccX; |
287 | Aktuell_ax = ADC - NeutralAccX; |
282 | AdWertAccNick = (Aktuell_ax + accx); |
288 | AdWertAccNick = (Aktuell_ax + accx); |
283 | kanal = AD_NICK; |
289 | kanal = AD_NICK; |
284 | break; |
290 | break; |
285 | case 15: |
291 | case 15: |
286 | nick1 += ADC; |
292 | nick1 += ADC; |
287 | if(PlatinenVersion == 10) nick1 *= 2; else nick1 *= 4; |
293 | if(PlatinenVersion == 10) nick1 *= 2; else nick1 *= 4; |
288 | AdWertNick = nick1 / 8; |
294 | AdWertNick = nick1 / 8; |
289 | nick_filter = (nick_filter + nick1) / 2; |
295 | nick_filter = (nick_filter + nick1) / 2; |
290 | HiResNick = nick_filter - AdNeutralNick; |
296 | //HiResNick = nick_filter - AdNeutralNick; // MartinR: so war es |
- | 297 | HiResNick = (nick_filter - AdNeutralNick + 4 ) / 8 ; // MartinR: + 4um Rundungsfehler zu verbessern |
|
- | 298 | // MartinR: /8 von fc.c nach hier verschoben um Code zu sparen |
|
291 | AdWertNickFilter = (AdWertNickFilter + HiResNick) / 2; |
299 | AdWertNickFilter = (AdWertNickFilter + HiResNick) / 2; |
292 | kanal = AD_ROLL; |
300 | kanal = AD_ROLL; |
293 | break; |
301 | break; |
294 | case 16: |
302 | case 16: |
295 | roll1 += ADC; |
303 | roll1 += ADC; |
296 | if(PlatinenVersion == 10) roll1 *= 2; else roll1 *= 4; |
304 | if(PlatinenVersion == 10) roll1 *= 2; else roll1 *= 4; |
297 | AdWertRoll = roll1 / 8; |
305 | AdWertRoll = roll1 / 8; |
298 | roll_filter = (roll_filter + roll1) / 2; |
306 | roll_filter = (roll_filter + roll1) / 2; |
299 | HiResRoll = roll_filter - AdNeutralRoll; |
307 | //HiResRoll = roll_filter - AdNeutralRoll; // MartinR: so war es |
- | 308 | HiResRoll = (roll_filter - AdNeutralRoll + 4 ) / 8; // MartinR: + 4um Rundungsfehler zu verbessern |
|
- | 309 | // MartinR: /8 von fc.c nach hier verschoben um Code zu sparen |
|
300 | AdWertRollFilter = (AdWertRollFilter + HiResRoll) / 2; |
310 | AdWertRollFilter = (AdWertRollFilter + HiResRoll) / 2; |
301 | kanal = AD_DRUCK; |
311 | kanal = AD_DRUCK; |
302 | break; |
312 | break; |
303 | case 17: |
313 | case 17: |
304 | state = 0; |
314 | state = 0; |
305 | AdReady = 1; |
315 | AdReady = 1; |
306 | ZaehlMessungen++; |
316 | ZaehlMessungen++; |
307 | // "break" fehlt hier absichtlich |
317 | // "break" fehlt hier absichtlich |
308 | case 9: |
318 | case 9: |
309 | MessLuftdruck = ADC; |
319 | //MessLuftdruck = ADC; // MartinR: so war es |
- | 320 | MessLuftdruck = ADC + ((Parameter_UserParam4 * AdWertAccHoch) / 256) ; // MartinR: |
|
- | 321 | // mit Korrektur der Beschleunigungsempfindlichkeit des Luftdrucksensors |
|
310 | tmpLuftdruck += MessLuftdruck; |
322 | tmpLuftdruck += MessLuftdruck; |
311 | if(++messanzahl_Druck >= 16) // war bis 0.86 "18" |
323 | if(++messanzahl_Druck >= 16) // war bis 0.86 "18" |
312 | { |
324 | { |
313 | signed int tmp; |
325 | signed int tmp; |
314 | Luftdruck = (7 * Luftdruck + tmpLuftdruck - (16 * 523) * (long)ExpandBaro + 4) / 8; // -523.19 counts per 10 counts offset step |
326 | Luftdruck = (7 * Luftdruck + tmpLuftdruck - (16 * 523) * (long)ExpandBaro + 4) / 8; // -523.19 counts per 10 counts offset step |
315 | HoehenWert = StartLuftdruck - Luftdruck; |
327 | HoehenWert = StartLuftdruck - Luftdruck; |
316 | SummenHoehe -= SummenHoehe/SM_FILTER; |
328 | SummenHoehe -= SummenHoehe/SM_FILTER; |
317 | SummenHoehe += HoehenWert; |
329 | SummenHoehe += HoehenWert; |
318 | tmp = (HoehenWert - SummenHoehe/SM_FILTER); |
330 | tmp = (HoehenWert - SummenHoehe/SM_FILTER); |
319 | if(tmp > 1024) tmp = 1024; else if(tmp < -1024) tmp = -1024; |
331 | if(tmp > 1024) tmp = 1024; else if(tmp < -1024) tmp = -1024; |
320 | if(abs(VarioMeter) > 700) VarioMeter = (15 * VarioMeter + 8 * tmp)/16; |
332 | if(abs(VarioMeter) > 700) VarioMeter = (15 * VarioMeter + 8 * tmp)/16; |
321 | else VarioMeter = (31 * VarioMeter + 8 * tmp)/32; |
333 | else VarioMeter = (31 * VarioMeter + 8 * tmp)/32; |
322 | tmpLuftdruck /= 2; |
334 | tmpLuftdruck /= 2; |
323 | messanzahl_Druck = 16/2; |
335 | messanzahl_Druck = 16/2; |
324 | } |
336 | } |
325 | kanal = AD_NICK; |
337 | kanal = AD_NICK; |
326 | break; |
338 | break; |
327 | default: |
339 | default: |
328 | kanal = 0; state = 0; kanal = AD_NICK; |
340 | kanal = 0; state = 0; kanal = AD_NICK; |
329 | break; |
341 | break; |
330 | } |
342 | } |
331 | ADMUX = kanal; |
343 | ADMUX = kanal; |
332 | if(state != 0) ANALOG_ON; |
344 | if(state != 0) ANALOG_ON; |
333 | } |
345 | } |
334 | 346 | ||
335 | 347 |