Rev 842 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
758 | walter | 1 | /*####################################################################################### |
2 | Decodieren eines RC Summen Signals |
||
3 | #######################################################################################*/ |
||
4 | // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
||
5 | // + Copyright (c) 04.2007 Holger Buss |
||
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 |
||
25 | |||
26 | // PWM |
||
27 | //TCCR1A = (1 << COM1B1) | (1 << WGM11) | (1 << WGM10); |
||
28 | //TCCR1B |= (1 << WGM12); |
||
29 | //OCR1B = 55; |
||
30 | |||
31 | TIMSK1 |= _BV(ICIE1); |
||
32 | AdNeutralGier = 0; |
||
33 | AdNeutralRoll = 0; |
||
34 | AdNeutralNick = 0; |
||
35 | return; |
||
36 | } |
||
37 | |||
38 | //############################################################################ |
||
39 | //Diese Routine startet und inizialisiert den Timer für RC |
||
40 | SIGNAL(SIG_INPUT_CAPTURE1) |
||
41 | //############################################################################ |
||
42 | |||
43 | { |
||
44 | static unsigned int AltICR=0; |
||
45 | signed int signal = 0,tmp; |
||
46 | static int index; |
||
47 | |||
48 | signal = (unsigned int) ICR1 - AltICR; |
||
842 | walter | 49 | signal += ((signed int)Parameter_UserParam7 - 125); |
758 | walter | 50 | AltICR = ICR1; |
51 | |||
52 | //Syncronisationspause? |
||
53 | // if((signal > (int) Parameter_UserParam2 * 10) && (signal < 8000)) |
||
54 | if((signal > 1100) && (signal < 8000)) |
||
55 | { |
||
56 | if(index >= 4) NewPpmData = 0; // Null bedeutet: Neue Daten |
||
57 | index = 1; |
||
58 | } |
||
59 | else |
||
60 | { |
||
61 | if(index < 10) |
||
62 | { |
||
63 | if((signal > 250) && (signal < 687)) |
||
64 | { |
||
65 | signal -= 466; |
||
852 | walter | 66 | |
67 | // if (index == EE_Parameter.Kanalbelegung[K_GAS] ) signal = -signal; //invertiere GAS |
||
68 | // if (index == EE_Parameter.Kanalbelegung[K_GIER] ) signal = -signal; //invertiere GIER |
||
69 | // if (index == EE_Parameter.Kanalbelegung[K_NICK] ) signal = -signal; //invertiere NICK |
||
70 | // if (index == EE_Parameter.Kanalbelegung[K_ROLL] ) signal = -signal; //invertiere ROLL |
||
71 | |||
758 | walter | 72 | // Stabiles Signal |
73 | if(abs(signal - PPM_in[index]) < 6) { if(SenderOkay < 200) SenderOkay += 10;} |
||
74 | // tmp = (7 * (PPM_in[index]) + signal) / 8; |
||
75 | tmp = (3 * (PPM_in[index]) + signal) / 4; |
||
76 | if(tmp > signal+1) tmp--; else |
||
77 | if(tmp < signal-1) tmp++; |
||
78 | if(SenderOkay >= 195) PPM_diff[index] = ((tmp - PPM_in[index]) / 3) * 3; |
||
79 | else PPM_diff[index] = 0; |
||
80 | PPM_in[index] = tmp; |
||
81 | } |
||
82 | index++; |
||
83 | if(index == 5) PORTD |= 0x20; else PORTD &= ~0x20; // Servosignal an J3 anlegen |
||
84 | if(index == 6) PORTD |= 0x10; else PORTD &= ~0x10; // Servosignal an J4 anlegen |
||
85 | if(index == 7) PORTD |= 0x08; else PORTD &= ~0x08; // Servosignal an J5 anlegen |
||
86 | } |
||
87 | } |
||
88 | } |
||
89 | |||
90 | |||
91 | |||
92 | |||
93 |