Rev 1880 | 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 | } |
||
1897 | - | 33 | |
34 | PPM_in[13] = PPM_in[13] -127; /// MartinW: Initialisierungswerte für die seriellen Potis für Jeti+ |
||
35 | PPM_in[14] = PPM_in[14] -127; |
||
36 | PPM_in[15] = PPM_in[15] -127; /// MartinW: Initialisierungswerte für die seriellen Potis für Jeti+ |
||
37 | PPM_in[16] = PPM_in[16] -127; |
||
1438 | ingob | 38 | |
1 | ingob | 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 |
||
1561 | killagreg | 48 | ISR(TIMER1_CAPT_vect) |
1278 | hbuss | 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; |
||
1561 | killagreg | 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) |
1561 | killagreg | 60 | if((signal > 1100) && (signal < 8000)) |
1278 | hbuss | 61 | { |
1320 | hbuss | 62 | Channels = index; |
1278 | hbuss | 63 | if(index >= 4) NewPpmData = 0; // Null bedeutet: Neue Daten |
1561 | killagreg | 64 | index = 1; |
65 | } |
||
66 | else |
||
1278 | hbuss | 67 | { |
1377 | hbuss | 68 | if(index < 13) |
1278 | hbuss | 69 | { |
1561 | killagreg | 70 | if((signal > 250) && (signal < 687)) |
71 | { |
||
1278 | hbuss | 72 | signal -= 466; |
73 | // Stabiles Signal |
||
74 | if(abs(signal - PPM_in[index]) < 6) { if(SenderOkay < 200) SenderOkay += 10; else SenderOkay = 200;} |
||
1561 | killagreg | 75 | tmp = (3 * (PPM_in[index]) + signal) / 4; |
1278 | hbuss | 76 | if(tmp > signal+1) tmp--; else |
1561 | killagreg | 77 | if(tmp < signal-1) tmp++; |
78 | if(SenderOkay >= 195) PPM_diff[index] = ((tmp - PPM_in[index]) / 3) * 3; |
||
1278 | hbuss | 79 | else PPM_diff[index] = 0; |
80 | PPM_in[index] = tmp; |
||
1561 | killagreg | 81 | } |
82 | index++; |
||
1639 | holgerb | 83 | if(PlatinenVersion < 20) |
84 | { |
||
85 | if(index == 5) J3High; else J3Low; // Servosignal an J3 anlegen |
||
86 | if(index == 6) J4High; else J4Low; // Servosignal an J4 anlegen |
||
87 | if(index == 7) J5High; else J5Low; // Servosignal an J5 anlegen |
||
88 | } |
||
1278 | hbuss | 89 | } |
90 | } |
||
1309 | hbuss | 91 | } |
1561 | killagreg | 92 | else |
1309 | hbuss | 93 | { |
1 | ingob | 94 | static unsigned int AltICR=0; |
1377 | hbuss | 95 | static int ppm_in[13]; |
1561 | killagreg | 96 | static int ppm_diff[13]; |
1377 | hbuss | 97 | static int old_ppm_in[13]; |
1561 | killagreg | 98 | static int old_ppm_diff[13]; |
173 | holgerb | 99 | signed int signal = 0,tmp; |
1561 | killagreg | 100 | static unsigned char index, okay_cnt = 0; |
101 | signal = (unsigned int) ICR1 - AltICR; |
||
102 | AltICR = ICR1; |
||
1283 | hbuss | 103 | //Syncronisationspause? (3.52 ms < signal < 25.6 ms) |
1561 | killagreg | 104 | if((signal > 1100) && (signal < 8000)) |
1 | ingob | 105 | { |
1268 | hbuss | 106 | tmpChannels = index; |
1561 | killagreg | 107 | if(tmpChannels >= 4 && Channels == tmpChannels) |
1268 | hbuss | 108 | { |
1276 | hbuss | 109 | if(okay_cnt > 10) |
1268 | hbuss | 110 | { |
111 | NewPpmData = 0; // Null bedeutet: Neue Daten |
||
1377 | hbuss | 112 | for(index = 0; index < 13; index++) |
1268 | hbuss | 113 | { |
1561 | killagreg | 114 | if(okay_cnt > 30) |
1268 | hbuss | 115 | { |
116 | old_ppm_in[index] = PPM_in[index]; |
||
117 | old_ppm_diff[index] = PPM_diff[index]; |
||
1561 | killagreg | 118 | } |
1268 | hbuss | 119 | PPM_in[index] = ppm_in[index]; |
120 | PPM_diff[index] = ppm_diff[index]; |
||
121 | } |
||
122 | } |
||
123 | if(okay_cnt < 255) okay_cnt++; |
||
124 | } |
||
1561 | killagreg | 125 | else |
1278 | hbuss | 126 | { |
127 | if(okay_cnt > 100) okay_cnt = 10; else okay_cnt = 0; |
||
128 | ROT_ON; |
||
129 | } |
||
1561 | killagreg | 130 | index = 1; |
1268 | hbuss | 131 | if(!MotorenEin) Channels = tmpChannels; |
1561 | killagreg | 132 | } |
133 | else |
||
1 | ingob | 134 | { |
1377 | hbuss | 135 | if(index < 13) |
1 | ingob | 136 | { |
1561 | killagreg | 137 | if((signal > 250) && (signal < 687)) |
138 | { |
||
1 | ingob | 139 | signal -= 466; |
140 | // Stabiles Signal |
||
1271 | hbuss | 141 | if((abs(signal - ppm_in[index]) < 6)) |
142 | { |
||
1276 | hbuss | 143 | if(okay_cnt > 25) SenderOkay += 10; |
1561 | killagreg | 144 | else |
145 | if(okay_cnt > 10) SenderOkay += 2; |
||
1276 | hbuss | 146 | if(SenderOkay > 200) SenderOkay = 200; |
1271 | hbuss | 147 | } |
1561 | killagreg | 148 | tmp = (3 * (ppm_in[index]) + signal) / 4; |
604 | hbuss | 149 | if(tmp > signal+1) tmp--; else |
1561 | killagreg | 150 | if(tmp < signal-1) tmp++; |
151 | if(SenderOkay >= 190) ppm_diff[index] = ((tmp - ppm_in[index]) / 3) * 3; |
||
1268 | hbuss | 152 | else ppm_diff[index] = 0; |
153 | ppm_in[index] = tmp; |
||
1561 | killagreg | 154 | } |
1268 | hbuss | 155 | else ROT_ON; |
1639 | holgerb | 156 | if(PlatinenVersion < 20) |
157 | { |
||
158 | if(index == 5) J3High; else J3Low; // Servosignal an J3 anlegen |
||
159 | if(index == 6) J4High; else J4Low; // Servosignal an J4 anlegen |
||
160 | if(index == 7) J5High; else J5Low; // Servosignal an J5 anlegen |
||
161 | } |
||
1268 | hbuss | 162 | } |
1561 | killagreg | 163 | if(index < 20) index++; |
1276 | hbuss | 164 | else |
1561 | killagreg | 165 | if(index == 20) |
1268 | hbuss | 166 | { |
1276 | hbuss | 167 | unsigned char i; |
1278 | hbuss | 168 | ROT_ON; |
1276 | hbuss | 169 | index = 30; |
1377 | hbuss | 170 | for(i=0;i<13;i++) // restore from older data |
1268 | hbuss | 171 | { |
1276 | hbuss | 172 | PPM_in[i] = old_ppm_in[i]; |
173 | PPM_diff[i] = 0; |
||
174 | // okay_cnt /= 2; |
||
1268 | hbuss | 175 | } |
176 | } |
||
177 | } |
||
1309 | hbuss | 178 | } |
1171 | hbuss | 179 | } |
180 | |||
1561 | killagreg | 181 | #else |
1171 | hbuss | 182 | //############################################################################ |
183 | //Diese Routine startet und inizialisiert den Timer für RC |
||
1561 | killagreg | 184 | ISR(TIMER1_CAPT_vect) |
1171 | hbuss | 185 | //############################################################################ |
186 | |||
187 | { |
||
188 | static unsigned int AltICR=0; |
||
189 | signed int signal = 0,tmp; |
||
1561 | killagreg | 190 | static int index; |
191 | |||
192 | signal = (unsigned int) ICR1 - AltICR; |
||
1171 | hbuss | 193 | signal /= 2; |
1561 | killagreg | 194 | AltICR = ICR1; |
1171 | hbuss | 195 | //Syncronisationspause? |
1561 | killagreg | 196 | if((signal > 1100*2) && (signal < 8000*2)) |
1171 | hbuss | 197 | { |
198 | if(index >= 4) NewPpmData = 0; // Null bedeutet: Neue Daten |
||
1561 | killagreg | 199 | index = 1; |
200 | } |
||
201 | else |
||
1171 | hbuss | 202 | { |
1377 | hbuss | 203 | if(index < 13) |
1171 | hbuss | 204 | { |
1561 | killagreg | 205 | if((signal > 250) && (signal < 687*2)) |
206 | { |
||
1171 | hbuss | 207 | signal -= 962; |
208 | // Stabiles Signal |
||
209 | if(abs(signal - PPM_in[index]) < 6) { if(SenderOkay < 200) SenderOkay += 10;} |
||
1561 | killagreg | 210 | tmp = (3 * (PPM_in[index]) + signal) / 4; |
1171 | hbuss | 211 | if(tmp > signal+1) tmp--; else |
1561 | killagreg | 212 | if(tmp < signal-1) tmp++; |
213 | if(SenderOkay >= 195) PPM_diff[index] = ((tmp - PPM_in[index]) / 3) * 3; |
||
1171 | hbuss | 214 | else PPM_diff[index] = 0; |
215 | PPM_in[index] = tmp; |
||
1561 | killagreg | 216 | } |
217 | index++; |
||
1 | ingob | 218 | } |
219 | } |
||
220 | } |
||
1356 | hbuss | 221 | #endif |
1 | ingob | 222 |