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