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 |
||
1171 | hbuss | 26 | // TCCR1B=(1<<CS11)|(0<<CS10)|(1<<ICES1)|(1<<ICNC1); //timer1 prescale 64 |
1 | ingob | 27 | TIMSK1 |= _BV(ICIE1); |
28 | AdNeutralGier = 0; |
||
29 | AdNeutralRoll = 0; |
||
30 | AdNeutralNick = 0; |
||
31 | return; |
||
32 | } |
||
1278 | hbuss | 33 | /* |
34 | //############################################################################ |
||
35 | //Diese Routine startet und inizialisiert den Timer für RC |
||
36 | SIGNAL(SIG_INPUT_CAPTURE1) |
||
37 | //############################################################################ |
||
1 | ingob | 38 | |
1278 | hbuss | 39 | { |
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; |
||
46 | //Syncronisationspause? |
||
47 | if((signal > 1100) && (signal < 8000)) |
||
48 | { |
||
49 | if(index >= 4) NewPpmData = 0; // Null bedeutet: Neue Daten |
||
50 | index = 1; |
||
51 | } |
||
52 | else |
||
53 | { |
||
54 | if(index < 10) |
||
55 | { |
||
56 | if((signal > 250) && (signal < 687)) |
||
57 | { |
||
58 | signal -= 466; |
||
59 | // Stabiles Signal |
||
60 | if(abs(signal - PPM_in[index]) < 6) { if(SenderOkay < 200) SenderOkay += 10; else SenderOkay = 200;} |
||
61 | tmp = (3 * (PPM_in[index]) + signal) / 4; |
||
62 | if(tmp > signal+1) tmp--; else |
||
63 | if(tmp < signal-1) tmp++; |
||
64 | if(SenderOkay >= 195) PPM_diff[index] = ((tmp - PPM_in[index]) / 3) * 3; |
||
65 | else PPM_diff[index] = 0; |
||
66 | PPM_in[index] = tmp; |
||
67 | } |
||
68 | index++; |
||
69 | if(index == 5) J3High; else J3Low; // Servosignal an J3 anlegen |
||
70 | if(index == 6) J4High; else J4Low; // Servosignal an J4 anlegen |
||
71 | if(index == 7) J5High; else J5Low; // Servosignal an J5 anlegen |
||
72 | } |
||
73 | } |
||
74 | } |
||
75 | */ |
||
76 | |||
77 | |||
1 | ingob | 78 | //############################################################################ |
79 | //Diese Routine startet und inizialisiert den Timer für RC |
||
80 | SIGNAL(SIG_INPUT_CAPTURE1) |
||
81 | //############################################################################ |
||
82 | |||
83 | { |
||
84 | static unsigned int AltICR=0; |
||
1268 | hbuss | 85 | static int ppm_in[11]; |
86 | static int ppm_diff[11]; |
||
87 | static int old_ppm_in[11]; |
||
88 | static int old_ppm_diff[11]; |
||
173 | holgerb | 89 | signed int signal = 0,tmp; |
1268 | hbuss | 90 | static unsigned char index, okay_cnt = 0; |
1 | ingob | 91 | signal = (unsigned int) ICR1 - AltICR; |
92 | AltICR = ICR1; |
||
93 | //Syncronisationspause? |
||
513 | hbuss | 94 | if((signal > 1100) && (signal < 8000)) |
1 | ingob | 95 | { |
1268 | hbuss | 96 | tmpChannels = index; |
97 | if(tmpChannels >= 4 && Channels == tmpChannels) |
||
98 | { |
||
1276 | hbuss | 99 | if(okay_cnt > 10) |
1268 | hbuss | 100 | { |
101 | NewPpmData = 0; // Null bedeutet: Neue Daten |
||
102 | for(index = 0; index < 11; index++) |
||
103 | { |
||
104 | if(okay_cnt > 30) |
||
105 | { |
||
106 | old_ppm_in[index] = PPM_in[index]; |
||
107 | old_ppm_diff[index] = PPM_diff[index]; |
||
108 | } |
||
109 | PPM_in[index] = ppm_in[index]; |
||
110 | PPM_diff[index] = ppm_diff[index]; |
||
111 | } |
||
112 | } |
||
113 | if(okay_cnt < 255) okay_cnt++; |
||
114 | } |
||
1276 | hbuss | 115 | else |
1278 | hbuss | 116 | { |
117 | if(okay_cnt > 100) okay_cnt = 10; else okay_cnt = 0; |
||
118 | ROT_ON; |
||
119 | } |
||
1 | ingob | 120 | index = 1; |
1268 | hbuss | 121 | if(!MotorenEin) Channels = tmpChannels; |
1 | ingob | 122 | } |
123 | else |
||
124 | { |
||
125 | if(index < 10) |
||
126 | { |
||
127 | if((signal > 250) && (signal < 687)) |
||
128 | { |
||
129 | signal -= 466; |
||
130 | // Stabiles Signal |
||
1271 | hbuss | 131 | if((abs(signal - ppm_in[index]) < 6)) |
132 | { |
||
1276 | hbuss | 133 | if(okay_cnt > 25) SenderOkay += 10; |
1271 | hbuss | 134 | else |
1276 | hbuss | 135 | if(okay_cnt > 10) SenderOkay += 2; |
136 | if(SenderOkay > 200) SenderOkay = 200; |
||
1271 | hbuss | 137 | } |
1268 | hbuss | 138 | tmp = (3 * (ppm_in[index]) + signal) / 4; |
604 | hbuss | 139 | if(tmp > signal+1) tmp--; else |
140 | if(tmp < signal-1) tmp++; |
||
1268 | hbuss | 141 | if(SenderOkay >= 190) ppm_diff[index] = ((tmp - ppm_in[index]) / 3) * 3; |
142 | else ppm_diff[index] = 0; |
||
143 | ppm_in[index] = tmp; |
||
1 | ingob | 144 | } |
1268 | hbuss | 145 | else ROT_ON; |
146 | if(index == 5) J3High; else J3Low; // Servosignal an J3 anlegen |
||
147 | if(index == 6) J4High; else J4Low; // Servosignal an J4 anlegen |
||
148 | if(index == 7) J5High; else J5Low; // Servosignal an J5 anlegen |
||
149 | } |
||
150 | if(index < 20) index++; |
||
1276 | hbuss | 151 | else |
152 | if(index == 20) |
||
1268 | hbuss | 153 | { |
1276 | hbuss | 154 | unsigned char i; |
1278 | hbuss | 155 | ROT_ON; |
1276 | hbuss | 156 | index = 30; |
1268 | hbuss | 157 | for(i=0;i<11;i++) // restore from older data |
158 | { |
||
1276 | hbuss | 159 | PPM_in[i] = old_ppm_in[i]; |
160 | PPM_diff[i] = 0; |
||
161 | // okay_cnt /= 2; |
||
1268 | hbuss | 162 | } |
163 | } |
||
164 | } |
||
1276 | hbuss | 165 | DebugOut.Analog[16] = okay_cnt; |
166 | DebugOut.Analog[17] = PPM_in[2]; |
||
1171 | hbuss | 167 | } |
168 | |||
1278 | hbuss | 169 | |
1171 | hbuss | 170 | /* |
171 | //############################################################################ |
||
172 | //Diese Routine startet und inizialisiert den Timer für RC |
||
173 | SIGNAL(SIG_INPUT_CAPTURE1) |
||
174 | //############################################################################ |
||
175 | |||
176 | { |
||
177 | static unsigned int AltICR=0; |
||
178 | signed int signal = 0,tmp; |
||
179 | static int index; |
||
180 | |||
181 | signal = (unsigned int) ICR1 - AltICR; |
||
182 | DebugOut.Analog[16] = signal; |
||
183 | signal /= 2; |
||
184 | AltICR = ICR1; |
||
185 | //Syncronisationspause? |
||
186 | if((signal > 1100*2) && (signal < 8000*2)) |
||
187 | { |
||
188 | if(index >= 4) NewPpmData = 0; // Null bedeutet: Neue Daten |
||
189 | index = 1; |
||
190 | } |
||
191 | else |
||
192 | { |
||
193 | if(index < 10) |
||
194 | { |
||
195 | if((signal > 250) && (signal < 687*2)) |
||
196 | { |
||
197 | signal -= 962; |
||
198 | // Stabiles Signal |
||
199 | if(abs(signal - PPM_in[index]) < 6) { if(SenderOkay < 200) SenderOkay += 10;} |
||
200 | tmp = (3 * (PPM_in[index]) + signal) / 4; |
||
201 | if(tmp > signal+1) tmp--; else |
||
202 | if(tmp < signal-1) tmp++; |
||
203 | if(SenderOkay >= 195) PPM_diff[index] = ((tmp - PPM_in[index]) / 3) * 3; |
||
204 | else PPM_diff[index] = 0; |
||
205 | PPM_in[index] = tmp; |
||
206 | } |
||
207 | index++; |
||
1155 | hbuss | 208 | if(index == 5) J3High; else J3Low; // Servosignal an J3 anlegen |
1171 | hbuss | 209 | if(index == 2) J4High; else J4Low; // Servosignal an J4 anlegen |
1155 | hbuss | 210 | if(index == 7) J5High; else J5Low; // Servosignal an J5 anlegen |
1 | ingob | 211 | } |
212 | } |
||
213 | } |
||
1171 | hbuss | 214 | */ |
1 | ingob | 215 | |
216 | |||
217 |