Go to most recent revision | Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
2248 | - | 1 | /************************************************************************************************************************************** |
2 | * File: rc.c |
||
3 | * |
||
4 | * Purpose: Decoding of the radio control sum signal |
||
5 | * |
||
6 | * Functions: void rc_sum_init(void) |
||
7 | * ISR(TIMER1_CAPT_vect) |
||
8 | * |
||
9 | *************************************************************************************************************************************/ |
||
10 | #include "rc.h" |
||
11 | #include "main.h" |
||
12 | |||
13 | |||
14 | volatile int PPM_in[11]; // containing the stick signal of the according radio control chanel |
||
15 | volatile int PPM_diff[11]; // the differential stick signal of the appropriate radio control chanel |
||
16 | volatile char Channels; // containing the number of channels |
||
17 | volatile char tmpChannels = 0; // |
||
18 | volatile unsigned char NewPpmData = 1; // |
||
19 | |||
20 | |||
21 | //---------------------------------------------------------------------------------------------------------------------------------- |
||
22 | // The input capture function of Timer1 is used to decode the PPM sum signal |
||
23 | //---------------------------------------------------------------------------------------------------------------------------------- |
||
24 | void rc_sum_init(void) |
||
25 | { |
||
26 | //------------------------------------------------------------------------------------------------ |
||
27 | // TCCR1B = Timer/Counter1 Control Register B -> ICNC1 ICES1 – WGM13 WGM12 CS12 CS11 CS10 |
||
28 | // |
||
29 | // ICES1: Input Capture Edge Select = activated |
||
30 | // ICNC1: Input Capture Noise Canceler = activated |
||
31 | // CSn2:0 Clock Select = 1:64 from prescaler |
||
32 | // |
||
33 | TCCR1B= (1<<ICES1)|(1<<ICNC1)|(1<<CS11)|(1<<CS10); |
||
34 | |||
35 | //------------------------------------------------------------------------------------------------ |
||
36 | // TIMSK1 = Timer/Counter1 Interrupt Mask Register -> – – ICIE1 – – OCIE1B OCIE1A TOIE1 |
||
37 | // ICIE1: Timer/Counter1, Input Capture Interrupt Enable |
||
38 | // |
||
39 | TIMSK1 |= (1<<ICIE1); |
||
40 | |||
41 | AdNeutralGier = 0; |
||
42 | AdNeutralRoll = 0; |
||
43 | AdNeutralNick = 0; |
||
44 | |||
45 | return; |
||
46 | } |
||
47 | //---------------------------------------------------------------------------------------------------------------------------------- |
||
48 | |||
49 | |||
50 | |||
51 | //---------------------------------------------------------------------------------------------------------------------------------- |
||
52 | // This function works with Timer1 to decode the radio control |
||
53 | //---------------------------------------------------------------------------------------------------------------------------------- |
||
54 | ISR(TIMER1_CAPT_vect) |
||
55 | { |
||
56 | static unsigned int AltICR=0; |
||
57 | signed int signal = 0; |
||
58 | signed int tmp; |
||
59 | static int index; |
||
60 | |||
61 | signal = (unsigned int) ICR1 - AltICR; // ICR1H and ICR1L – Input Capture Register 1 |
||
62 | AltICR = ICR1; |
||
63 | |||
64 | if((signal > 1100) && (signal < 8000)) // Syncronisation break? (3.52 ms < signal < 25.6 ms) |
||
65 | { |
||
66 | Channels = index; |
||
67 | if(index >= 4) NewPpmData = 0; // zero is equal to new Data |
||
68 | index = 1; |
||
69 | } |
||
70 | else |
||
71 | { |
||
72 | if(index < 10) |
||
73 | { |
||
74 | if((signal > 250) && (signal < 687)) |
||
75 | { |
||
76 | signal -= 466; |
||
77 | |||
78 | if(abs(signal - PPM_in[index]) < 6) // good signal |
||
79 | { |
||
80 | if(SenderOkay < 200) SenderOkay += 10; |
||
81 | else SenderOkay = 200; |
||
82 | } |
||
83 | |||
84 | tmp = (3 * (PPM_in[index]) + signal) / 4; |
||
85 | |||
86 | if(tmp > signal+1) tmp--; |
||
87 | else if(tmp < signal-1) tmp++; |
||
88 | |||
89 | if(SenderOkay >= 195) PPM_diff[index] = ((tmp - PPM_in[index]) / 3) * 3; |
||
90 | else PPM_diff[index] = 0; |
||
91 | |||
92 | PPM_in[index] = tmp; |
||
93 | } |
||
94 | |||
95 | index++; |
||
96 | |||
97 | if(index == 5) J3High; else J3Low; // Servosignal an J3 anlegen |
||
98 | if(index == 6) J4High; else J4Low; // Servosignal an J4 anlegen |
||
99 | if(index == 7) J5High; else J5Low; // Servosignal an J5 anlegen |
||
100 | } |
||
101 | } |
||
102 | } |
||
103 | //---------------------------------------------------------------------------------------------------------------------------------- |
||
104 |