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