Rev 1272 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
1 | ingob | 1 | /*####################################################################################### |
2 | Decodieren eines RC Summen Signals |
||
3 | #######################################################################################*/ |
||
4 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
||
5 | // + Copyright (c) 04.2007 Holger Buss |
||
6 | // + only for non-profit use |
||
7 | // + www.MikroKopter.com |
||
8 | // + see the File "License.txt" for further Informations |
||
9 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
||
10 | |||
11 | #include "rc.h" |
||
12 | #include "main.h" |
||
13 | |||
14 | volatile int PPM_in[11]; |
||
15 | volatile int PPM_diff[11]; // das diffenzierte Stick-Signal |
||
1268 | hbuss | 16 | volatile char Channels,tmpChannels = 0; |
1 | ingob | 17 | volatile unsigned char NewPpmData = 1; |
18 | |||
19 | //############################################################################ |
||
20 | //zum decodieren des PPM-Signals wird Timer1 mit seiner Input |
||
21 | //Capture Funktion benutzt: |
||
22 | void rc_sum_init (void) |
||
23 | //############################################################################ |
||
24 | { |
||
25 | TCCR1B=(1<<CS11)|(1<<CS10)|(1<<ICES1)|(1<<ICNC1);//|(1 << WGM12); //timer1 prescale 64 |
||
1171 | hbuss | 26 | // TCCR1B=(1<<CS11)|(0<<CS10)|(1<<ICES1)|(1<<ICNC1); //timer1 prescale 64 |
1 | ingob | 27 | TIMSK1 |= _BV(ICIE1); |
28 | AdNeutralGier = 0; |
||
29 | AdNeutralRoll = 0; |
||
30 | AdNeutralNick = 0; |
||
31 | return; |
||
32 | } |
||
33 | |||
34 | //############################################################################ |
||
35 | //Diese Routine startet und inizialisiert den Timer für RC |
||
36 | SIGNAL(SIG_INPUT_CAPTURE1) |
||
37 | //############################################################################ |
||
38 | |||
39 | { |
||
40 | static unsigned int AltICR=0; |
||
1268 | hbuss | 41 | static int ppm_in[11]; |
42 | static int ppm_diff[11]; |
||
43 | static int old_ppm_in[11]; |
||
44 | static int old_ppm_diff[11]; |
||
173 | holgerb | 45 | signed int signal = 0,tmp; |
1268 | hbuss | 46 | static unsigned char index, okay_cnt = 0; |
1 | ingob | 47 | signal = (unsigned int) ICR1 - AltICR; |
48 | AltICR = ICR1; |
||
49 | //Syncronisationspause? |
||
513 | hbuss | 50 | if((signal > 1100) && (signal < 8000)) |
1 | ingob | 51 | { |
1268 | hbuss | 52 | tmpChannels = index; |
53 | if(tmpChannels >= 4 && Channels == tmpChannels) |
||
54 | { |
||
1276 | hbuss | 55 | if(okay_cnt > 10) |
1268 | hbuss | 56 | { |
57 | NewPpmData = 0; // Null bedeutet: Neue Daten |
||
58 | for(index = 0; index < 11; index++) |
||
59 | { |
||
60 | if(okay_cnt > 30) |
||
61 | { |
||
62 | old_ppm_in[index] = PPM_in[index]; |
||
63 | old_ppm_diff[index] = PPM_diff[index]; |
||
64 | } |
||
65 | PPM_in[index] = ppm_in[index]; |
||
66 | PPM_diff[index] = ppm_diff[index]; |
||
67 | } |
||
68 | } |
||
69 | if(okay_cnt < 255) okay_cnt++; |
||
70 | } |
||
1276 | hbuss | 71 | else |
72 | if(okay_cnt > 100) okay_cnt = 10; else okay_cnt = 0; |
||
1 | ingob | 73 | index = 1; |
1268 | hbuss | 74 | if(!MotorenEin) Channels = tmpChannels; |
1 | ingob | 75 | } |
76 | else |
||
77 | { |
||
78 | if(index < 10) |
||
79 | { |
||
80 | if((signal > 250) && (signal < 687)) |
||
81 | { |
||
82 | signal -= 466; |
||
83 | // Stabiles Signal |
||
1271 | hbuss | 84 | if((abs(signal - ppm_in[index]) < 6)) |
85 | { |
||
1276 | hbuss | 86 | if(okay_cnt > 25) SenderOkay += 10; |
1271 | hbuss | 87 | else |
1276 | hbuss | 88 | if(okay_cnt > 10) SenderOkay += 2; |
89 | if(SenderOkay > 200) SenderOkay = 200; |
||
1271 | hbuss | 90 | } |
1268 | hbuss | 91 | tmp = (3 * (ppm_in[index]) + signal) / 4; |
604 | hbuss | 92 | if(tmp > signal+1) tmp--; else |
93 | if(tmp < signal-1) tmp++; |
||
1268 | hbuss | 94 | if(SenderOkay >= 190) ppm_diff[index] = ((tmp - ppm_in[index]) / 3) * 3; |
95 | else ppm_diff[index] = 0; |
||
96 | ppm_in[index] = tmp; |
||
1 | ingob | 97 | } |
1268 | hbuss | 98 | else ROT_ON; |
99 | if(index == 5) J3High; else J3Low; // Servosignal an J3 anlegen |
||
100 | if(index == 6) J4High; else J4Low; // Servosignal an J4 anlegen |
||
101 | if(index == 7) J5High; else J5Low; // Servosignal an J5 anlegen |
||
102 | } |
||
103 | else ROT_ON; |
||
104 | if(index < 20) index++; |
||
1276 | hbuss | 105 | else |
106 | if(index == 20) |
||
1268 | hbuss | 107 | { |
1276 | hbuss | 108 | unsigned char i; |
109 | index = 30; |
||
1268 | hbuss | 110 | for(i=0;i<11;i++) // restore from older data |
111 | { |
||
1276 | hbuss | 112 | PPM_in[i] = old_ppm_in[i]; |
113 | PPM_diff[i] = 0; |
||
114 | // okay_cnt /= 2; |
||
1268 | hbuss | 115 | } |
116 | } |
||
117 | } |
||
1276 | hbuss | 118 | DebugOut.Analog[16] = okay_cnt; |
119 | DebugOut.Analog[17] = PPM_in[2]; |
||
1171 | hbuss | 120 | } |
121 | |||
122 | /* |
||
123 | //############################################################################ |
||
124 | //Diese Routine startet und inizialisiert den Timer für RC |
||
125 | SIGNAL(SIG_INPUT_CAPTURE1) |
||
126 | //############################################################################ |
||
127 | |||
128 | { |
||
129 | static unsigned int AltICR=0; |
||
130 | signed int signal = 0,tmp; |
||
131 | static int index; |
||
132 | |||
133 | signal = (unsigned int) ICR1 - AltICR; |
||
134 | DebugOut.Analog[16] = signal; |
||
135 | signal /= 2; |
||
136 | AltICR = ICR1; |
||
137 | //Syncronisationspause? |
||
138 | if((signal > 1100*2) && (signal < 8000*2)) |
||
139 | { |
||
140 | if(index >= 4) NewPpmData = 0; // Null bedeutet: Neue Daten |
||
141 | index = 1; |
||
142 | } |
||
143 | else |
||
144 | { |
||
145 | if(index < 10) |
||
146 | { |
||
147 | if((signal > 250) && (signal < 687*2)) |
||
148 | { |
||
149 | signal -= 962; |
||
150 | // Stabiles Signal |
||
151 | if(abs(signal - PPM_in[index]) < 6) { if(SenderOkay < 200) SenderOkay += 10;} |
||
152 | tmp = (3 * (PPM_in[index]) + signal) / 4; |
||
153 | if(tmp > signal+1) tmp--; else |
||
154 | if(tmp < signal-1) tmp++; |
||
155 | if(SenderOkay >= 195) PPM_diff[index] = ((tmp - PPM_in[index]) / 3) * 3; |
||
156 | else PPM_diff[index] = 0; |
||
157 | PPM_in[index] = tmp; |
||
158 | } |
||
159 | index++; |
||
1155 | hbuss | 160 | if(index == 5) J3High; else J3Low; // Servosignal an J3 anlegen |
1171 | hbuss | 161 | if(index == 2) J4High; else J4Low; // Servosignal an J4 anlegen |
1155 | hbuss | 162 | if(index == 7) J5High; else J5Low; // Servosignal an J5 anlegen |
1 | ingob | 163 | } |
164 | } |
||
165 | } |
||
1171 | hbuss | 166 | */ |
1 | ingob | 167 | |
168 | |||
169 |