Rev 2342 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 2342 | Rev 2426 | ||
---|---|---|---|
1 | /*####################################################################################### |
1 | /*####################################################################################### |
2 | Decodieren eines RC Summen Signals |
2 | Decodieren eines RC Summen Signals |
3 | #######################################################################################*/ |
3 | #######################################################################################*/ |
4 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
4 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
5 | // + www.MikroKopter.com |
5 | // + www.MikroKopter.com |
6 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
6 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
7 | // + Software Nutzungsbedingungen (english version: see below) |
7 | // + Software Nutzungsbedingungen (english version: see below) |
8 | // + der Fa. HiSystems GmbH, Flachsmeerstrasse 2, 26802 Moormerland - nachfolgend Lizenzgeber genannt - |
8 | // + der Fa. HiSystems GmbH, Flachsmeerstrasse 2, 26802 Moormerland - nachfolgend Lizenzgeber genannt - |
9 | // + Der Lizenzgeber räumt dem Kunden ein nicht-ausschließliches, zeitlich und räumlich* unbeschränktes Recht ein, die im den |
9 | // + Der Lizenzgeber räumt dem Kunden ein nicht-ausschließliches, zeitlich und räumlich* unbeschränktes Recht ein, die im den |
10 | // + Mikrocontroller verwendete Firmware für die Hardware Flight-Ctrl, Navi-Ctrl, BL-Ctrl, MK3Mag & PC-Programm MikroKopter-Tool |
10 | // + Mikrocontroller verwendete Firmware für die Hardware Flight-Ctrl, Navi-Ctrl, BL-Ctrl, MK3Mag & PC-Programm MikroKopter-Tool |
11 | // + - nachfolgend Software genannt - nur für private Zwecke zu nutzen. |
11 | // + - nachfolgend Software genannt - nur für private Zwecke zu nutzen. |
12 | // + Der Einsatz dieser Software ist nur auf oder mit Produkten des Lizenzgebers zulässig. |
12 | // + Der Einsatz dieser Software ist nur auf oder mit Produkten des Lizenzgebers zulässig. |
13 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
13 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
14 | // + Die vom Lizenzgeber gelieferte Software ist urheberrechtlich geschützt. Alle Rechte an der Software sowie an sonstigen im |
14 | // + Die vom Lizenzgeber gelieferte Software ist urheberrechtlich geschützt. Alle Rechte an der Software sowie an sonstigen im |
15 | // + Rahmen der Vertragsanbahnung und Vertragsdurchführung überlassenen Unterlagen stehen im Verhältnis der Vertragspartner ausschließlich dem Lizenzgeber zu. |
15 | // + Rahmen der Vertragsanbahnung und Vertragsdurchführung überlassenen Unterlagen stehen im Verhältnis der Vertragspartner ausschließlich dem Lizenzgeber zu. |
16 | // + Die in der Software enthaltenen Copyright-Vermerke, Markenzeichen, andere Rechtsvorbehalte, Seriennummern sowie |
16 | // + Die in der Software enthaltenen Copyright-Vermerke, Markenzeichen, andere Rechtsvorbehalte, Seriennummern sowie |
17 | // + sonstige der Programmidentifikation dienenden Merkmale dürfen vom Kunden nicht verändert oder unkenntlich gemacht werden. |
17 | // + sonstige der Programmidentifikation dienenden Merkmale dürfen vom Kunden nicht verändert oder unkenntlich gemacht werden. |
18 | // + Der Kunde trifft angemessene Vorkehrungen für den sicheren Einsatz der Software. Er wird die Software gründlich auf deren |
18 | // + Der Kunde trifft angemessene Vorkehrungen für den sicheren Einsatz der Software. Er wird die Software gründlich auf deren |
19 | // + Verwendbarkeit zu dem von ihm beabsichtigten Zweck testen, bevor er diese operativ einsetzt. |
19 | // + Verwendbarkeit zu dem von ihm beabsichtigten Zweck testen, bevor er diese operativ einsetzt. |
20 | // + Die Haftung des Lizenzgebers wird - soweit gesetzlich zulässig - begrenzt in Höhe des typischen und vorhersehbaren |
20 | // + Die Haftung des Lizenzgebers wird - soweit gesetzlich zulässig - begrenzt in Höhe des typischen und vorhersehbaren |
21 | // + Schadens. Die gesetzliche Haftung bei Personenschäden und nach dem Produkthaftungsgesetz bleibt unberührt. Dem Lizenzgeber steht jedoch der Einwand |
21 | // + Schadens. Die gesetzliche Haftung bei Personenschäden und nach dem Produkthaftungsgesetz bleibt unberührt. Dem Lizenzgeber steht jedoch der Einwand |
22 | // + des Mitverschuldens offen. |
22 | // + des Mitverschuldens offen. |
23 | // + Der Kunde trifft angemessene Vorkehrungen für den Fall, dass die Software ganz oder teilweise nicht ordnungsgemäß arbeitet. |
23 | // + Der Kunde trifft angemessene Vorkehrungen für den Fall, dass die Software ganz oder teilweise nicht ordnungsgemäß arbeitet. |
24 | // + Er wird die Software gründlich auf deren Verwendbarkeit zu dem von ihm beabsichtigten Zweck testen, bevor er diese operativ einsetzt. |
24 | // + Er wird die Software gründlich auf deren Verwendbarkeit zu dem von ihm beabsichtigten Zweck testen, bevor er diese operativ einsetzt. |
25 | // + Der Kunde wird er seine Daten vor Einsatz der Software nach dem Stand der Technik sichern. |
25 | // + Der Kunde wird er seine Daten vor Einsatz der Software nach dem Stand der Technik sichern. |
26 | // + Der Kunde ist darüber unterrichtet, dass der Lizenzgeber seine Daten im zur Vertragsdurchführung erforderlichen Umfang |
26 | // + Der Kunde ist darüber unterrichtet, dass der Lizenzgeber seine Daten im zur Vertragsdurchführung erforderlichen Umfang |
27 | // + und auf Grundlage der Datenschutzvorschriften erhebt, speichert, verarbeitet und, sofern notwendig, an Dritte übermittelt. |
27 | // + und auf Grundlage der Datenschutzvorschriften erhebt, speichert, verarbeitet und, sofern notwendig, an Dritte übermittelt. |
28 | // + *) Die räumliche Nutzung bezieht sich nur auf den Einsatzort, nicht auf die Reichweite der programmierten Software. |
28 | // + *) Die räumliche Nutzung bezieht sich nur auf den Einsatzort, nicht auf die Reichweite der programmierten Software. |
29 | // + #### ENDE DER NUTZUNGSBEDINGUNGEN ####' |
29 | // + #### ENDE DER NUTZUNGSBEDINGUNGEN ####' |
30 | // + 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. |
30 | // + 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. |
31 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
31 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
32 | // + Software LICENSING TERMS |
32 | // + Software LICENSING TERMS |
33 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
33 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
34 | // + of HiSystems GmbH, Flachsmeerstrasse 2, 26802 Moormerland, Germany - the Licensor - |
34 | // + of HiSystems GmbH, Flachsmeerstrasse 2, 26802 Moormerland, Germany - the Licensor - |
35 | // + 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 |
35 | // + 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 |
36 | // + (the Software) exclusively for private purposes. The License is unrestricted with respect to time and territory*. |
36 | // + (the Software) exclusively for private purposes. The License is unrestricted with respect to time and territory*. |
37 | // + The Software may only be used with the Licensor's products. |
37 | // + The Software may only be used with the Licensor's products. |
38 | // + The Software provided by the Licensor is protected by copyright. With respect to the relationship between the parties to this |
38 | // + The Software provided by the Licensor is protected by copyright. With respect to the relationship between the parties to this |
39 | // + agreement, all rights pertaining to the Software and other documents provided during the preparation and execution of this |
39 | // + agreement, all rights pertaining to the Software and other documents provided during the preparation and execution of this |
40 | // + agreement shall be the property of the Licensor. |
40 | // + agreement shall be the property of the Licensor. |
41 | // + The information contained in the Software copyright notices, trademarks, other legal reservations, serial numbers and other |
41 | // + The information contained in the Software copyright notices, trademarks, other legal reservations, serial numbers and other |
42 | // + features that can be used to identify the program may not be altered or defaced by the customer. |
42 | // + features that can be used to identify the program may not be altered or defaced by the customer. |
43 | // + The customer shall be responsible for taking reasonable precautions |
43 | // + The customer shall be responsible for taking reasonable precautions |
44 | // + for the safe use of the Software. The customer shall test the Software thoroughly regarding its suitability for the |
44 | // + for the safe use of the Software. The customer shall test the Software thoroughly regarding its suitability for the |
45 | // + intended purpose before implementing it for actual operation. The Licensor's liability shall be limited to the extent of typical and |
45 | // + intended purpose before implementing it for actual operation. The Licensor's liability shall be limited to the extent of typical and |
46 | // + foreseeable damage to the extent permitted by law, notwithstanding statutory liability for bodily injury and product |
46 | // + foreseeable damage to the extent permitted by law, notwithstanding statutory liability for bodily injury and product |
47 | // + liability. However, the Licensor shall be entitled to the defense of contributory negligence. |
47 | // + liability. However, the Licensor shall be entitled to the defense of contributory negligence. |
48 | // + The customer will take adequate precautions in the case, that the software is not working properly. The customer will test |
48 | // + The customer will take adequate precautions in the case, that the software is not working properly. The customer will test |
49 | // + the software for his purpose before any operational usage. The customer will backup his data before using the software. |
49 | // + the software for his purpose before any operational usage. The customer will backup his data before using the software. |
50 | // + The customer understands that the Licensor collects, stores and processes, and, where required, forwards, customer data |
50 | // + The customer understands that the Licensor collects, stores and processes, and, where required, forwards, customer data |
51 | // + to third parties to the extent necessary for executing the agreement, subject to applicable data protection and privacy regulations. |
51 | // + to third parties to the extent necessary for executing the agreement, subject to applicable data protection and privacy regulations. |
52 | // + *) The territory aspect only refers to the place where the Software is used, not its programmed range. |
52 | // + *) The territory aspect only refers to the place where the Software is used, not its programmed range. |
53 | // + #### END OF LICENSING TERMS #### |
53 | // + #### END OF LICENSING TERMS #### |
54 | // + Note: For information on license extensions (e.g. commercial use), please contact us at info(@)hisystems.de. |
54 | // + Note: For information on license extensions (e.g. commercial use), please contact us at info(@)hisystems.de. |
55 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
55 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
56 | 56 | ||
57 | #include "rc.h" |
57 | #include "rc.h" |
58 | #include "main.h" |
58 | #include "main.h" |
59 | // Achtung: ACT_S3D_SUMMENSIGNAL wird in der Main.h gesetzt |
59 | // Achtung: ACT_S3D_SUMMENSIGNAL wird in der Main.h gesetzt |
60 | #define MAX_RC_IN 16+12+3+4 // 16ch + 12ser + 3stages + 4 reserved |
60 | #define MAX_RC_IN 16+12+3+4 // 16ch + 12ser + 3stages + 4 reserved |
61 | volatile int PPM_in[MAX_RC_IN]; |
61 | volatile int PPM_in[MAX_RC_IN]; |
62 | volatile int PPM_diff[MAX_RC_IN]; // das differnzierte Stick-Signal |
62 | volatile int PPM_diff[MAX_RC_IN]; // das differnzierte Stick-Signal |
63 | volatile char Channels,tmpChannels = 0; |
63 | volatile char Channels,tmpChannels = 0; |
64 | volatile unsigned char NewPpmData = 1; |
64 | volatile unsigned char NewPpmData = 1; |
65 | unsigned int PPM_Neutral = 466; |
65 | unsigned int PPM_Neutral = 466; |
66 | 66 | ||
67 | //############################################################################ |
67 | //############################################################################ |
68 | // Clear the values |
68 | // Clear the values |
69 | void rc_sum_init(void) |
69 | void rc_sum_init(void) |
70 | //############################################################################ |
70 | //############################################################################ |
71 | { |
71 | { |
72 | unsigned char i; |
72 | unsigned char i; |
73 | for(i=0;i<MAX_RC_IN;i++) |
73 | for(i=0;i<MAX_RC_IN;i++) |
74 | { |
74 | { |
75 | if(i < 5) PPM_in[i] = 0; else PPM_in[i] = -127; |
75 | if(i < 5) PPM_in[i] = 0; else PPM_in[i] = -127; |
76 | PPM_diff[i] = 0; |
76 | PPM_diff[i] = 0; |
77 | } |
77 | } |
78 | PPM_in[PPM_IN_MAX] = +127; |
78 | PPM_in[PPM_IN_MAX] = +127; |
79 | PPM_in[PPM_IN_OFF] = -127; |
79 | PPM_in[PPM_IN_OFF] = -127; |
80 | PPM_in[PPM_IN_MID] = 0; |
80 | PPM_in[PPM_IN_MID] = 0; |
81 | AdNeutralGier = 0; |
81 | AdNeutralGier = 0; |
82 | AdNeutralRoll = 0; |
82 | AdNeutralRoll = 0; |
83 | AdNeutralNick = 0; |
83 | AdNeutralNick = 0; |
84 | return; |
84 | return; |
85 | } |
85 | } |
86 | 86 | ||
87 | #ifndef ACT_S3D_SUMMENSIGNAL |
87 | #ifndef ACT_S3D_SUMMENSIGNAL |
88 | //############################################################################ |
88 | //############################################################################ |
89 | // Interrupt function for the PPM-Input |
89 | // Interrupt function for the PPM-Input |
90 | ISR(TIMER1_CAPT_vect) |
90 | ISR(TIMER1_CAPT_vect) |
91 | //############################################################################ |
91 | //############################################################################ |
92 | { |
92 | { |
93 | #if (defined(__AVR_ATmega1284__) || defined(__AVR_ATmega1284P__)) |
93 | #if (defined(__AVR_ATmega1284__) || defined(__AVR_ATmega1284P__)) |
94 | if(!(EE_Parameter.ExtraConfig & CFG_SENSITIVE_RC)) |
94 | if(!(EE_Parameter.ExtraConfig & CFG_SENSITIVE_RC)) |
95 | #endif |
95 | #endif |
96 | { |
96 | { |
97 | static unsigned int AltICR=0; |
97 | static unsigned int AltICR=0; |
98 | signed int signal = 0,tmp; |
98 | signed int signal = 0,tmp; |
99 | static int index; |
99 | static int index; |
100 | 100 | ||
101 | signal = (unsigned int) ICR1 - AltICR; |
101 | signal = (unsigned int) ICR1 - AltICR; |
102 | AltICR = ICR1; |
102 | AltICR = ICR1; |
103 | //Syncronisationspause? (3.52 ms < signal < 25.6 ms) |
103 | //Syncronisationspause? (3.52 ms < signal < 25.6 ms) |
104 | if((signal > 1100) && (signal < 8000)) |
104 | if((signal > 1100) && (signal < 8000)) |
105 | { |
105 | { |
106 | Channels = index; |
106 | Channels = index; |
107 | if(index >= 4) NewPpmData = 0; // Null bedeutet: Neue Daten |
107 | if(index >= 4) NewPpmData = 0; // Null bedeutet: Neue Daten |
108 | index = 1; |
108 | index = 1; |
109 | } |
109 | } |
110 | else |
110 | else |
111 | { |
111 | { |
112 | if(index < 13+4) |
112 | if(index < 13+4) |
113 | { |
113 | { |
114 | if((signal > 250) && (signal < 687)) |
114 | if((signal > 250) && (signal < 687)) |
115 | { |
115 | { |
116 | signal -= PPM_Neutral; |
116 | signal -= PPM_Neutral; |
117 | // Stabiles Signal |
117 | // Stabiles Signal |
118 | if(EE_Parameter.FailsafeChannel == 0 || PPM_in[EE_Parameter.FailsafeChannel] < 100) // forces Failsafe if the receiver doesn't have 'signal loss' on Failsafe |
118 | if(EE_Parameter.FailsafeChannel == 0 || PPM_in[EE_Parameter.FailsafeChannel] < 100) // forces Failsafe if the receiver doesn't have 'signal loss' on Failsafe |
119 | { |
119 | { |
120 | if(abs(signal - PPM_in[index]) < 6) { if(SenderOkay < 200) SenderOkay += 10; else SenderOkay = 200;} |
120 | if(abs(signal - PPM_in[index]) < 6) { if(SenderOkay < 200) SenderOkay += 10; else SenderOkay = 200;} |
121 | } |
121 | } |
122 | tmp = (3 * (PPM_in[index]) + signal) / 4; |
122 | tmp = (3 * (PPM_in[index]) + signal) / 4; |
123 | if(tmp > signal+1) tmp--; else |
123 | if(tmp > signal+1) tmp--; else |
124 | if(tmp < signal-1) tmp++; |
124 | if(tmp < signal-1) tmp++; |
125 | if(SenderOkay >= 195) PPM_diff[index] = ((tmp - PPM_in[index]) / 3) * 3; |
125 | if(SenderOkay >= 195) PPM_diff[index] = ((tmp - PPM_in[index]) / 3) * 3; |
126 | else PPM_diff[index] = 0; |
126 | else PPM_diff[index] = 0; |
127 | PPM_in[index] = tmp; |
127 | PPM_in[index] = tmp; |
128 | } |
128 | } |
129 | index++; |
129 | index++; |
130 | #if (defined(__AVR_ATmega1284__) || defined(__AVR_ATmega1284P__)) |
130 | #if (defined(__AVR_ATmega1284__) || defined(__AVR_ATmega1284P__)) |
131 | #else |
131 | #else |
- | 132 | /* |
|
132 | if(PlatinenVersion < 20) |
133 | if(PlatinenVersion < 20) |
133 | { |
134 | { |
134 | if(index == 5) J3High; else J3Low; // Servosignal an J3 anlegen |
135 | if(index == 5) J3High; else J3Low; // Servosignal an J3 anlegen |
135 | if(index == 6) J4High; else J4Low; // Servosignal an J4 anlegen |
136 | if(index == 6) J4High; else J4Low; // Servosignal an J4 anlegen |
136 | if(index == 7) J5High; else J5Low; // Servosignal an J5 anlegen |
137 | if(index == 7) J5High; else J5Low; // Servosignal an J5 anlegen |
137 | } |
138 | } |
- | 139 | */ |
|
138 | #endif |
140 | #endif |
139 | } |
141 | } |
140 | } |
142 | } |
141 | } |
143 | } |
142 | #if (defined(__AVR_ATmega1284__) || defined(__AVR_ATmega1284P__)) |
144 | #if (defined(__AVR_ATmega1284__) || defined(__AVR_ATmega1284P__)) |
143 | else |
145 | else |
144 | { |
146 | { |
145 | static unsigned int AltICR=0; |
147 | static unsigned int AltICR=0; |
146 | static int ppm_in[13+4]; |
148 | static int ppm_in[13+4]; |
147 | static int ppm_diff[13+4]; |
149 | static int ppm_diff[13+4]; |
148 | static int old_ppm_in[13+4]; |
150 | static int old_ppm_in[13+4]; |
149 | static int old_ppm_diff[13+4]; |
151 | static int old_ppm_diff[13+4]; |
150 | signed int signal = 0,tmp; |
152 | signed int signal = 0,tmp; |
151 | static unsigned char index, okay_cnt = 0; |
153 | static unsigned char index, okay_cnt = 0; |
152 | signal = (unsigned int) ICR1 - AltICR; |
154 | signal = (unsigned int) ICR1 - AltICR; |
153 | AltICR = ICR1; |
155 | AltICR = ICR1; |
154 | //Syncronisationspause? (3.52 ms < signal < 25.6 ms) |
156 | //Syncronisationspause? (3.52 ms < signal < 25.6 ms) |
155 | if((signal > 1100) && (signal < 8000)) |
157 | if((signal > 1100) && (signal < 8000)) |
156 | { |
158 | { |
157 | tmpChannels = index; |
159 | tmpChannels = index; |
158 | if(tmpChannels >= 4 && Channels == tmpChannels) |
160 | if(tmpChannels >= 4 && Channels == tmpChannels) |
159 | { |
161 | { |
160 | if(okay_cnt > 10) |
162 | if(okay_cnt > 10) |
161 | { |
163 | { |
162 | NewPpmData = 0; // Null bedeutet: Neue Daten |
164 | NewPpmData = 0; // Null bedeutet: Neue Daten |
163 | for(index = 0; index < 13+4; index++) |
165 | for(index = 0; index < 13+4; index++) |
164 | { |
166 | { |
165 | if(okay_cnt > 30) |
167 | if(okay_cnt > 30) |
166 | { |
168 | { |
167 | old_ppm_in[index] = PPM_in[index]; |
169 | old_ppm_in[index] = PPM_in[index]; |
168 | old_ppm_diff[index] = PPM_diff[index]; |
170 | old_ppm_diff[index] = PPM_diff[index]; |
169 | } |
171 | } |
170 | PPM_in[index] = ppm_in[index]; |
172 | PPM_in[index] = ppm_in[index]; |
171 | PPM_diff[index] = ppm_diff[index]; |
173 | PPM_diff[index] = ppm_diff[index]; |
172 | } |
174 | } |
173 | } |
175 | } |
174 | if(okay_cnt < 255) okay_cnt++; |
176 | if(okay_cnt < 255) okay_cnt++; |
175 | } |
177 | } |
176 | else |
178 | else |
177 | { |
179 | { |
178 | if(okay_cnt > 100) okay_cnt = 10; else okay_cnt = 0; |
180 | if(okay_cnt > 100) okay_cnt = 10; else okay_cnt = 0; |
179 | ROT_ON; |
181 | ROT_ON; |
180 | } |
182 | } |
181 | index = 1; |
183 | index = 1; |
182 | if(!MotorenEin) Channels = tmpChannels; |
184 | if(!MotorenEin) Channels = tmpChannels; |
183 | } |
185 | } |
184 | else |
186 | else |
185 | { |
187 | { |
186 | if(index < 13+4) |
188 | if(index < 13+4) |
187 | { |
189 | { |
188 | if((signal > 250) && (signal < 687)) |
190 | if((signal > 250) && (signal < 687)) |
189 | { |
191 | { |
190 | signal -= PPM_Neutral; |
192 | signal -= PPM_Neutral; |
191 | // Stabiles Signal |
193 | // Stabiles Signal |
192 | if((abs(signal - ppm_in[index]) < 6)) |
194 | if((abs(signal - ppm_in[index]) < 6)) |
193 | { |
195 | { |
194 | if(EE_Parameter.FailsafeChannel == 0 || PPM_in[EE_Parameter.FailsafeChannel] < 100) // forces Failsafe if the receiver doesn't have 'signal loss' on Failsafe |
196 | if(EE_Parameter.FailsafeChannel == 0 || PPM_in[EE_Parameter.FailsafeChannel] < 100) // forces Failsafe if the receiver doesn't have 'signal loss' on Failsafe |
195 | { |
197 | { |
196 | if(okay_cnt > 25) SenderOkay += 10; |
198 | if(okay_cnt > 25) SenderOkay += 10; |
197 | else |
199 | else |
198 | if(okay_cnt > 10) SenderOkay += 2; |
200 | if(okay_cnt > 10) SenderOkay += 2; |
199 | if(SenderOkay > 200) SenderOkay = 200; |
201 | if(SenderOkay > 200) SenderOkay = 200; |
200 | } |
202 | } |
201 | } |
203 | } |
202 | tmp = (3 * (ppm_in[index]) + signal) / 4; |
204 | tmp = (3 * (ppm_in[index]) + signal) / 4; |
203 | if(tmp > signal+1) tmp--; else |
205 | if(tmp > signal+1) tmp--; else |
204 | if(tmp < signal-1) tmp++; |
206 | if(tmp < signal-1) tmp++; |
205 | if(SenderOkay >= 190) ppm_diff[index] = ((tmp - ppm_in[index]) / 3) * 3; |
207 | if(SenderOkay >= 190) ppm_diff[index] = ((tmp - ppm_in[index]) / 3) * 3; |
206 | else ppm_diff[index] = 0; |
208 | else ppm_diff[index] = 0; |
207 | ppm_in[index] = tmp; |
209 | ppm_in[index] = tmp; |
208 | } |
210 | } |
209 | else ROT_ON; |
211 | else ROT_ON; |
210 | #if (defined(__AVR_ATmega1284__) || defined(__AVR_ATmega1284P__)) |
212 | #if (defined(__AVR_ATmega1284__) || defined(__AVR_ATmega1284P__)) |
211 | #else |
213 | #else |
212 | if(PlatinenVersion < 20) |
214 | if(PlatinenVersion < 20) |
213 | { |
215 | { |
214 | if(index == 5) J3High; else J3Low; // Servosignal an J3 anlegen |
216 | if(index == 5) J3High; else J3Low; // Servosignal an J3 anlegen |
215 | if(index == 6) J4High; else J4Low; // Servosignal an J4 anlegen |
217 | if(index == 6) J4High; else J4Low; // Servosignal an J4 anlegen |
216 | if(index == 7) J5High; else J5Low; // Servosignal an J5 anlegen |
218 | if(index == 7) J5High; else J5Low; // Servosignal an J5 anlegen |
217 | } |
219 | } |
218 | #endif |
220 | #endif |
219 | } |
221 | } |
220 | if(index < 20) index++; |
222 | if(index < 20) index++; |
221 | else |
223 | else |
222 | if(index == 20) |
224 | if(index == 20) |
223 | { |
225 | { |
224 | unsigned char i; |
226 | unsigned char i; |
225 | ROT_ON; |
227 | ROT_ON; |
226 | index = 30; |
228 | index = 30; |
227 | for(i=0;i<13+4;i++) // restore from older data |
229 | for(i=0;i<13+4;i++) // restore from older data |
228 | { |
230 | { |
229 | PPM_in[i] = old_ppm_in[i]; |
231 | PPM_in[i] = old_ppm_in[i]; |
230 | PPM_diff[i] = 0; |
232 | PPM_diff[i] = 0; |
231 | // okay_cnt /= 2; |
233 | // okay_cnt /= 2; |
232 | } |
234 | } |
233 | } |
235 | } |
234 | } |
236 | } |
235 | } |
237 | } |
236 | #endif |
238 | #endif |
237 | 239 | ||
238 | } |
240 | } |
239 | 241 | ||
240 | #else |
242 | #else |
241 | //############################################################################ |
243 | //############################################################################ |
242 | // Interrupt function for the PPM-Input |
244 | // Interrupt function for the PPM-Input |
243 | ISR(TIMER1_CAPT_vect) |
245 | ISR(TIMER1_CAPT_vect) |
244 | //############################################################################ |
246 | //############################################################################ |
245 | 247 | ||
246 | { |
248 | { |
247 | static unsigned int AltICR=0; |
249 | static unsigned int AltICR=0; |
248 | signed int signal = 0,tmp; |
250 | signed int signal = 0,tmp; |
249 | static int index; |
251 | static int index; |
250 | 252 | ||
251 | signal = (unsigned int) ICR1 - AltICR; |
253 | signal = (unsigned int) ICR1 - AltICR; |
252 | signal /= 2; |
254 | signal /= 2; |
253 | AltICR = ICR1; |
255 | AltICR = ICR1; |
254 | //Syncronisationspause? |
256 | //Syncronisationspause? |
255 | if((signal > 1100*2) && (signal < 8000*2)) |
257 | if((signal > 1100*2) && (signal < 8000*2)) |
256 | { |
258 | { |
257 | if(index >= 4) NewPpmData = 0; // Null bedeutet: Neue Daten |
259 | if(index >= 4) NewPpmData = 0; // Null bedeutet: Neue Daten |
258 | index = 1; |
260 | index = 1; |
259 | } |
261 | } |
260 | else |
262 | else |
261 | { |
263 | { |
262 | if(index < 13) |
264 | if(index < 13) |
263 | { |
265 | { |
264 | if((signal > 250) && (signal < 687*2)) |
266 | if((signal > 250) && (signal < 687*2)) |
265 | { |
267 | { |
266 | signal -= 962; |
268 | signal -= 962; |
267 | // Stabiles Signal |
269 | // Stabiles Signal |
268 | if(abs(signal - PPM_in[index]) < 6) { if(SenderOkay < 200) SenderOkay += 10;} |
270 | if(abs(signal - PPM_in[index]) < 6) { if(SenderOkay < 200) SenderOkay += 10;} |
269 | tmp = (3 * (PPM_in[index]) + signal) / 4; |
271 | tmp = (3 * (PPM_in[index]) + signal) / 4; |
270 | if(tmp > signal+1) tmp--; else |
272 | if(tmp > signal+1) tmp--; else |
271 | if(tmp < signal-1) tmp++; |
273 | if(tmp < signal-1) tmp++; |
272 | if(SenderOkay >= 195) PPM_diff[index] = ((tmp - PPM_in[index]) / 3) * 3; |
274 | if(SenderOkay >= 195) PPM_diff[index] = ((tmp - PPM_in[index]) / 3) * 3; |
273 | else PPM_diff[index] = 0; |
275 | else PPM_diff[index] = 0; |
274 | PPM_in[index] = tmp; |
276 | PPM_in[index] = tmp; |
275 | } |
277 | } |
276 | index++; |
278 | index++; |
277 | } |
279 | } |
278 | } |
280 | } |
279 | } |
281 | } |
280 | #endif |
282 | #endif |
281 | 283 | ||
282 | 284 | ||
283 | 285 | ||
284 | 286 |