Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
2003 | - | 1 | /*####################################################################################### |
2 | Decodieren eines RC Summen Signals |
||
3 | #######################################################################################*/ |
||
4 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
||
5 | // + Copyright (c) Holger Buss, Ingo Busker |
||
6 | // + only for non-profit use |
||
7 | // + 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 |
||
9 | // + see the File "License.txt" for further Informations |
||
10 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
||
11 | |||
12 | #include "rc.h" |
||
13 | #include "main.h" |
||
14 | // Achtung: ACT_S3D_SUMMENSIGNAL wird in der Main.h gesetzt |
||
15 | |||
16 | volatile int PPM_in[26]; |
||
17 | volatile int PPM_diff[26]; // das diffenzierte Stick-Signal |
||
18 | volatile char Channels,tmpChannels = 0; |
||
19 | volatile unsigned char NewPpmData = 1; |
||
20 | unsigned int PPM_Neutral = 466; |
||
21 | |||
22 | //############################################################################ |
||
23 | //zum decodieren des PPM-Signals wird Timer1 mit seiner Input |
||
24 | //Capture Funktion benutzt: |
||
25 | void rc_sum_init (void) |
||
26 | //############################################################################ |
||
27 | { |
||
28 | unsigned char i; |
||
29 | for(i=0;i<26;i++) |
||
30 | { |
||
31 | if(i < 5) PPM_in[i] = 0; else PPM_in[i] = -126; |
||
32 | PPM_diff[i] = 0; |
||
33 | } |
||
34 | |||
35 | AdNeutralGier = 0; |
||
36 | AdNeutralRoll = 0; |
||
37 | AdNeutralNick = 0; |
||
38 | return; |
||
39 | } |
||
40 | |||
41 | #ifndef ACT_S3D_SUMMENSIGNAL |
||
42 | //############################################################################ |
||
43 | //Diese Routine startet und inizialisiert den Timer für RC |
||
44 | ISR(TIMER1_CAPT_vect) |
||
45 | //############################################################################ |
||
46 | { |
||
47 | if(!(EE_Parameter.ExtraConfig & CFG_SENSITIVE_RC)) |
||
48 | { |
||
49 | static unsigned int AltICR=0; |
||
50 | signed int signal = 0,tmp; |
||
51 | static int index; |
||
52 | |||
53 | signal = (unsigned int) ICR1 - AltICR; |
||
54 | AltICR = ICR1; |
||
55 | //Syncronisationspause? (3.52 ms < signal < 25.6 ms) |
||
56 | if((signal > 1100) && (signal < 8000)) |
||
57 | { |
||
58 | Channels = index; |
||
59 | if(index >= 4) NewPpmData = 0; // Null bedeutet: Neue Daten |
||
60 | index = 1; |
||
61 | } |
||
62 | else |
||
63 | { |
||
64 | if(index < 13) |
||
65 | { |
||
66 | if((signal > 250) && (signal < 687)) |
||
67 | { |
||
68 | signal -= PPM_Neutral; |
||
69 | // Stabiles Signal |
||
70 | if(abs(signal - PPM_in[index]) < 6) { if(SenderOkay < 200) SenderOkay += 10; else SenderOkay = 200;} |
||
71 | tmp = (3 * (PPM_in[index]) + signal) / 4; |
||
72 | if(tmp > signal+1) tmp--; else |
||
73 | if(tmp < signal-1) tmp++; |
||
74 | if(SenderOkay >= 195) PPM_diff[index] = ((tmp - PPM_in[index]) / 3) * 3; |
||
75 | else PPM_diff[index] = 0; |
||
76 | PPM_in[index] = tmp; |
||
77 | } |
||
78 | index++; |
||
79 | if(PlatinenVersion < 20) |
||
80 | { |
||
81 | if(index == 5) J3High; else J3Low; // Servosignal an J3 anlegen |
||
82 | if(index == 6) J4High; else J4Low; // Servosignal an J4 anlegen |
||
83 | if(index == 7) J5High; else J5Low; // Servosignal an J5 anlegen |
||
84 | } |
||
85 | } |
||
86 | } |
||
87 | } |
||
88 | else |
||
89 | { |
||
90 | static unsigned int AltICR=0; |
||
91 | static int ppm_in[13]; |
||
92 | static int ppm_diff[13]; |
||
93 | static int old_ppm_in[13]; |
||
94 | static int old_ppm_diff[13]; |
||
95 | signed int signal = 0,tmp; |
||
96 | static unsigned char index, okay_cnt = 0; |
||
97 | signal = (unsigned int) ICR1 - AltICR; |
||
98 | AltICR = ICR1; |
||
99 | //Syncronisationspause? (3.52 ms < signal < 25.6 ms) |
||
100 | if((signal > 1100) && (signal < 8000)) |
||
101 | { |
||
102 | tmpChannels = index; |
||
103 | if(tmpChannels >= 4 && Channels == tmpChannels) |
||
104 | { |
||
105 | if(okay_cnt > 10) |
||
106 | { |
||
107 | NewPpmData = 0; // Null bedeutet: Neue Daten |
||
108 | for(index = 0; index < 13; index++) |
||
109 | { |
||
110 | if(okay_cnt > 30) |
||
111 | { |
||
112 | old_ppm_in[index] = PPM_in[index]; |
||
113 | old_ppm_diff[index] = PPM_diff[index]; |
||
114 | } |
||
115 | PPM_in[index] = ppm_in[index]; |
||
116 | PPM_diff[index] = ppm_diff[index]; |
||
117 | } |
||
118 | } |
||
119 | if(okay_cnt < 255) okay_cnt++; |
||
120 | } |
||
121 | else |
||
122 | { |
||
123 | if(okay_cnt > 100) okay_cnt = 10; else okay_cnt = 0; |
||
124 | ROT_ON; |
||
125 | } |
||
126 | index = 1; |
||
127 | if(!MotorenEin) Channels = tmpChannels; |
||
128 | } |
||
129 | else |
||
130 | { |
||
131 | if(index < 13) |
||
132 | { |
||
133 | if((signal > 250) && (signal < 687)) |
||
134 | { |
||
135 | signal -= PPM_Neutral; |
||
136 | // Stabiles Signal |
||
137 | if((abs(signal - ppm_in[index]) < 6)) |
||
138 | { |
||
139 | if(okay_cnt > 25) SenderOkay += 10; |
||
140 | else |
||
141 | if(okay_cnt > 10) SenderOkay += 2; |
||
142 | if(SenderOkay > 200) SenderOkay = 200; |
||
143 | } |
||
144 | tmp = (3 * (ppm_in[index]) + signal) / 4; |
||
145 | if(tmp > signal+1) tmp--; else |
||
146 | if(tmp < signal-1) tmp++; |
||
147 | if(SenderOkay >= 190) ppm_diff[index] = ((tmp - ppm_in[index]) / 3) * 3; |
||
148 | else ppm_diff[index] = 0; |
||
149 | ppm_in[index] = tmp; |
||
150 | } |
||
151 | else ROT_ON; |
||
152 | if(PlatinenVersion < 20) |
||
153 | { |
||
154 | if(index == 5) J3High; else J3Low; // Servosignal an J3 anlegen |
||
155 | if(index == 6) J4High; else J4Low; // Servosignal an J4 anlegen |
||
156 | if(index == 7) J5High; else J5Low; // Servosignal an J5 anlegen |
||
157 | } |
||
158 | } |
||
159 | if(index < 20) index++; |
||
160 | else |
||
161 | if(index == 20) |
||
162 | { |
||
163 | unsigned char i; |
||
164 | ROT_ON; |
||
165 | index = 30; |
||
166 | for(i=0;i<13;i++) // restore from older data |
||
167 | { |
||
168 | PPM_in[i] = old_ppm_in[i]; |
||
169 | PPM_diff[i] = 0; |
||
170 | // okay_cnt /= 2; |
||
171 | } |
||
172 | } |
||
173 | } |
||
174 | } |
||
175 | } |
||
176 | |||
177 | #else |
||
178 | //############################################################################ |
||
179 | //Diese Routine startet und inizialisiert den Timer für RC |
||
180 | ISR(TIMER1_CAPT_vect) |
||
181 | //############################################################################ |
||
182 | |||
183 | { |
||
184 | static unsigned int AltICR=0; |
||
185 | signed int signal = 0,tmp; |
||
186 | static int index; |
||
187 | |||
188 | signal = (unsigned int) ICR1 - AltICR; |
||
189 | signal /= 2; |
||
190 | AltICR = ICR1; |
||
191 | //Syncronisationspause? |
||
192 | if((signal > 1100*2) && (signal < 8000*2)) |
||
193 | { |
||
194 | if(index >= 4) NewPpmData = 0; // Null bedeutet: Neue Daten |
||
195 | index = 1; |
||
196 | } |
||
197 | else |
||
198 | { |
||
199 | if(index < 13) |
||
200 | { |
||
201 | if((signal > 250) && (signal < 687*2)) |
||
202 | { |
||
203 | signal -= 962; |
||
204 | // Stabiles Signal |
||
205 | if(abs(signal - PPM_in[index]) < 6) { if(SenderOkay < 200) SenderOkay += 10;} |
||
206 | tmp = (3 * (PPM_in[index]) + signal) / 4; |
||
207 | if(tmp > signal+1) tmp--; else |
||
208 | if(tmp < signal-1) tmp++; |
||
209 | if(SenderOkay >= 195) PPM_diff[index] = ((tmp - PPM_in[index]) / 3) * 3; |
||
210 | else PPM_diff[index] = 0; |
||
211 | PPM_in[index] = tmp; |
||
212 | } |
||
213 | index++; |
||
214 | } |
||
215 | } |
||
216 | } |
||
217 | #endif |
||
218 |