Rev 2136 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 2136 | Rev 2173 | ||
---|---|---|---|
Line 9... | Line 9... | ||
9 | #include "output.h" |
9 | #include "output.h" |
Line 10... | Line 10... | ||
10 | 10 | ||
11 | // The channel array is 0-based! |
11 | // The channel array is 0-based! |
12 | volatile int16_t PPM_in[MAX_CHANNELS]; |
12 | volatile int16_t PPM_in[MAX_CHANNELS]; |
13 | volatile uint16_t RC_buffer[MAX_CHANNELS]; |
13 | volatile uint16_t RC_buffer[MAX_CHANNELS]; |
Line 14... | Line 14... | ||
14 | volatile uint8_t inBfrPnt = 0; |
14 | volatile uint8_t inBfrPnt; |
Line 15... | Line 15... | ||
15 | 15 | ||
16 | volatile uint8_t RCQuality; |
16 | volatile uint8_t RCQuality; |
Line 17... | Line 17... | ||
17 | 17 | ||
Line 18... | Line 18... | ||
18 | uint8_t lastRCCommand = COMMAND_NONE; |
18 | uint8_t lastRCCommand; |
19 | uint8_t lastFlightMode = FLIGHT_MODE_NONE; |
19 | uint8_t lastFlightMode; |
Line 70... | Line 70... | ||
70 | // Enable Input Capture Interrupt (bit: ICIE1=1) |
70 | // Enable Input Capture Interrupt (bit: ICIE1=1) |
71 | // Disable Output Compare A & B Match Interrupts (bit: OCIE1B=0, OICIE1A=0) |
71 | // Disable Output Compare A & B Match Interrupts (bit: OCIE1B=0, OICIE1A=0) |
72 | // Enable Overflow Interrupt (bit: TOIE1=0) |
72 | // Enable Overflow Interrupt (bit: TOIE1=0) |
73 | TIMSK1 &= ~((1<<OCIE1B) | (1<<OCIE1A) | (1<<TOIE1)); |
73 | TIMSK1 &= ~((1<<OCIE1B) | (1<<OCIE1A) | (1<<TOIE1)); |
74 | TIMSK1 |= (1<<ICIE1); |
74 | TIMSK1 |= (1<<ICIE1); |
75 | - | ||
76 | RCQuality = 0; |
75 | RCQuality = 0; |
77 | - | ||
78 | SREG = sreg; |
76 | SREG = sreg; |
79 | } |
77 | } |
Line 80... | Line 78... | ||
80 | 78 | ||
81 | /* |
79 | /* |
Line 85... | Line 83... | ||
85 | static uint16_t oldICR1 = 0; |
83 | static uint16_t oldICR1 = 0; |
86 | uint16_t signal = (uint16_t)ICR1 - oldICR1; |
84 | uint16_t signal = (uint16_t)ICR1 - oldICR1; |
87 | oldICR1 = ICR1; |
85 | oldICR1 = ICR1; |
88 | //sync gap? (3.5 ms < signal < 25.6 ms) |
86 | //sync gap? (3.5 ms < signal < 25.6 ms) |
89 | if (signal > TIME(3.5)) { |
87 | if (signal > TIME(3.5)) { |
90 | inBfrPnt = 0; |
88 | inBfrPnt = 0; |
91 | } else if (inBfrPnt<MAX_CHANNELS) { |
89 | } else if (inBfrPnt<MAX_CHANNELS) { |
92 | RC_buffer[inBfrPnt++] = signal; |
90 | RC_buffer[inBfrPnt++] = signal; |
93 | } |
91 | } |
94 | } |
92 | } |
Line 95... | Line 93... | ||
95 | 93 | ||
96 | /********************************************************************/ |
94 | /********************************************************************/ |
Line 113... | Line 111... | ||
113 | The maximum duration of all channels at maximum value is 8 * 2 ms = 16 ms. |
111 | The maximum duration of all channels at maximum value is 8 * 2 ms = 16 ms. |
114 | The remaining time of (22.5 - 8 ms) ms = 14.5 ms to (22.5 - 16 ms) ms = 6.5 ms is |
112 | The remaining time of (22.5 - 8 ms) ms = 14.5 ms to (22.5 - 16 ms) ms = 6.5 ms is |
115 | the syncronization gap. |
113 | the syncronization gap. |
116 | */ |
114 | */ |
117 | void RC_process(void) { |
115 | void RC_process(void) { |
118 | if (RCQuality) RCQuality--; |
116 | if (RCQuality) RCQuality--; |
119 | for (uint8_t channel=0; channel<MAX_CHANNELS; channel++) { |
117 | for (uint8_t channel=0; channel<MAX_CHANNELS; channel++) { |
120 | uint16_t signal = RC_buffer[channel]; |
118 | uint16_t signal = RC_buffer[channel]; |
121 | if (signal != 0) { |
119 | if (signal != 0) { |
122 | RC_buffer[channel] = 0; // reset to flag value already used. |
120 | RC_buffer[channel] = 0; // reset to flag value already used. |
123 | if ((signal >= TIME(0.8)) && (signal < TIME(2.2))) { |
121 | if ((signal >= TIME(0.8)) && (signal < TIME(2.2))) { |