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