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; |
1933 | holgerb | 20 | unsigned int PPM_Neutral = 466; |
1 | ingob | 21 | |
22 | //############################################################################ |
||
2008 | holgerb | 23 | // Clear the values |
1 | ingob | 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 | //############################################################################ |
2008 | holgerb | 41 | // Interrupt function for the PPM-Input |
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 | { |
||
1933 | holgerb | 66 | signal -= PPM_Neutral; |
1278 | hbuss | 67 | // Stabiles Signal |
2008 | holgerb | 68 | if(EE_Parameter.FailsafeChannel == 0 || PPM_in[EE_Parameter.FailsafeChannel] < 100) // forces Failsafe if the receiver doesn't have 'signal loss' on Failsafe |
69 | { |
||
70 | if(abs(signal - PPM_in[index]) < 6) { if(SenderOkay < 200) SenderOkay += 10; else SenderOkay = 200;} |
||
71 | } |
||
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 | { |
||
1933 | holgerb | 136 | signal -= PPM_Neutral; |
1 | ingob | 137 | // Stabiles Signal |
1271 | hbuss | 138 | if((abs(signal - ppm_in[index]) < 6)) |
139 | { |
||
2008 | holgerb | 140 | if(EE_Parameter.FailsafeChannel == 0 || PPM_in[EE_Parameter.FailsafeChannel] < 100) // forces Failsafe if the receiver doesn't have 'signal loss' on Failsafe |
141 | { |
||
142 | if(okay_cnt > 25) SenderOkay += 10; |
||
143 | else |
||
144 | if(okay_cnt > 10) SenderOkay += 2; |
||
145 | if(SenderOkay > 200) SenderOkay = 200; |
||
146 | } |
||
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 | //############################################################################ |
2008 | holgerb | 183 | // Interrupt function for the PPM-Input |
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 | |
2034 | holgerb | 223 | |
224 |