Rev 1209 | Rev 1226 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 1209 | Rev 1224 | ||
---|---|---|---|
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 unsigned char NewPpmData = 1; |
16 | volatile unsigned char NewPpmData = 1; |
17 | 17 | ||
18 | //############################################################################ |
18 | //############################################################################ |
19 | //zum decodieren des PPM-Signals wird Timer1 mit seiner Input |
19 | //zum decodieren des PPM-Signals wird Timer1 mit seiner Input |
20 | //Capture Funktion benutzt: |
20 | //Capture Funktion benutzt: |
21 | void rc_sum_init (void) |
21 | void rc_sum_init (void) |
22 | //############################################################################ |
22 | //############################################################################ |
23 | { |
23 | { |
24 | TCCR1B=(1<<CS11)|(1<<CS10)|(1<<ICES1)|(1<<ICNC1);//|(1 << WGM12); //timer1 prescale 64 |
24 | TCCR1B=(1<<CS11)|(1<<CS10)|(1<<ICES1)|(1<<ICNC1);//|(1 << WGM12); //timer1 prescale 64 |
25 | // TCCR1B=(1<<CS11)|(0<<CS10)|(1<<ICES1)|(1<<ICNC1); //timer1 prescale 64 |
25 | // TCCR1B=(1<<CS11)|(0<<CS10)|(1<<ICES1)|(1<<ICNC1); //timer1 prescale 64 |
26 | TIMSK1 |= _BV(ICIE1); |
26 | TIMSK1 |= _BV(ICIE1); |
27 | AdNeutralGier = 0; |
27 | AdNeutralGier = 0; |
28 | AdNeutralRoll = 0; |
28 | AdNeutralRoll = 0; |
29 | AdNeutralNick = 0; |
29 | AdNeutralNick = 0; |
30 | return; |
30 | return; |
31 | } |
31 | } |
32 | 32 | ||
33 | //############################################################################ |
33 | //############################################################################ |
34 | //Diese Routine startet und inizialisiert den Timer für RC |
34 | //Diese Routine startet und inizialisiert den Timer für RC |
35 | SIGNAL(SIG_INPUT_CAPTURE1) |
35 | SIGNAL(SIG_INPUT_CAPTURE1) |
36 | //############################################################################ |
36 | //############################################################################ |
37 | 37 | ||
38 | { |
38 | { |
39 | static unsigned int AltICR=0; |
39 | static unsigned int AltICR=0; |
40 | signed int signal = 0,tmp; |
40 | signed int signal = 0,tmp; |
41 | static int index; |
41 | static int index; |
42 | 42 | ||
43 | signal = (unsigned int) ICR1 - AltICR; |
43 | signal = (unsigned int) ICR1 - AltICR; |
44 | AltICR = ICR1; |
44 | AltICR = ICR1; |
45 | //Syncronisationspause? |
45 | //Syncronisationspause? |
46 | if((signal > 1100) && (signal < 8000)) |
46 | if((signal > 1100) && (signal < 8000)) |
47 | { |
47 | { |
48 | if(index >= 4) NewPpmData = 0; // Null bedeutet: Neue Daten |
48 | if(index >= 4) NewPpmData = 0; // Null bedeutet: Neue Daten |
49 | index = 1; |
49 | index = 1; |
50 | } |
50 | } |
51 | else |
51 | else |
52 | { |
52 | { |
53 | if(index < 10) |
53 | if(index < 10) |
54 | { |
54 | { |
55 | if((signal > 250) && (signal < 687)) |
55 | if((signal > 250) && (signal < 687)) |
56 | { |
56 | { |
57 | signal -= 466; |
57 | signal -= 466; |
58 | // Stabiles Signal |
58 | // Stabiles Signal |
59 | if(abs(signal - PPM_in[index]) < 6) { if(SenderOkay < 200) SenderOkay += 10; else SenderOkay = 200;} |
59 | if(abs(signal - PPM_in[index]) < 6) { if(SenderOkay < 200) SenderOkay += 10; else SenderOkay = 200;} |
60 | tmp = (3 * (PPM_in[index]) + signal) / 4; |
60 | tmp = (3 * (PPM_in[index]) + signal) / 4; |
61 | if(tmp > signal+1) tmp--; else |
61 | if(tmp > signal+1) tmp--; else |
62 | if(tmp < signal-1) tmp++; |
62 | if(tmp < signal-1) tmp++; |
63 | if(SenderOkay >= 195) PPM_diff[index] = ((tmp - PPM_in[index]) / 3) * 3; |
63 | if(SenderOkay >= 195) PPM_diff[index] = ((tmp - PPM_in[index]) / 3) * 3; |
64 | else PPM_diff[index] = 0; |
64 | else PPM_diff[index] = 0; |
65 | PPM_in[index] = tmp; |
65 | PPM_in[index] = tmp; |
66 | } |
66 | } |
67 | index++; |
67 | index++; |
68 | // if(index == 5) J3High; else J3Low; // Servosignal an J3 anlegen |
68 | if(index == 5) J3High; else J3Low; // Servosignal an J3 anlegen |
69 | // if(index == 6) J4High; else J4Low; // Servosignal an J4 anlegen |
69 | if(index == 6) J4High; else J4Low; // Servosignal an J4 anlegen |
70 | // if(index == 7) J5High; else J5Low; // Servosignal an J5 anlegen |
70 | if(index == 7) J5High; else J5Low; // Servosignal an J5 anlegen |
71 | } |
71 | } |
72 | } |
72 | } |
73 | } |
73 | } |
74 | 74 | ||
75 | /* |
75 | /* |
76 | //############################################################################ |
76 | //############################################################################ |
77 | //Diese Routine startet und inizialisiert den Timer für RC |
77 | //Diese Routine startet und inizialisiert den Timer für RC |
78 | SIGNAL(SIG_INPUT_CAPTURE1) |
78 | SIGNAL(SIG_INPUT_CAPTURE1) |
79 | //############################################################################ |
79 | //############################################################################ |
80 | 80 | ||
81 | { |
81 | { |
82 | static unsigned int AltICR=0; |
82 | static unsigned int AltICR=0; |
83 | signed int signal = 0,tmp; |
83 | signed int signal = 0,tmp; |
84 | static int index; |
84 | static int index; |
85 | |
85 | |
86 | signal = (unsigned int) ICR1 - AltICR; |
86 | signal = (unsigned int) ICR1 - AltICR; |
87 | DebugOut.Analog[16] = signal; |
87 | DebugOut.Analog[16] = signal; |
88 | signal /= 2; |
88 | signal /= 2; |
89 | AltICR = ICR1; |
89 | AltICR = ICR1; |
90 | //Syncronisationspause? |
90 | //Syncronisationspause? |
91 | if((signal > 1100*2) && (signal < 8000*2)) |
91 | if((signal > 1100*2) && (signal < 8000*2)) |
92 | { |
92 | { |
93 | if(index >= 4) NewPpmData = 0; // Null bedeutet: Neue Daten |
93 | if(index >= 4) NewPpmData = 0; // Null bedeutet: Neue Daten |
94 | index = 1; |
94 | index = 1; |
95 | } |
95 | } |
96 | else |
96 | else |
97 | { |
97 | { |
98 | if(index < 10) |
98 | if(index < 10) |
99 | { |
99 | { |
100 | if((signal > 250) && (signal < 687*2)) |
100 | if((signal > 250) && (signal < 687*2)) |
101 | { |
101 | { |
102 | signal -= 962; |
102 | signal -= 962; |
103 | // Stabiles Signal |
103 | // Stabiles Signal |
104 | if(abs(signal - PPM_in[index]) < 6) { if(SenderOkay < 200) SenderOkay += 10;} |
104 | if(abs(signal - PPM_in[index]) < 6) { if(SenderOkay < 200) SenderOkay += 10;} |
105 | tmp = (3 * (PPM_in[index]) + signal) / 4; |
105 | tmp = (3 * (PPM_in[index]) + signal) / 4; |
106 | if(tmp > signal+1) tmp--; else |
106 | if(tmp > signal+1) tmp--; else |
107 | if(tmp < signal-1) tmp++; |
107 | if(tmp < signal-1) tmp++; |
108 | if(SenderOkay >= 195) PPM_diff[index] = ((tmp - PPM_in[index]) / 3) * 3; |
108 | if(SenderOkay >= 195) PPM_diff[index] = ((tmp - PPM_in[index]) / 3) * 3; |
109 | else PPM_diff[index] = 0; |
109 | else PPM_diff[index] = 0; |
110 | PPM_in[index] = tmp; |
110 | PPM_in[index] = tmp; |
111 | } |
111 | } |
112 | index++; |
112 | index++; |
113 | if(index == 5) J3High; else J3Low; // Servosignal an J3 anlegen |
113 | if(index == 5) J3High; else J3Low; // Servosignal an J3 anlegen |
114 | if(index == 2) J4High; else J4Low; // Servosignal an J4 anlegen |
114 | if(index == 2) J4High; else J4Low; // Servosignal an J4 anlegen |
115 | if(index == 7) J5High; else J5Low; // Servosignal an J5 anlegen |
115 | if(index == 7) J5High; else J5Low; // Servosignal an J5 anlegen |
116 | } |
116 | } |
117 | } |
117 | } |
118 | } |
118 | } |
119 | */ |
119 | */ |
120 | 120 | ||
121 | 121 | ||
122 | 122 | ||
123 | 123 |