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