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