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