Rev 1506 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 1506 | Rev 1680 | ||
---|---|---|---|
Line 2... | Line 2... | ||
2 | Decodieren eines RC Summen Signals oder Spektrum Empfänger-Satellit |
2 | Decodieren eines RC Summen Signals oder Spektrum Empfänger-Satellit |
3 | #######################################################################################*/ |
3 | #######################################################################################*/ |
Line 4... | Line 4... | ||
4 | 4 | ||
5 | #include "Spektrum.h" |
5 | #include "Spektrum.h" |
6 | #include "main.h" |
6 | #include "main.h" |
Line 7... | Line 7... | ||
7 | //#define RECEIVER_SPEKTRUM_EXP |
7 | // Achtung: RECEIVER_SPEKTRUM_EXP wird in der Main.h gesetzt |
Line 8... | Line 8... | ||
8 | 8 | ||
9 | unsigned char SpektrumTimer = 0; |
9 | unsigned char SpektrumTimer = 0; |
10 | 10 | ||
11 | #ifdef RECEIVER_SPEKTRUM_EXP |
11 | #ifdef RECEIVER_SPEKTRUM_EXP |
12 | unsigned char sexcnt; // Counter for Spektrum-Expander |
12 | unsigned char s_excnt = 0; // Counter for Spektrum-Expander |
13 | unsigned char sexparity; // Parity Bit for Spektrum-Expander |
13 | unsigned char s_exparity = 0; // Parity Bit for Spektrum-Expander |
14 | signed char sexdata[7]; // Data for Spektrum-Expander |
14 | signed char s_exdata[11]; // Data for Spektrum-Expander |
15 | #endif |
15 | #endif |
16 | //--------------------------------------------------------------// |
16 | //--------------------------------------------------------------// |
Line 36... | Line 36... | ||
36 | { |
36 | { |
Line 37... | Line 37... | ||
37 | 37 | ||
38 | printf("ok.\n\r"); |
38 | printf("ok.\n\r"); |
Line 39... | Line 39... | ||
39 | DDRD |= (1 << DDD2); // Rx as output |
39 | DDRD |= (1 << DDD2); // Rx as output |
40 | 40 | ||
41 | while(!CheckDelay(timerTimeout)); // delay after startup of RX |
41 | while(!CheckDelay(timerTimeout)); // delay after startup of RX |
Line 42... | Line 42... | ||
42 | for (delaycounter = 0; delaycounter < 100; delaycounter++) PORTD |= (1 << PORTD2); |
42 | for (delaycounter = 0; delaycounter < 100; delaycounter++) PORTD |= (1 << PORTD2); |
43 | for (delaycounter = 0; delaycounter < 400; delaycounter++) PORTD &= ~(1 << PORTD2); |
43 | for (delaycounter = 0; delaycounter < 400; delaycounter++) PORTD &= ~(1 << PORTD2); |
44 | 44 | ||
45 | for (delaycounter = 0; delaycounter < 10; delaycounter++) PORTD |= (1 << PORTD2); |
45 | for (delaycounter = 0; delaycounter < 10; delaycounter++) PORTD |= (1 << PORTD2); |
Line 46... | Line 46... | ||
46 | for (delaycounter = 0; delaycounter < 10; delaycounter++) PORTD &= ~(1 << PORTD2); |
46 | for (delaycounter = 0; delaycounter < 10; delaycounter++) PORTD &= ~(1 << PORTD2); |
47 | for (delaycounter = 0; delaycounter < 400; delaycounter++) PORTD |= (1 << PORTD2); |
47 | for (delaycounter = 0; delaycounter < 400; delaycounter++) PORTD |= (1 << PORTD2); |
48 | for (delaycounter = 0; delaycounter < 400; delaycounter++) PORTD &= ~(1 << PORTD2); |
48 | for (delaycounter = 0; delaycounter < 400; delaycounter++) PORTD &= ~(1 << PORTD2); |
49 | 49 | ||
Line 50... | Line 50... | ||
50 | for (delaycounter = 0; delaycounter < 10; delaycounter++) PORTD |= (1 << PORTD2); |
50 | for (delaycounter = 0; delaycounter < 10; delaycounter++) PORTD |= (1 << PORTD2); |
51 | for (delaycounter = 0; delaycounter < 10; delaycounter++) PORTD &= ~(1 << PORTD2); |
51 | for (delaycounter = 0; delaycounter < 10; delaycounter++) PORTD &= ~(1 << PORTD2); |
52 | for (delaycounter = 0; delaycounter < 400; delaycounter++) PORTD |= (1 << PORTD2); |
52 | for (delaycounter = 0; delaycounter < 400; delaycounter++) PORTD |= (1 << PORTD2); |
Line 53... | Line 53... | ||
53 | for (delaycounter = 0; delaycounter < 400; delaycounter++) PORTD &= ~(1 << PORTD2); |
53 | for (delaycounter = 0; delaycounter < 400; delaycounter++) PORTD &= ~(1 << PORTD2); |
54 | 54 | ||
55 | for (delaycounter = 0; delaycounter < 10; delaycounter++) PORTD |= (1 << PORTD2); |
55 | for (delaycounter = 0; delaycounter < 10; delaycounter++) PORTD |= (1 << PORTD2); |
Line 72... | Line 72... | ||
72 | //############################################################################ |
72 | //############################################################################ |
73 | // USART1 initialisation from killagreg |
73 | // USART1 initialisation from killagreg |
74 | void SpektrumUartInit(void) |
74 | void SpektrumUartInit(void) |
75 | //############################################################################ |
75 | //############################################################################ |
76 | { |
76 | { |
77 | // -- Start of USART1 initialisation for Spekturm seriell-mode |
77 | // -- Start of USART1 initialisation for Spekturm seriell-mode |
78 | // USART1 Control and Status Register A, B, C and baud rate register |
78 | // USART1 Control and Status Register A, B, C and baud rate register |
79 | uint8_t sreg = SREG; |
79 | uint8_t sreg = SREG; |
80 | 80 | ||
81 | uint16_t ubrr = (uint16_t) ((uint32_t) SYSCLK/(8 * 115200) - 1); |
81 | uint16_t ubrr = (uint16_t) ((uint32_t) SYSCLK/(8 * 115200) - 1); |
82 | 82 | ||
83 | // disable all interrupts before reconfiguration |
83 | // disable all interrupts before reconfiguration |
84 | cli(); |
84 | cli(); |
85 | // disable RX-Interrupt |
85 | // disable RX-Interrupt |
86 | UCSR1B &= ~(1 << RXCIE1); |
86 | UCSR1B &= ~(1 << RXCIE1); |
87 | // disable TX-Interrupt |
87 | // disable TX-Interrupt |
88 | UCSR1B &= ~(1 << TXCIE1); |
88 | UCSR1B &= ~(1 << TXCIE1); |
89 | // disable DRE-Interrupt |
89 | // disable DRE-Interrupt |
90 | UCSR1B &= ~(1 << UDRIE1); |
90 | UCSR1B &= ~(1 << UDRIE1); |
91 | // set direction of RXD1 and TXD1 pins |
91 | // set direction of RXD1 and TXD1 pins |
92 | // set RXD1 (PD2) as an input pin |
92 | // set RXD1 (PD2) as an input pin |
93 | PORTD |= (1 << PORTD2); |
93 | PORTD |= (1 << PORTD2); |
94 | DDRD &= ~(1 << DDD2); |
94 | DDRD &= ~(1 << DDD2); |
95 | 95 | ||
96 | // set TXD1 (PD3) as an output pin |
96 | // set TXD1 (PD3) as an output pin |
97 | PORTD |= (1 << PORTD3); |
97 | PORTD |= (1 << PORTD3); |
98 | DDRD |= (1 << DDD3); |
98 | DDRD |= (1 << DDD3); |
99 | 99 | ||
100 | // USART0 Baud Rate Register |
100 | // USART0 Baud Rate Register |
101 | // set clock divider |
101 | // set clock divider |
102 | UBRR1H = (uint8_t)(ubrr>>8); |
102 | UBRR1H = (uint8_t)(ubrr>>8); |
103 | UBRR1L = (uint8_t)ubrr; |
103 | UBRR1L = (uint8_t)ubrr; |
104 | // enable double speed operation |
104 | // enable double speed operation |
105 | UCSR1A |= (1 << U2X1); |
105 | UCSR1A |= (1 << U2X1); |
106 | // enable receiver and transmitter |
106 | // enable receiver and transmitter |
107 | //UCSR1B = (1<<RXEN1)|(1<<TXEN1); |
107 | //UCSR1B = (1<<RXEN1)|(1<<TXEN1); |
108 | 108 | ||
109 | UCSR1B = (1<<RXEN1); |
109 | UCSR1B = (1<<RXEN1); |
110 | // set asynchronous mode |
110 | // set asynchronous mode |
111 | UCSR1C &= ~(1 << UMSEL11); |
111 | UCSR1C &= ~(1 << UMSEL11); |
112 | UCSR1C &= ~(1 << UMSEL10); |
112 | UCSR1C &= ~(1 << UMSEL10); |
113 | // no parity |
113 | // no parity |
114 | UCSR1C &= ~(1 << UPM11); |
114 | UCSR1C &= ~(1 << UPM11); |
115 | UCSR1C &= ~(1 << UPM10); |
115 | UCSR1C &= ~(1 << UPM10); |
116 | // 1 stop bit |
116 | // 1 stop bit |
117 | UCSR1C &= ~(1 << USBS1); |
117 | UCSR1C &= ~(1 << USBS1); |
118 | // 8-bit |
118 | // 8-bit |
119 | UCSR1B &= ~(1 << UCSZ12); |
119 | UCSR1B &= ~(1 << UCSZ12); |
120 | UCSR1C |= (1 << UCSZ11); |
120 | UCSR1C |= (1 << UCSZ11); |
121 | UCSR1C |= (1 << UCSZ10); |
121 | UCSR1C |= (1 << UCSZ10); |
122 | // flush receive buffer explicit |
122 | // flush receive buffer explicit |
123 | while(UCSR1A & (1<<RXC1)) UDR1; |
123 | while(UCSR1A & (1<<RXC1)) UDR1; |
124 | // enable RX-interrupts at the end |
124 | // enable RX-interrupts at the end |
125 | UCSR1B |= (1 << RXCIE1); |
125 | UCSR1B |= (1 << RXCIE1); |
126 | // -- End of USART1 initialisation |
126 | // -- End of USART1 initialisation |
127 | // restore global interrupt flags |
127 | // restore global interrupt flags |
Line 128... | Line 128... | ||
128 | 128 | ||
129 | SREG = sreg; |
129 | SREG = sreg; |
130 | return; |
130 | return; |
Line 131... | Line 131... | ||
131 | } |
131 | } |
132 | 132 | ||
Line 146... | Line 146... | ||
146 | // Entweder Summensignal ODER Spektrum-Receiver anschließen. Nicht beides gleichzeitig betreiben! |
146 | // Entweder Summensignal ODER Spektrum-Receiver anschließen. Nicht beides gleichzeitig betreiben! |
147 | // Binding is not implemented. Bind with external Receiver. |
147 | // Binding is not implemented. Bind with external Receiver. |
148 | // Servo output J3, J4, J5 not serviced |
148 | // Servo output J3, J4, J5 not serviced |
149 | // |
149 | // |
150 | // Anschuß Spektrum Receiver |
150 | // Anschuß Spektrum Receiver |
151 | // Orange: 3V von der FC (keinesfalls an 5V anschließen!) |
151 | // Orange: 3V von der FC (keinesfalls an 5V anschließen!) |
152 | // Schwarz: GND |
152 | // Schwarz: GND |
153 | // Grau: RXD1 (Pin 3) auf 10-Pol FC-Stecker |
153 | // Grau: RXD1 (Pin 3) auf 10-Pol FC-Stecker |
154 | // |
154 | // |
155 | // --- |
155 | // --- |
156 | // Satellite-Reciever connected on USART1: |
156 | // Satellite-Reciever connected on USART1: |
157 | // |
157 | // |
158 | // DX7/DX6i: One data-frame at 115200 baud every 22ms. |
158 | // DX7/DX6i: One data-frame at 115200 baud every 22ms. |
159 | // DX7se: One data-frame at 115200 baud every 11ms. |
159 | // DX7se: One data-frame at 115200 baud every 11ms. |
160 | // byte1: unknown |
160 | // byte1: unknown |
161 | // byte2: unknown |
161 | // byte2: unknown |
162 | // byte3: and byte4: channel data (FLT-Mode) |
162 | // byte3: and byte4: channel data (FLT-Mode) |
163 | // byte5: and byte6: channel data (Roll) |
163 | // byte5: and byte6: channel data (Roll) |
164 | // byte7: and byte8: channel data (Nick) |
164 | // byte7: and byte8: channel data (Nick) |
165 | // byte9: and byte10: channel data (Gier) |
165 | // byte9: and byte10: channel data (Gier) |
166 | // byte11: and byte12: channel data (Gear Switch) |
166 | // byte11: and byte12: channel data (Gear Switch) |
167 | // byte13: and byte14: channel data (Gas) |
167 | // byte13: and byte14: channel data (Gas) |
168 | // byte15: and byte16: channel data (AUX2) |
168 | // byte15: and byte16: channel data (AUX2) |
169 | // |
169 | // |
170 | // DS9 (9 Channel): One data-frame at 115200 baud every 11ms, alternating frame 1/2 for CH1-7 / CH8-9 |
170 | // DS9 (9 Channel): One data-frame at 115200 baud every 11ms, alternating frame 1/2 for CH1-7 / CH8-9 |
171 | // 1st Frame: |
171 | // 1st Frame: |
172 | // byte1: unknown |
172 | // byte1: unknown |
173 | // byte2: unknown |
173 | // byte2: unknown |
174 | // byte3: and byte4: channel data |
174 | // byte3: and byte4: channel data |
175 | // byte5: and byte6: channel data |
175 | // byte5: and byte6: channel data |
176 | // byte7: and byte8: channel data |
176 | // byte7: and byte8: channel data |
177 | // byte9: and byte10: channel data |
177 | // byte9: and byte10: channel data |
178 | // byte11: and byte12: channel data |
178 | // byte11: and byte12: channel data |
179 | // byte13: and byte14: channel data |
179 | // byte13: and byte14: channel data |
180 | // byte15: and byte16: channel data |
180 | // byte15: and byte16: channel data |
181 | // 2nd Frame: |
181 | // 2nd Frame: |
182 | // byte1: unknown |
182 | // byte1: unknown |
183 | // byte2: unknown |
183 | // byte2: unknown |
184 | // byte3: and byte4: channel data |
184 | // byte3: and byte4: channel data |
185 | // byte5: and byte6: channel data |
185 | // byte5: and byte6: channel data |
186 | // byte7: and byte8: 0xffff |
186 | // byte7: and byte8: 0xffff |
187 | // byte9: and byte10: 0xffff |
187 | // byte9: and byte10: 0xffff |
188 | // byte11: and byte12: 0xffff |
188 | // byte11: and byte12: 0xffff |
189 | // byte13: and byte14: 0xffff |
189 | // byte13: and byte14: 0xffff |
190 | // byte15: and byte16: 0xffff |
190 | // byte15: and byte16: 0xffff |
191 | // |
191 | // |
192 | // Each channel data (16 bit= 2byte, first msb, second lsb) is arranged as: |
192 | // Each channel data (16 bit= 2byte, first msb, second lsb) is arranged as: |
193 | // |
193 | // |
194 | // Bits: F 0 C3 C2 C1 C0 D9 D8 D7 D6 D5 D4 D3 D2 D1 D0 |
194 | // Bits: F 0 C3 C2 C1 C0 D9 D8 D7 D6 D5 D4 D3 D2 D1 D0 |
195 | // |
195 | // |
Line 208... | Line 208... | ||
208 | // Wird im UART-Interrupt aufgerufen |
208 | // Wird im UART-Interrupt aufgerufen |
209 | //############################################################################ |
209 | //############################################################################ |
210 | void SpektrumParser(unsigned char c) |
210 | void SpektrumParser(unsigned char c) |
211 | { |
211 | { |
212 | static unsigned char Sync=0, FrameCnt=0, ByteHigh=0, ReSync=1, Frame2=0; |
212 | static unsigned char Sync=0, FrameCnt=0, ByteHigh=0, ReSync=1, Frame2=0; |
213 | unsigned int Channel, index = 0; |
213 | unsigned int Channel, index = 0; |
214 | signed int signal = 0, tmp; |
214 | signed int signal = 0, tmp; |
215 | int bCheckDelay; |
215 | int bCheckDelay; |
216 | // c = UDR1; // get data byte |
216 | // c = UDR1; // get data byte |
217 | if(ReSync == 1) |
217 | if(ReSync == 1) |
218 | { |
218 | { |
219 | // wait for beginning of new frame |
219 | // wait for beginning of new frame |
220 | ReSync = 0; |
220 | ReSync = 0; |
221 | SpektrumTimer = MIN_FRAMEGAP; |
221 | SpektrumTimer = MIN_FRAMEGAP; |
222 | FrameCnt = 0; |
222 | FrameCnt = 0; |
223 | Sync = 0; |
223 | Sync = 0; |
224 | ByteHigh = 0; |
224 | ByteHigh = 0; |
225 | } |
225 | } |
226 | else |
226 | else |
227 | { |
227 | { |
228 | if(!SpektrumTimer) bCheckDelay = 1; else bCheckDelay = 0;//CheckDelay(FrameTimer); |
228 | if(!SpektrumTimer) bCheckDelay = 1; else bCheckDelay = 0;//CheckDelay(FrameTimer); |
229 | if ( Sync == 0 ) |
229 | if ( Sync == 0 ) |
230 | { |
230 | { |
231 | if(bCheckDelay) |
231 | if(bCheckDelay) |
232 | { |
232 | { |
233 | // nach einer Pause von mind. 7ms erstes Sync-Character gefunden |
233 | // nach einer Pause von mind. 7ms erstes Sync-Character gefunden |
234 | // Zeichen ignorieren, da Bedeutung unbekannt |
234 | // Zeichen ignorieren, da Bedeutung unbekannt |
235 | Sync = 1; |
235 | Sync = 1; |
236 | FrameCnt ++; |
236 | FrameCnt ++; |
237 | SpektrumTimer = MAX_BYTEGAP; |
237 | SpektrumTimer = MAX_BYTEGAP; |
238 | } |
238 | } |
239 | else |
239 | else |
240 | { |
240 | { |
241 | // Zeichen kam vor Ablauf der 7ms Sync-Pause |
241 | // Zeichen kam vor Ablauf der 7ms Sync-Pause |
242 | // warten auf erstes Sync-Zeichen |
242 | // warten auf erstes Sync-Zeichen |
243 | SpektrumTimer = MIN_FRAMEGAP; |
243 | SpektrumTimer = MIN_FRAMEGAP; |
244 | FrameCnt = 0; |
244 | FrameCnt = 0; |
245 | Sync = 0; |
245 | Sync = 0; |
246 | ByteHigh = 0; |
246 | ByteHigh = 0; |
247 | } |
247 | } |
248 | } |
248 | } |
249 | else if((Sync == 1) && !bCheckDelay) |
249 | else if((Sync == 1) && !bCheckDelay) |
250 | { |
250 | { |
251 | // zweites Sync-Character ignorieren, Bedeutung unbekannt |
251 | // zweites Sync-Character ignorieren, Bedeutung unbekannt |
252 | Sync = 2; |
252 | Sync = 2; |
253 | FrameCnt ++; |
253 | FrameCnt ++; |
254 | SpektrumTimer = MAX_BYTEGAP; |
254 | SpektrumTimer = MAX_BYTEGAP; |
255 | } |
255 | } |
256 | else if((Sync == 2) && !bCheckDelay) |
256 | else if((Sync == 2) && !bCheckDelay) |
257 | { |
257 | { |
258 | SpektrumTimer = MAX_BYTEGAP; |
258 | SpektrumTimer = MAX_BYTEGAP; |
259 | // Datenbyte high |
259 | // Datenbyte high |
260 | ByteHigh = c; |
260 | ByteHigh = c; |
261 | if (FrameCnt == 2) |
261 | if (FrameCnt == 2) |
262 | { |
262 | { |
263 | // is 1st Byte of Channel-data |
263 | // is 1st Byte of Channel-data |
264 | // Frame 1 with Channel 1-7 comming next |
264 | // Frame 1 with Channel 1-7 comming next |
265 | Frame2 = 0; |
265 | Frame2 = 0; |
266 | if(ByteHigh & 0x80) |
266 | if(ByteHigh & 0x80) |
267 | { |
267 | { |
268 | // DS9: Frame 2 with Channel 8-9 comming next |
268 | // DS9: Frame 2 with Channel 8-9 comming next |
269 | Frame2 = 1; |
269 | Frame2 = 1; |
270 | } |
270 | } |
271 | } |
271 | } |
272 | Sync = 3; |
272 | Sync = 3; |
273 | FrameCnt ++; |
273 | FrameCnt ++; |
274 | } |
274 | } |
275 | else if((Sync == 3) && !bCheckDelay) |
275 | else if((Sync == 3) && !bCheckDelay) |
276 | { |
276 | { |
277 | // Datenbyte low |
277 | // Datenbyte low |
278 | // High-Byte for next channel comes next |
278 | // High-Byte for next channel comes next |
279 | SpektrumTimer = MAX_BYTEGAP; |
279 | SpektrumTimer = MAX_BYTEGAP; |
280 | Sync = 2; |
280 | Sync = 2; |
281 | FrameCnt ++; |
281 | FrameCnt ++; |
282 | Channel = ((unsigned int)ByteHigh << 8) | c; |
282 | Channel = ((unsigned int)ByteHigh << 8) | c; |
283 | if(EE_Parameter.Receiver == RECEIVER_SPEKTRUM) |
283 | if(EE_Parameter.Receiver == RECEIVER_SPEKTRUM) |
284 | { |
284 | { |
285 | signal = Channel & 0x3ff; |
285 | signal = Channel & 0x3ff; |
286 | signal -= 0x200; // Offset, range 0x000..0x3ff? |
286 | signal -= 0x200; // Offset, range 0x000..0x3ff? |
287 | signal = signal/3; // scaling to fit PPM resolution |
287 | signal = signal/3; // scaling to fit PPM resolution |
288 | index = (ByteHigh >> 2) & 0x0f; |
288 | index = (ByteHigh >> 2) & 0x0f; |
289 | } |
289 | } |
290 | else |
290 | else |
291 | if(EE_Parameter.Receiver == RECEIVER_SPEKTRUM_HI_RES) |
291 | if(EE_Parameter.Receiver == RECEIVER_SPEKTRUM_HI_RES) |
292 | { |
292 | { |
293 | signal = Channel & 0x7ff; |
293 | signal = Channel & 0x7ff; |
294 | signal -= 0x400; // Offset, range 0x000..0x7ff? |
294 | signal -= 0x400; // Offset, range 0x000..0x7ff? |
295 | signal = signal/6; // scaling to fit PPM resolution |
295 | signal = signal/6; // scaling to fit PPM resolution |
296 | index = (ByteHigh >> 3) & 0x0f; |
296 | index = (ByteHigh >> 3) & 0x0f; |
297 | } |
297 | } |
298 | else |
298 | else |
299 | //if(EE_Parameter.Receiver == RECEIVER_SPEKTRUM_LOW_RES) |
299 | //if(EE_Parameter.Receiver == RECEIVER_SPEKTRUM_LOW_RES) |
300 | { |
300 | { |
301 | signal = Channel & 0x3ff; |
301 | signal = Channel & 0x3ff; |
302 | signal -= 360; // Offset, range 0x000..0x3ff? |
302 | signal -= 360; // Offset, range 0x000..0x3ff? |
303 | signal = signal/2; // scaling to fit PPM resolution |
303 | signal = signal/2; // scaling to fit PPM resolution |
304 | index = (ByteHigh >> 2) & 0x0f; |
304 | index = (ByteHigh >> 2) & 0x0f; |
305 | } |
305 | } |
306 | 306 | ||
307 | index++; |
307 | index++; |
308 | if(index < 13) |
308 | if(index < 13) |
309 | { |
309 | { |
310 | // Stabiles Signal |
310 | // Stabiles Signal |
311 | #ifdef RECEIVER_SPEKTRUM_EXP |
311 | #ifdef RECEIVER_SPEKTRUM_EXP |
312 | if (index == 2) index = 4; // Analog channel reassigment (2 <-> 4) for logical numbering (1,2,3,4) |
312 | if (index == 2) index = 4; // Analog channel reassigment (2 <-> 4) for logical numbering (1,2,3,4) |
313 | else if (index == 4) index = 2; |
313 | else if (index == 4) index = 2; |
314 | #endif |
314 | #endif |
315 | if(abs(signal - PPM_in[index]) < 6) |
315 | if(abs(signal - PPM_in[index]) < 6) |
316 | { |
- | |
317 | if(SenderOkay < 200) SenderOkay += 10; |
- | |
318 | else |
- | |
319 | { |
- | |
320 | SenderOkay = 200; |
- | |
321 | TIMSK1 &= ~_BV(ICIE1); // disable PPM-Input |
- | |
322 | } |
- | |
323 | } |
- | |
324 | tmp = (3 * (PPM_in[index]) + signal) / 4; |
- | |
325 | if(tmp > signal+1) tmp--; else |
- | |
326 | if(tmp < signal-1) tmp++; |
- | |
327 | - | ||
328 | #ifdef RECEIVER_SPEKTRUM_EXP |
- | |
329 | if(index == 6) // FLIGHT-MODE - The channel used for our data uplink |
- | |
330 | { |
- | |
331 | if (signal > 100) // SYNC received |
- | |
332 | { |
316 | { |
333 | sexcnt = 0; // Reset bitcounter |
- | |
334 | sexparity = 0; // Reset parity bit |
317 | if(SenderOkay < 200) SenderOkay += 10; |
335 | } |
318 | else |
336 | - | ||
337 | if (signal < 10) |
- | |
338 | { |
319 | { |
339 | sexcnt++; // Increase counter only for non-sync bits |
320 | SenderOkay = 200; |
340 | sexdata[sexcnt] = -113; // Bit = 0 -> value = -113 (min) |
321 | TIMSK1 &= ~_BV(ICIE1); // disable PPM-Input |
341 | } |
322 | } |
- | 323 | } |
|
- | 324 | tmp = (3 * (PPM_in[index]) + signal) / 4; |
|
- | 325 | if(tmp > signal+1) tmp--; else |
|
- | 326 | if(tmp < signal-1) tmp++; |
|
- | 327 | ||
- | 328 | #ifdef RECEIVER_SPEKTRUM_EXP |
|
- | 329 | if(index == 6) // FLIGHT-MODE - The channel used for our data uplink |
|
- | 330 | { |
|
- | 331 | if (signal > 100) // SYNC received |
|
- | 332 | { |
|
- | 333 | if (s_exdata[s_excnt] == 125) s_exparity = ~s_exparity; // Bit = 1 -> Re-Invert parity bit |
|
- | 334 | if ((s_excnt == 6 && ((s_exparity != 0 && s_exdata[s_excnt] == -125) || (s_exparity == 0 && s_exdata[s_excnt] == 125))) || (s_excnt == 9 && ((s_exparity == 0 && s_exdata[s_excnt] == -125) || (s_exparity != 0 && s_exdata[s_excnt] == 125)))) // Parity check |
|
- | 335 | { |
|
- | 336 | if (s_exdata[1] == 125 && s_exdata[2] == -125) PPM_in[5] = -125; // Reconstruct tripole Flight-Mode value (CH5) |
|
- | 337 | else if (s_exdata[1] == -125 && s_exdata[2] == -125) PPM_in[5] = 0; // Reconstruct tripole Flight-Mode value (CH5) |
|
- | 338 | else if (s_exdata[1] == -125 && s_exdata[2] == 125) PPM_in[5] = 125; // Reconstruct tripole Flight-Mode value (CH5) |
|
- | 339 | PPM_in[6] = s_exdata[3]; // Elevator (CH6) |
|
- | 340 | PPM_in[11] = s_exdata[4]; // Aileron (CH11) |
|
- | 341 | PPM_in[12] = s_exdata[5]; // Rudder (CH12) |
|
- | 342 | ||
- | 343 | if (s_excnt == 9) // New Mode (12 Channels) |
|
- | 344 | { |
|
- | 345 | if (s_exdata[7] == 125) PPM_in[8] += 5; // Hover Pitch UP (CH8) |
|
- | 346 | if (s_exdata[8] == 125) PPM_in[8] -= 5; // Hover Pitch DN (CH8) |
|
- | 347 | if (PPM_in[8] < -125) PPM_in[8] = -125; // Range-Limit |
|
- | 348 | else if (PPM_in[8] > 125) PPM_in[8] = 125; // Range-Limit |
|
- | 349 | PPM_in[10] = s_exdata[6]; // AUX2 (CH10) |
|
- | 350 | } |
|
- | 351 | } |
|
Line 342... | Line 352... | ||
342 | 352 | ||
- | 353 | s_excnt = 0; // Reset bitcounter |
|
- | 354 | s_exparity = 0; // Reset parity bit |
|
Line -... | Line 355... | ||
- | 355 | } |
|
- | 356 | ||
343 | if (sexcnt == 7) sexcnt = 0; // Overflow protection |
357 | if (signal < 10) s_exdata[++s_excnt] = -125; // Bit = 0 -> value = -125 (min) |
344 | 358 | if (s_excnt == 10) s_excnt = 0; // Overflow protection |
|
345 | if (signal < -100) |
359 | if (signal < -100) |
346 | { |
360 | { |
347 | sexdata[sexcnt] = 114; // Bit = 1 -> value = 114 (max) |
- | |
348 | if (sexcnt < 6) sexparity = ~sexparity; // Bit = 1 -> Invert parity bit (without itself) |
- | |
349 | } |
- | |
350 | - | ||
351 | if (sexcnt == 6) // Wait for complete frame |
- | |
352 | { |
- | |
353 | if ((sexparity != 0 && sexdata[6] == -113) || (sexparity == 0 && sexdata[6] == 114)) // Parity check |
- | |
354 | { |
- | |
355 | if (sexdata[1] == 114 && sexdata[2] == -113) PPM_in[5] = -113;// Reconstruct tripole Flight-Mode value (CH5) |
- | |
356 | if (sexdata[1] == -113 && sexdata[2] == -113) PPM_in[5] = 0; // Reconstruct tripole Flight-Mode value (CH5) |
- | |
357 | if (sexdata[1] == -113 && sexdata[2] == 114) PPM_in[5] = 114; // Reconstruct tripole Flight-Mode value (CH5) |
- | |
358 | PPM_in[6] = sexdata[3]; // Elevator (CH6) |
- | |
359 | PPM_in[9] = sexdata[4]; // Aileron (CH9) |
- | |
360 | PPM_in[10] = sexdata[5]; // Rudder (CH10) |
361 | s_exdata[s_excnt] = 125; // Bit = 1 -> value = 125 (max) |
- | 362 | s_exparity = ~s_exparity; // Bit = 1 -> Invert parity bit |
|
361 | } |
363 | } |
362 | } |
364 | |
363 | } |
365 | } |
- | 366 | #endif |
|
Line 364... | Line -... | ||
364 | #endif |
- | |
365 | if(SenderOkay >= 180) PPM_diff[index] = ((tmp - PPM_in[index]) / 3) * 3; |
- | |
366 | 367 | if(SenderOkay >= 180) PPM_diff[index] = ((tmp - PPM_in[index]) / 3) * 3; |
|
367 | else PPM_diff[index] = 0; |
368 | else PPM_diff[index] = 0; |
368 | 369 | ||
369 | #ifdef RECEIVER_SPEKTRUM_EXP |
370 | #ifdef RECEIVER_SPEKTRUM_EXP |
370 | if (index < 5 ) PPM_in[index] = tmp; // Update normal potis (CH1-4) |
371 | if (index < 5 ) PPM_in[index] = tmp; // Update normal potis (CH1-4) |
371 | if (index == 5) PPM_in[7] = signal; // Gear (CH7) |
372 | else if (index == 5) PPM_in[7] = signal; // Gear (CH7) |
372 | if (index == 7) PPM_in[8] = signal; // AUX2 (CH8) |
373 | else if (index == 7) PPM_in[9] = signal; // Hover Throttle (CH9) |
373 | #else |
374 | #else |
374 | PPM_in[index] = tmp; |
375 | PPM_in[index] = tmp; |
375 | #endif |
376 | #endif |
376 | } |
377 | } |
377 | else if(index > 17) ReSync = 1; // hier stimmt was nicht: neu synchronisieren |
378 | else if(index > 17) ReSync = 1; // hier stimmt was nicht: neu synchronisieren |
378 | } |
379 | } |
379 | else |
380 | else |
380 | { |
381 | { |
381 | // hier stimmt was nicht: neu synchronisieren |
382 | // hier stimmt was nicht: neu synchronisieren |
382 | ReSync = 1; |
383 | ReSync = 1; |
383 | FrameCnt = 0; |
384 | FrameCnt = 0; |
384 | Frame2 = 0; |
385 | Frame2 = 0; |
385 | // new frame next, nach fruehestens 7ms erwartet |
386 | // new frame next, nach fruehestens 7ms erwartet |
386 | SpektrumTimer = MIN_FRAMEGAP; |
387 | SpektrumTimer = MIN_FRAMEGAP; |
387 | } |
388 | } |
388 | 389 | ||
389 | // 16 Bytes eingetroffen -> Komplett |
390 | // 16 Bytes eingetroffen -> Komplett |
390 | if(FrameCnt >= 16) |
391 | if(FrameCnt >= 16) |
391 | { |
392 | { |
392 | // Frame complete |
393 | // Frame complete |
393 | if(Frame2 == 0) |
394 | if(Frame2 == 0) |
394 | { |
395 | { |
395 | // Null bedeutet: Neue Daten |
396 | // Null bedeutet: Neue Daten |
396 | // nur beim ersten Frame (CH 0-7) setzen |
397 | // nur beim ersten Frame (CH 0-7) setzen |
397 | if(!ReSync) NewPpmData = 0; |
398 | if(!ReSync) NewPpmData = 0; |
398 | } |
399 | } |
399 | FrameCnt = 0; |
400 | FrameCnt = 0; |
400 | Frame2 = 0; |
401 | Frame2 = 0; |
401 | Sync = 0; |
402 | Sync = 0; |
402 | SpektrumTimer = MIN_FRAMEGAP; |
403 | SpektrumTimer = MIN_FRAMEGAP; |
403 | } |
- | |
404 | } |
- |