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