Rev 716 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 716 | Rev 753 | ||
---|---|---|---|
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); //timer1 prescale 64 |
25 | - | ||
26 | // PWM |
- | |
27 | //TCCR1A = (1 << COM1B1) | (1 << WGM11) | (1 << WGM10); |
- | |
28 | //TCCR1B |= (1 << WGM12); |
- | |
29 | //OCR1B = 55; |
- | |
30 | 25 | ||
31 | TIMSK1 |= _BV(ICIE1); |
26 | TIMSK1 |= _BV(ICIE1); |
32 | AdNeutralGier = 0; |
27 | AdNeutralGier = 0; |
33 | AdNeutralRoll = 0; |
28 | AdNeutralRoll = 0; |
34 | AdNeutralNick = 0; |
29 | AdNeutralNick = 0; |
35 | return; |
30 | return; |
36 | } |
31 | } |
37 | 32 | ||
38 | //############################################################################ |
33 | //############################################################################ |
39 | //Diese Routine startet und inizialisiert den Timer für RC |
34 | //Diese Routine startet und inizialisiert den Timer für RC |
40 | SIGNAL(SIG_INPUT_CAPTURE1) |
35 | SIGNAL(SIG_INPUT_CAPTURE1) |
41 | //############################################################################ |
36 | //############################################################################ |
42 | 37 | ||
43 | { |
38 | { |
44 | static unsigned int AltICR=0; |
39 | static unsigned int AltICR=0; |
45 | signed int signal = 0,tmp; |
40 | signed int signal = 0,tmp; |
46 | static int index; |
41 | static int index; |
47 | 42 | ||
48 | signal = (unsigned int) ICR1 - AltICR; |
43 | signal = (unsigned int) ICR1 - AltICR; |
49 | AltICR = ICR1; |
44 | AltICR = ICR1; |
50 | 45 | ||
51 | //Syncronisationspause? |
- | |
52 | // if((signal > (int) Parameter_UserParam2 * 10) && (signal < 8000)) |
46 | //Syncronisationspause? |
53 | if((signal > 1100) && (signal < 8000)) |
47 | if((signal > 1100) && (signal < 8000)) |
54 | { |
48 | { |
55 | if(index >= 4) NewPpmData = 0; // Null bedeutet: Neue Daten |
49 | if(index >= 4) NewPpmData = 0; // Null bedeutet: Neue Daten |
56 | index = 1; |
50 | index = 1; |
57 | } |
51 | } |
58 | else |
52 | else |
59 | { |
53 | { |
60 | if(index < 10) |
54 | if(index < 10) |
61 | { |
55 | { |
62 | if((signal > 250) && (signal < 687)) |
56 | if((signal > 250) && (signal < 687)) |
63 | { |
57 | { |
64 | signal -= 466; |
58 | signal -= 466; |
65 | - | ||
66 | if (index == 1) signal -= 16; |
- | |
67 | if (index == 2) signal -= 12; |
- | |
68 | 59 | ||
69 | // Stabiles Signal |
60 | // Stabiles Signal |
70 | if(abs(signal - PPM_in[index]) < 6) { if(SenderOkay < 200) SenderOkay += 10;} |
61 | if(abs(signal - PPM_in[index]) < 6) { if(SenderOkay < 200) SenderOkay += 10;} |
71 | tmp = (3 * (PPM_in[index]) + signal) / 4; |
62 | tmp = (3 * (PPM_in[index]) + signal) / 4; |
72 | if(tmp > signal+1) tmp--; else |
63 | if(tmp > signal+1) tmp--; else |
73 | if(tmp < signal-1) tmp++; |
64 | if(tmp < signal-1) tmp++; |
74 | if(SenderOkay >= 195) PPM_diff[index] = ((tmp - PPM_in[index]) / 3) * 3; |
65 | if(SenderOkay >= 195) PPM_diff[index] = ((tmp - PPM_in[index]) / 3) * 3; |
75 | else PPM_diff[index] = 0; |
66 | else PPM_diff[index] = 0; |
76 | PPM_in[index] = tmp; |
67 | PPM_in[index] = tmp; |
77 | } |
68 | } |
78 | index++; |
69 | index++; |
79 | if(index == 5) PORTD |= 0x20; else PORTD &= ~0x20; // Servosignal an J3 anlegen |
70 | //if(index == 5) PORTD |= 0x20; else PORTD &= ~0x20; // Servosignal an J3 anlegen |
80 | if(index == 6) PORTD |= 0x10; else PORTD &= ~0x10; // Servosignal an J4 anlegen |
71 | //if(index == 6) PORTD |= 0x10; else PORTD &= ~0x10; // Servosignal an J4 anlegen |
81 | if(index == 7) PORTD |= 0x08; else PORTD &= ~0x08; // Servosignal an J5 anlegen |
72 | //if(index == 7) PORTD |= 0x08; else PORTD &= ~0x08; // Servosignal an J5 anlegen |
82 | } |
73 | } |
83 | } |
74 | } |
84 | } |
75 | } |
85 | 76 | ||
86 | 77 | ||
87 | 78 | ||
88 | 79 | ||
89 | 80 | ||
90 | 81 |