Rev 1812 | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 1812 | Rev 1819 | ||
---|---|---|---|
- | 1 | /****************************************************************************************************************** |
|
- | 2 | V0.82b-Arthur-P 2010-12-18 |
|
- | 3 | ------------------------------------------------------------------------------------------------------------------ |
|
- | 4 | Version includes only support for external HEF4017 for FC1.x hardware, NOT for Twi2Ppm converters for ESCs. |
|
- | 5 | ||
- | 6 | 2010-12-18 Chanded the if(Platinenversion < 20) statement within this file to correctly identify external HEF4017. |
|
- | 7 | Arthur P. Modified to use several parameters for servo control: |
|
- | 8 | User_Parameter4: |
|
- | 9 | User_Parameter5: |
|
- | 10 | User_Parameter6: |
|
- | 11 | User_Parameter7: |
|
- | 12 | User_Parameter8: Use external HEF4017 if bit 8 is set (>127). The remaining 7 bits are used |
|
- | 13 | for the shutter cycle counter: the value is multiplied by 5 programmatically, |
|
- | 14 | resulting in steps of approx. 0.1sec. Minimum value to start using the |
|
- | 15 | interval timer is 10 (approx. 1 sec, or countervalue of 50). Note that this |
|
- | 16 | was originally done through user para 6. |
|
- | 17 | ******************************************************************************************************************/ |
|
1 | /*####################################################################################### |
18 | /*####################################################################################### |
2 | Decodieren eines RC Summen Signals |
19 | Decodieren eines RC Summen Signals |
3 | #######################################################################################*/ |
20 | #######################################################################################*/ |
4 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
21 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
5 | // + Copyright (c) Holger Buss, Ingo Busker |
22 | // + Copyright (c) Holger Buss, Ingo Busker |
6 | // + only for non-profit use |
23 | // + only for non-profit use |
7 | // + www.MikroKopter.com |
24 | // + www.MikroKopter.com |
8 | // + porting the sources to other systems or using the software on other systems (except hardware from www.mikrokopter.de) is not allowed |
25 | // + porting the sources to other systems or using the software on other systems (except hardware from www.mikrokopter.de) is not allowed |
9 | // + see the File "License.txt" for further Informations |
26 | // + see the File "License.txt" for further Informations |
10 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
27 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
11 | 28 | ||
12 | #include "rc.h" |
29 | #include "rc.h" |
13 | #include "main.h" |
30 | #include "main.h" |
14 | // Achtung: ACT_S3D_SUMMENSIGNAL wird in der Main.h gesetzt |
31 | // Achtung: ACT_S3D_SUMMENSIGNAL wird in der Main.h gesetzt |
15 | 32 | ||
16 | volatile int PPM_in[26]; |
33 | volatile int PPM_in[26]; |
17 | volatile int PPM_diff[26]; // das diffenzierte Stick-Signal |
34 | volatile int PPM_diff[26]; // das diffenzierte Stick-Signal |
18 | volatile char Channels,tmpChannels = 0; |
35 | volatile char Channels,tmpChannels = 0; |
19 | volatile unsigned char NewPpmData = 1; |
36 | volatile unsigned char NewPpmData = 1; |
20 | 37 | ||
21 | //############################################################################ |
38 | //############################################################################ |
22 | //zum decodieren des PPM-Signals wird Timer1 mit seiner Input |
39 | //zum decodieren des PPM-Signals wird Timer1 mit seiner Input |
23 | //Capture Funktion benutzt: |
40 | //Capture Funktion benutzt: |
24 | void rc_sum_init (void) |
41 | void rc_sum_init (void) |
25 | //############################################################################ |
42 | //############################################################################ |
26 | { |
43 | { |
27 | unsigned char i; |
44 | unsigned char i; |
28 | for(i=0;i<26;i++) |
45 | for(i=0;i<26;i++) |
29 | { |
46 | { |
30 | PPM_in[i] = 0; |
47 | PPM_in[i] = 0; |
31 | PPM_diff[i] = 0; |
48 | PPM_diff[i] = 0; |
32 | } |
49 | } |
33 | 50 | ||
34 | AdNeutralGier = 0; |
51 | AdNeutralGier = 0; |
35 | AdNeutralRoll = 0; |
52 | AdNeutralRoll = 0; |
36 | AdNeutralNick = 0; |
53 | AdNeutralNick = 0; |
37 | return; |
54 | return; |
38 | } |
55 | } |
39 | 56 | ||
40 | #ifndef ACT_S3D_SUMMENSIGNAL |
57 | #ifndef ACT_S3D_SUMMENSIGNAL |
41 | //############################################################################ |
58 | //############################################################################ |
42 | //Diese Routine startet und inizialisiert den Timer für RC |
59 | //Diese Routine startet und inizialisiert den Timer für RC |
43 | ISR(TIMER1_CAPT_vect) |
60 | ISR(TIMER1_CAPT_vect) |
44 | //############################################################################ |
61 | //############################################################################ |
45 | { |
62 | { |
46 | if(!(EE_Parameter.ExtraConfig & CFG_SENSITIVE_RC)) |
63 | if(!(EE_Parameter.ExtraConfig & CFG_SENSITIVE_RC)) |
47 | { |
64 | { |
48 | static unsigned int AltICR=0; |
65 | static unsigned int AltICR=0; |
49 | signed int signal = 0,tmp; |
66 | signed int signal = 0,tmp; |
50 | static int index; |
67 | static int index; |
51 | 68 | ||
52 | signal = (unsigned int) ICR1 - AltICR; |
69 | signal = (unsigned int) ICR1 - AltICR; |
53 | AltICR = ICR1; |
70 | AltICR = ICR1; |
54 | //Syncronisationspause? (3.52 ms < signal < 25.6 ms) |
71 | //Syncronisationspause? (3.52 ms < signal < 25.6 ms) |
55 | if((signal > 1100) && (signal < 8000)) |
72 | if((signal > 1100) && (signal < 8000)) |
56 | { |
73 | { |
57 | Channels = index; |
74 | Channels = index; |
58 | if(index >= 4) NewPpmData = 0; // Null bedeutet: Neue Daten |
75 | if(index >= 4) NewPpmData = 0; // Null bedeutet: Neue Daten |
59 | index = 1; |
76 | index = 1; |
60 | } |
77 | } |
61 | else |
78 | else |
62 | { |
79 | { |
63 | if(index < 13) |
80 | if(index < 13) |
64 | { |
81 | { |
65 | if((signal > 250) && (signal < 687)) |
82 | if((signal > 250) && (signal < 687)) |
66 | { |
83 | { |
67 | signal -= 466; |
84 | signal -= 466; |
68 | // Stabiles Signal |
85 | // Stabiles Signal |
69 | if(abs(signal - PPM_in[index]) < 6) { if(SenderOkay < 200) SenderOkay += 10; else SenderOkay = 200;} |
86 | if(abs(signal - PPM_in[index]) < 6) { if(SenderOkay < 200) SenderOkay += 10; else SenderOkay = 200;} |
70 | tmp = (3 * (PPM_in[index]) + signal) / 4; |
87 | tmp = (3 * (PPM_in[index]) + signal) / 4; |
71 | if(tmp > signal+1) tmp--; else |
88 | if(tmp > signal+1) tmp--; else |
72 | if(tmp < signal-1) tmp++; |
89 | if(tmp < signal-1) tmp++; |
73 | if(SenderOkay >= 195) PPM_diff[index] = ((tmp - PPM_in[index]) / 3) * 3; |
90 | if(SenderOkay >= 195) PPM_diff[index] = ((tmp - PPM_in[index]) / 3) * 3; |
74 | else PPM_diff[index] = 0; |
91 | else PPM_diff[index] = 0; |
75 | PPM_in[index] = tmp; |
92 | PPM_in[index] = tmp; |
76 | } |
93 | } |
77 | index++; |
94 | index++; |
- | 95 | /****************************************************************************************************************** |
|
- | 96 | Arthur P: Modified the code to check the value of parameter 8. If 128 or higher then a HEF4017 is |
|
- | 97 | expected and will be used. Else J7 and J9 are seen as separate normal outputs. |
|
- | 98 | if((PlatinenVersion < 20) |
|
- | 99 | 20100802 Inserted changes into v.0.82b code. |
|
- | 100 | ******************************************************************************************************************/ |
|
- | 101 | ||
78 | if(PlatinenVersion < 20) |
102 | // if(PlatinenVersion < 20) |
- | 103 | ||
- | 104 | if((PlatinenVersion < 20) && (Parameter_UserParam8 < 128 )) |
|
- | 105 | /****************************************************************************************************************** |
|
- | 106 | Arthur P: End of modification ot if statement. |
|
- | 107 | ******************************************************************************************************************/ |
|
79 | { |
108 | { |
80 | if(index == 5) J3High; else J3Low; // Servosignal an J3 anlegen |
109 | if(index == 5) J3High; else J3Low; // Servosignal an J3 anlegen |
81 | if(index == 6) J4High; else J4Low; // Servosignal an J4 anlegen |
110 | if(index == 6) J4High; else J4Low; // Servosignal an J4 anlegen |
82 | if(index == 7) J5High; else J5Low; // Servosignal an J5 anlegen |
111 | if(index == 7) J5High; else J5Low; // Servosignal an J5 anlegen |
83 | } |
112 | } |
84 | } |
113 | } |
85 | } |
114 | } |
86 | } |
115 | } |
87 | else |
116 | else |
88 | { |
117 | { |
89 | static unsigned int AltICR=0; |
118 | static unsigned int AltICR=0; |
90 | static int ppm_in[13]; |
119 | static int ppm_in[13]; |
91 | static int ppm_diff[13]; |
120 | static int ppm_diff[13]; |
92 | static int old_ppm_in[13]; |
121 | static int old_ppm_in[13]; |
93 | static int old_ppm_diff[13]; |
122 | static int old_ppm_diff[13]; |
94 | signed int signal = 0,tmp; |
123 | signed int signal = 0,tmp; |
95 | static unsigned char index, okay_cnt = 0; |
124 | static unsigned char index, okay_cnt = 0; |
96 | signal = (unsigned int) ICR1 - AltICR; |
125 | signal = (unsigned int) ICR1 - AltICR; |
97 | AltICR = ICR1; |
126 | AltICR = ICR1; |
98 | //Syncronisationspause? (3.52 ms < signal < 25.6 ms) |
127 | //Syncronisationspause? (3.52 ms < signal < 25.6 ms) |
99 | if((signal > 1100) && (signal < 8000)) |
128 | if((signal > 1100) && (signal < 8000)) |
100 | { |
129 | { |
101 | tmpChannels = index; |
130 | tmpChannels = index; |
102 | if(tmpChannels >= 4 && Channels == tmpChannels) |
131 | if(tmpChannels >= 4 && Channels == tmpChannels) |
103 | { |
132 | { |
104 | if(okay_cnt > 10) |
133 | if(okay_cnt > 10) |
105 | { |
134 | { |
106 | NewPpmData = 0; // Null bedeutet: Neue Daten |
135 | NewPpmData = 0; // Null bedeutet: Neue Daten |
107 | for(index = 0; index < 13; index++) |
136 | for(index = 0; index < 13; index++) |
108 | { |
137 | { |
109 | if(okay_cnt > 30) |
138 | if(okay_cnt > 30) |
110 | { |
139 | { |
111 | old_ppm_in[index] = PPM_in[index]; |
140 | old_ppm_in[index] = PPM_in[index]; |
112 | old_ppm_diff[index] = PPM_diff[index]; |
141 | old_ppm_diff[index] = PPM_diff[index]; |
113 | } |
142 | } |
114 | PPM_in[index] = ppm_in[index]; |
143 | PPM_in[index] = ppm_in[index]; |
115 | PPM_diff[index] = ppm_diff[index]; |
144 | PPM_diff[index] = ppm_diff[index]; |
116 | } |
145 | } |
117 | } |
146 | } |
118 | if(okay_cnt < 255) okay_cnt++; |
147 | if(okay_cnt < 255) okay_cnt++; |
119 | } |
148 | } |
120 | else |
149 | else |
121 | { |
150 | { |
122 | if(okay_cnt > 100) okay_cnt = 10; else okay_cnt = 0; |
151 | if(okay_cnt > 100) okay_cnt = 10; else okay_cnt = 0; |
123 | ROT_ON; |
152 | ROT_ON; |
124 | } |
153 | } |
125 | index = 1; |
154 | index = 1; |
126 | if(!MotorenEin) Channels = tmpChannels; |
155 | if(!MotorenEin) Channels = tmpChannels; |
127 | } |
156 | } |
128 | else |
157 | else |
129 | { |
158 | { |
130 | if(index < 13) |
159 | if(index < 13) |
131 | { |
160 | { |
132 | if((signal > 250) && (signal < 687)) |
161 | if((signal > 250) && (signal < 687)) |
133 | { |
162 | { |
134 | signal -= 466; |
163 | signal -= 466; |
135 | // Stabiles Signal |
164 | // Stabiles Signal |
136 | if((abs(signal - ppm_in[index]) < 6)) |
165 | if((abs(signal - ppm_in[index]) < 6)) |
137 | { |
166 | { |
138 | if(okay_cnt > 25) SenderOkay += 10; |
167 | if(okay_cnt > 25) SenderOkay += 10; |
139 | else |
168 | else |
140 | if(okay_cnt > 10) SenderOkay += 2; |
169 | if(okay_cnt > 10) SenderOkay += 2; |
141 | if(SenderOkay > 200) SenderOkay = 200; |
170 | if(SenderOkay > 200) SenderOkay = 200; |
142 | } |
171 | } |
143 | tmp = (3 * (ppm_in[index]) + signal) / 4; |
172 | tmp = (3 * (ppm_in[index]) + signal) / 4; |
144 | if(tmp > signal+1) tmp--; else |
173 | if(tmp > signal+1) tmp--; else |
145 | if(tmp < signal-1) tmp++; |
174 | if(tmp < signal-1) tmp++; |
146 | if(SenderOkay >= 190) ppm_diff[index] = ((tmp - ppm_in[index]) / 3) * 3; |
175 | if(SenderOkay >= 190) ppm_diff[index] = ((tmp - ppm_in[index]) / 3) * 3; |
147 | else ppm_diff[index] = 0; |
176 | else ppm_diff[index] = 0; |
148 | ppm_in[index] = tmp; |
177 | ppm_in[index] = tmp; |
149 | } |
178 | } |
150 | else ROT_ON; |
179 | else ROT_ON; |
- | 180 | /****************************************************************************************************************** |
|
- | 181 | Arthur P: Modified the code to check the value of parameter 8. If 128 or higher then a HEF4017 is |
|
- | 182 | expected and will be used. Else J7 and J9 are seen as separate normal outputs. |
|
- | 183 | if((PlatinenVersion < 20) |
|
- | 184 | 20100802 Inserted changes into v.0.82b code. |
|
- | 185 | ******************************************************************************************************************/ |
|
- | 186 | ||
151 | if(PlatinenVersion < 20) |
187 | // if(PlatinenVersion < 20) |
- | 188 | ||
- | 189 | if((PlatinenVersion < 20) && (Parameter_UserParam8 < 128 )) |
|
- | 190 | /****************************************************************************************************************** |
|
- | 191 | Arthur P: End of modification ot if statement. |
|
- | 192 | ******************************************************************************************************************/ |
|
152 | { |
193 | { |
153 | if(index == 5) J3High; else J3Low; // Servosignal an J3 anlegen |
194 | if(index == 5) J3High; else J3Low; // Servosignal an J3 anlegen |
154 | if(index == 6) J4High; else J4Low; // Servosignal an J4 anlegen |
195 | if(index == 6) J4High; else J4Low; // Servosignal an J4 anlegen |
155 | if(index == 7) J5High; else J5Low; // Servosignal an J5 anlegen |
196 | if(index == 7) J5High; else J5Low; // Servosignal an J5 anlegen |
156 | } |
197 | } |
157 | } |
198 | } |
158 | if(index < 20) index++; |
199 | if(index < 20) index++; |
159 | else |
200 | else |
160 | if(index == 20) |
201 | if(index == 20) |
161 | { |
202 | { |
162 | unsigned char i; |
203 | unsigned char i; |
163 | ROT_ON; |
204 | ROT_ON; |
164 | index = 30; |
205 | index = 30; |
165 | for(i=0;i<13;i++) // restore from older data |
206 | for(i=0;i<13;i++) // restore from older data |
166 | { |
207 | { |
167 | PPM_in[i] = old_ppm_in[i]; |
208 | PPM_in[i] = old_ppm_in[i]; |
168 | PPM_diff[i] = 0; |
209 | PPM_diff[i] = 0; |
169 | // okay_cnt /= 2; |
210 | // okay_cnt /= 2; |
170 | } |
211 | } |
171 | } |
212 | } |
172 | } |
213 | } |
173 | } |
214 | } |
174 | } |
215 | } |
175 | 216 | ||
176 | #else |
217 | #else |
177 | //############################################################################ |
218 | //############################################################################ |
178 | //Diese Routine startet und inizialisiert den Timer für RC |
219 | //Diese Routine startet und inizialisiert den Timer für RC |
179 | ISR(TIMER1_CAPT_vect) |
220 | ISR(TIMER1_CAPT_vect) |
180 | //############################################################################ |
221 | //############################################################################ |
181 | 222 | ||
182 | { |
223 | { |
183 | static unsigned int AltICR=0; |
224 | static unsigned int AltICR=0; |
184 | signed int signal = 0,tmp; |
225 | signed int signal = 0,tmp; |
185 | static int index; |
226 | static int index; |
186 | 227 | ||
187 | signal = (unsigned int) ICR1 - AltICR; |
228 | signal = (unsigned int) ICR1 - AltICR; |
188 | signal /= 2; |
229 | signal /= 2; |
189 | AltICR = ICR1; |
230 | AltICR = ICR1; |
190 | //Syncronisationspause? |
231 | //Syncronisationspause? |
191 | if((signal > 1100*2) && (signal < 8000*2)) |
232 | if((signal > 1100*2) && (signal < 8000*2)) |
192 | { |
233 | { |
193 | if(index >= 4) NewPpmData = 0; // Null bedeutet: Neue Daten |
234 | if(index >= 4) NewPpmData = 0; // Null bedeutet: Neue Daten |
194 | index = 1; |
235 | index = 1; |
195 | } |
236 | } |
196 | else |
237 | else |
197 | { |
238 | { |
198 | if(index < 13) |
239 | if(index < 13) |
199 | { |
240 | { |
200 | if((signal > 250) && (signal < 687*2)) |
241 | if((signal > 250) && (signal < 687*2)) |
201 | { |
242 | { |
202 | signal -= 962; |
243 | signal -= 962; |
203 | // Stabiles Signal |
244 | // Stabiles Signal |
204 | if(abs(signal - PPM_in[index]) < 6) { if(SenderOkay < 200) SenderOkay += 10;} |
245 | if(abs(signal - PPM_in[index]) < 6) { if(SenderOkay < 200) SenderOkay += 10;} |
205 | tmp = (3 * (PPM_in[index]) + signal) / 4; |
246 | tmp = (3 * (PPM_in[index]) + signal) / 4; |
206 | if(tmp > signal+1) tmp--; else |
247 | if(tmp > signal+1) tmp--; else |
207 | if(tmp < signal-1) tmp++; |
248 | if(tmp < signal-1) tmp++; |
208 | if(SenderOkay >= 195) PPM_diff[index] = ((tmp - PPM_in[index]) / 3) * 3; |
249 | if(SenderOkay >= 195) PPM_diff[index] = ((tmp - PPM_in[index]) / 3) * 3; |
209 | else PPM_diff[index] = 0; |
250 | else PPM_diff[index] = 0; |
210 | PPM_in[index] = tmp; |
251 | PPM_in[index] = tmp; |
211 | } |
252 | } |
212 | index++; |
253 | index++; |
213 | } |
254 | } |
214 | } |
255 | } |
215 | } |
256 | } |
216 | #endif |
257 | #endif |
217 | 258 | ||
218 | 259 |