Rev 966 | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 966 | Rev 972 | ||
---|---|---|---|
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 | int PPM_in[11] = {0,0,0,0,0,0,0,0,0,0,0}; |
14 | int PPM_in[11] = {0,0,0,0,0,0,0,0,0,0,0}; |
15 | int RCQuality = 0; |
15 | int RCQuality = 0; |
16 | unsigned char NewPpmData = 1; |
16 | 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); //timer1 prescale 64 |
24 | TCCR1B=(1<<CS11)|(1<<CS10)|(1<<ICES1)|(1<<ICNC1); //timer1 prescale 64 |
25 | TIMSK1 |= _BV(ICIE1); |
25 | TIMSK1 |= _BV(ICIE1); |
26 | return; |
26 | return; |
27 | } |
27 | } |
28 | 28 | ||
29 | //############################################################################ |
29 | //############################################################################ |
30 | //Diese Routine startet und inizialisiert den Timer für RC |
30 | //Diese Routine startet und inizialisiert den Timer für RC |
31 | SIGNAL(SIG_INPUT_CAPTURE1) |
31 | SIGNAL(SIG_INPUT_CAPTURE1) |
32 | //############################################################################ |
32 | //############################################################################ |
33 | { |
33 | { |
34 | static unsigned int AltICR=0; |
34 | static unsigned int AltICR=0; |
35 | signed int signal = 0,tmp; |
35 | signed int signal = 0,tmp; |
36 | static int index; |
36 | static int index; |
37 | static float RC_Quality = 0.0F; |
37 | static float RC_Quality = 0.0F; |
38 | static int PPM_org[11]; |
38 | static int PPM_org[11]; |
39 | 39 | ||
40 | signal = (unsigned int) ICR1 - AltICR; |
40 | signal = (unsigned int) ICR1 - AltICR; |
41 | AltICR = ICR1; |
41 | AltICR = ICR1; |
42 | 42 | ||
43 | //Syncronisationspause? |
43 | //Syncronisationspause? |
44 | if ((signal > 1500) && (signal < 8000)) |
44 | if ((signal > 1500) && (signal < 8000)) |
45 | { |
45 | { |
46 | index = 1; |
46 | index = 1; |
47 | NewPpmData = 0; // Null bedeutet: Neue Daten |
47 | NewPpmData = 0; // Null bedeutet: Neue Daten |
48 | } |
48 | } |
49 | else |
49 | else |
50 | { |
50 | { |
51 | if(index < 10) |
51 | if(index < 10) |
52 | { |
52 | { |
53 | if((signal > 250) && (signal < 687)) |
53 | if((signal > 250) && (signal < 687)) |
54 | { |
54 | { |
55 | signal -= 466; |
55 | signal -= 466; |
56 | // Stabiles Signal |
56 | // Stabiles Signal |
57 | if(abs(signal - PPM_in[index]) < 6) |
57 | if(abs(signal - PPM_in[index]) < 6) |
58 | { |
58 | { |
59 | if(SenderOkay < 200) |
59 | if(SenderOkay < 200) |
60 | { |
60 | { |
61 | SenderOkay += 10; |
61 | SenderOkay += 10; |
62 | } |
62 | } |
63 | } |
63 | } |
64 | /* Give an estimate for the Signal Level based on the RC-Jitter see |
64 | /* Give an estimate for the Signal Level based on the RC-Jitter see |
65 | http://forum.mikrokopter.de/topic-post44807.html#post44807*/ |
65 | http://forum.mikrokopter.de/topic-post44807.html#post44807*/ |
66 | if (abs(2 * (signal - PPM_org[index]) > (int) RC_Quality)) |
66 | if (abs(2 * (signal - PPM_org[index]) > (int) RC_Quality)) |
67 | { |
67 | { |
68 | RC_Quality = 0.99F * RC_Quality + 0.01F * (float) abs(2 * (signal - PPM_org[index])) ; |
68 | RC_Quality = 0.99F * RC_Quality + 0.01F * (float) abs(2 * (signal - PPM_org[index])) ; |
69 | } |
69 | } |
70 | else |
70 | else |
71 | { |
71 | { |
72 | RC_Quality = 0.998F * RC_Quality + 0.002F * (float) abs(2 * (signal - PPM_org[index])); |
72 | RC_Quality = 0.998F * RC_Quality + 0.002F * (float) abs(2 * (signal - PPM_org[index])); |
73 | } |
73 | } |
74 | tmp = (3 * (PPM_in[index]) + signal) / 4; |
74 | tmp = (3 * (PPM_in[index]) + signal) / 4; |
75 | PPM_in[index] = tmp; |
75 | PPM_in[index] = tmp; |
76 | PPM_org[index] = signal; |
76 | PPM_org[index] = signal; |
77 | } |
77 | } |
78 | else |
78 | else |
79 | { |
79 | { |
80 | RC_Quality = 0.95F * RC_Quality + 0.05F * 100; |
80 | RC_Quality = 0.95F * RC_Quality + 0.05F * 100; |
81 | } |
81 | } |
82 | RC_Quality = MIN(100.F, RC_Quality); |
82 | RC_Quality = MIN(100.F, RC_Quality); |
83 | RCQuality = 100 - (int) RC_Quality; |
83 | RCQuality = 100 - (int) RC_Quality; |
84 | DebugOut.Analog[12] = RCQuality; |
84 | DebugOut.Analog[12] = RCQuality; |
85 | index++; |
85 | index++; |
- | 86 | /* |
|
86 | if(index == 5) PORTD |= 0x20; else PORTD &= ~0x20; // Servosignal an J3 anlegen |
87 | if(index == 5) PORTD |= 0x20; else PORTD &= ~0x20; // Servosignal an J3 anlegen |
87 | if(index == 6) PORTD |= 0x10; else PORTD &= ~0x10; // Servosignal an J4 anlegen |
88 | if(index == 6) PORTD |= 0x10; else PORTD &= ~0x10; // Servosignal an J4 anlegen |
88 | if(index == 7) PORTD |= 0x08; else PORTD &= ~0x08; // Servosignal an J5 anlegen |
89 | if(index == 7) PORTD |= 0x08; else PORTD &= ~0x08; // Servosignal an J5 anlegen |
- | 90 | */ |
|
89 | } |
91 | } |
90 | } |
92 | } |
91 | } |
93 | } |
92 | 94 | ||
93 | 95 | ||
94 | 96 | ||
95 | 97 | ||
96 | 98 | ||
97 | 99 |