Rev 1738 | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
1 | ingob | 1 | /*####################################################################################### |
1561 | killagreg | 2 | Decodieren eines RC Summen Signals |
1 | ingob | 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" |
||
1638 | holgerb | 14 | // Achtung: ACT_S3D_SUMMENSIGNAL wird in der Main.h gesetzt |
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 | } |
||
1757 | - | 33 | PPM_in[13] = Parameter_UserParam5 -110; // MartinR: Initialisierungswerte für die seriellen Potis für Jeti+ |
34 | PPM_in[14] = Parameter_UserParam6 -110; // MartinR: Initialisierungswerte für die seriellen Potis für Jeti+ |
||
1438 | ingob | 35 | |
1 | ingob | 36 | AdNeutralGier = 0; |
37 | AdNeutralRoll = 0; |
||
38 | AdNeutralNick = 0; |
||
39 | return; |
||
40 | } |
||
1309 | hbuss | 41 | |
1356 | hbuss | 42 | #ifndef ACT_S3D_SUMMENSIGNAL |
1278 | hbuss | 43 | //############################################################################ |
44 | //Diese Routine startet und inizialisiert den Timer für RC |
||
1561 | killagreg | 45 | ISR(TIMER1_CAPT_vect) |
1278 | hbuss | 46 | //############################################################################ |
47 | { |
||
1309 | hbuss | 48 | if(!(EE_Parameter.ExtraConfig & CFG_SENSITIVE_RC)) |
49 | { |
||
1278 | hbuss | 50 | static unsigned int AltICR=0; |
51 | signed int signal = 0,tmp; |
||
1561 | killagreg | 52 | static int index; |
53 | |||
54 | signal = (unsigned int) ICR1 - AltICR; |
||
55 | AltICR = ICR1; |
||
1283 | hbuss | 56 | //Syncronisationspause? (3.52 ms < signal < 25.6 ms) |
1561 | killagreg | 57 | if((signal > 1100) && (signal < 8000)) |
1278 | hbuss | 58 | { |
1320 | hbuss | 59 | Channels = index; |
1278 | hbuss | 60 | if(index >= 4) NewPpmData = 0; // Null bedeutet: Neue Daten |
1561 | killagreg | 61 | index = 1; |
62 | } |
||
63 | else |
||
1278 | hbuss | 64 | { |
1377 | hbuss | 65 | if(index < 13) |
1278 | hbuss | 66 | { |
1561 | killagreg | 67 | if((signal > 250) && (signal < 687)) |
68 | { |
||
1278 | hbuss | 69 | signal -= 466; |
70 | // Stabiles Signal |
||
71 | if(abs(signal - PPM_in[index]) < 6) { if(SenderOkay < 200) SenderOkay += 10; else SenderOkay = 200;} |
||
1561 | killagreg | 72 | tmp = (3 * (PPM_in[index]) + signal) / 4; |
1278 | hbuss | 73 | if(tmp > signal+1) tmp--; else |
1561 | killagreg | 74 | if(tmp < signal-1) tmp++; |
75 | if(SenderOkay >= 195) PPM_diff[index] = ((tmp - PPM_in[index]) / 3) * 3; |
||
1278 | hbuss | 76 | else PPM_diff[index] = 0; |
77 | PPM_in[index] = tmp; |
||
1561 | killagreg | 78 | } |
79 | index++; |
||
1639 | holgerb | 80 | if(PlatinenVersion < 20) |
81 | { |
||
82 | if(index == 5) J3High; else J3Low; // Servosignal an J3 anlegen |
||
83 | if(index == 6) J4High; else J4Low; // Servosignal an J4 anlegen |
||
84 | if(index == 7) J5High; else J5Low; // Servosignal an J5 anlegen |
||
85 | } |
||
1278 | hbuss | 86 | } |
87 | } |
||
1309 | hbuss | 88 | } |
1561 | killagreg | 89 | else |
1309 | hbuss | 90 | { |
1 | ingob | 91 | static unsigned int AltICR=0; |
1377 | hbuss | 92 | static int ppm_in[13]; |
1561 | killagreg | 93 | static int ppm_diff[13]; |
1377 | hbuss | 94 | static int old_ppm_in[13]; |
1561 | killagreg | 95 | static int old_ppm_diff[13]; |
173 | holgerb | 96 | signed int signal = 0,tmp; |
1561 | killagreg | 97 | static unsigned char index, okay_cnt = 0; |
98 | signal = (unsigned int) ICR1 - AltICR; |
||
99 | AltICR = ICR1; |
||
1283 | hbuss | 100 | //Syncronisationspause? (3.52 ms < signal < 25.6 ms) |
1561 | killagreg | 101 | if((signal > 1100) && (signal < 8000)) |
1 | ingob | 102 | { |
1268 | hbuss | 103 | tmpChannels = index; |
1561 | killagreg | 104 | if(tmpChannels >= 4 && Channels == tmpChannels) |
1268 | hbuss | 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 | { |
1561 | killagreg | 111 | if(okay_cnt > 30) |
1268 | hbuss | 112 | { |
113 | old_ppm_in[index] = PPM_in[index]; |
||
114 | old_ppm_diff[index] = PPM_diff[index]; |
||
1561 | killagreg | 115 | } |
1268 | hbuss | 116 | PPM_in[index] = ppm_in[index]; |
117 | PPM_diff[index] = ppm_diff[index]; |
||
118 | } |
||
119 | } |
||
120 | if(okay_cnt < 255) okay_cnt++; |
||
121 | } |
||
1561 | killagreg | 122 | else |
1278 | hbuss | 123 | { |
124 | if(okay_cnt > 100) okay_cnt = 10; else okay_cnt = 0; |
||
125 | ROT_ON; |
||
126 | } |
||
1561 | killagreg | 127 | index = 1; |
1268 | hbuss | 128 | if(!MotorenEin) Channels = tmpChannels; |
1561 | killagreg | 129 | } |
130 | else |
||
1 | ingob | 131 | { |
1377 | hbuss | 132 | if(index < 13) |
1 | ingob | 133 | { |
1561 | killagreg | 134 | if((signal > 250) && (signal < 687)) |
135 | { |
||
1 | ingob | 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; |
1561 | killagreg | 141 | else |
142 | if(okay_cnt > 10) SenderOkay += 2; |
||
1276 | hbuss | 143 | if(SenderOkay > 200) SenderOkay = 200; |
1271 | hbuss | 144 | } |
1561 | killagreg | 145 | tmp = (3 * (ppm_in[index]) + signal) / 4; |
604 | hbuss | 146 | if(tmp > signal+1) tmp--; else |
1561 | killagreg | 147 | if(tmp < signal-1) tmp++; |
148 | if(SenderOkay >= 190) ppm_diff[index] = ((tmp - ppm_in[index]) / 3) * 3; |
||
1268 | hbuss | 149 | else ppm_diff[index] = 0; |
150 | ppm_in[index] = tmp; |
||
1561 | killagreg | 151 | } |
1268 | hbuss | 152 | else ROT_ON; |
1639 | holgerb | 153 | if(PlatinenVersion < 20) |
154 | { |
||
155 | if(index == 5) J3High; else J3Low; // Servosignal an J3 anlegen |
||
156 | if(index == 6) J4High; else J4Low; // Servosignal an J4 anlegen |
||
157 | if(index == 7) J5High; else J5Low; // Servosignal an J5 anlegen |
||
158 | } |
||
1268 | hbuss | 159 | } |
1561 | killagreg | 160 | if(index < 20) index++; |
1276 | hbuss | 161 | else |
1561 | killagreg | 162 | if(index == 20) |
1268 | hbuss | 163 | { |
1276 | hbuss | 164 | unsigned char i; |
1278 | hbuss | 165 | ROT_ON; |
1276 | hbuss | 166 | index = 30; |
1377 | hbuss | 167 | for(i=0;i<13;i++) // restore from older data |
1268 | hbuss | 168 | { |
1276 | hbuss | 169 | PPM_in[i] = old_ppm_in[i]; |
170 | PPM_diff[i] = 0; |
||
171 | // okay_cnt /= 2; |
||
1268 | hbuss | 172 | } |
173 | } |
||
174 | } |
||
1309 | hbuss | 175 | } |
1171 | hbuss | 176 | } |
177 | |||
1561 | killagreg | 178 | #else |
1171 | hbuss | 179 | //############################################################################ |
180 | //Diese Routine startet und inizialisiert den Timer für RC |
||
1561 | killagreg | 181 | ISR(TIMER1_CAPT_vect) |
1171 | hbuss | 182 | //############################################################################ |
183 | |||
184 | { |
||
185 | static unsigned int AltICR=0; |
||
186 | signed int signal = 0,tmp; |
||
1561 | killagreg | 187 | static int index; |
188 | |||
189 | signal = (unsigned int) ICR1 - AltICR; |
||
1171 | hbuss | 190 | signal /= 2; |
1561 | killagreg | 191 | AltICR = ICR1; |
1171 | hbuss | 192 | //Syncronisationspause? |
1561 | killagreg | 193 | if((signal > 1100*2) && (signal < 8000*2)) |
1171 | hbuss | 194 | { |
195 | if(index >= 4) NewPpmData = 0; // Null bedeutet: Neue Daten |
||
1561 | killagreg | 196 | index = 1; |
197 | } |
||
198 | else |
||
1171 | hbuss | 199 | { |
1377 | hbuss | 200 | if(index < 13) |
1171 | hbuss | 201 | { |
1561 | killagreg | 202 | if((signal > 250) && (signal < 687*2)) |
203 | { |
||
1171 | hbuss | 204 | signal -= 962; |
205 | // Stabiles Signal |
||
206 | if(abs(signal - PPM_in[index]) < 6) { if(SenderOkay < 200) SenderOkay += 10;} |
||
1561 | killagreg | 207 | tmp = (3 * (PPM_in[index]) + signal) / 4; |
1171 | hbuss | 208 | if(tmp > signal+1) tmp--; else |
1561 | killagreg | 209 | if(tmp < signal-1) tmp++; |
210 | if(SenderOkay >= 195) PPM_diff[index] = ((tmp - PPM_in[index]) / 3) * 3; |
||
1171 | hbuss | 211 | else PPM_diff[index] = 0; |
212 | PPM_in[index] = tmp; |
||
1561 | killagreg | 213 | } |
214 | index++; |
||
1 | ingob | 215 | } |
216 | } |
||
217 | } |
||
1356 | hbuss | 218 | #endif |
1 | ingob | 219 |