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