Rev 1743 | Rev 1984 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 1743 | Rev 1928 | ||
---|---|---|---|
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 | // Achtung: RECEIVER_SPEKTRUM_EXP wird in der Main.h gesetzt |
7 | // Achtung: RECEIVER_SPEKTRUM_DX7EXP oder RECEIVER_SPEKTRUM_DX8EXP 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 | #if defined (RECEIVER_SPEKTRUM_DX7EXP) || defined (RECEIVER_SPEKTRUM_DX8EXP) |
12 | unsigned char s_excnt = 0; // Counter for Spektrum-Expander |
12 | unsigned char s_excnt = 0; // Counter for Spektrum-Expander |
13 | unsigned char s_exparity = 0; // Parity Bit for Spektrum-Expander |
13 | unsigned char s_exparity = 0; // Parity Bit for Spektrum-Expander |
Line 76... | Line 76... | ||
76 | //############################################################################ |
76 | //############################################################################ |
77 | { |
77 | { |
78 | // -- Start of USART1 initialisation for Spekturm seriell-mode |
78 | // -- Start of USART1 initialisation for Spekturm seriell-mode |
79 | // USART1 Control and Status Register A, B, C and baud rate register |
79 | // USART1 Control and Status Register A, B, C and baud rate register |
80 | uint8_t sreg = SREG; |
80 | uint8_t sreg = SREG; |
81 | 81 | ||
82 | uint16_t ubrr = (uint16_t) ((uint32_t) SYSCLK/(8 * 115200) - 1); |
82 | uint16_t ubrr = (uint16_t) ((uint32_t) SYSCLK/(8 * 115200) - 1); |
83 | 83 | ||
84 | // disable all interrupts before reconfiguration |
84 | // disable all interrupts before reconfiguration |
85 | cli(); |
85 | cli(); |
86 | // disable RX-Interrupt |
86 | // disable RX-Interrupt |
87 | UCSR1B &= ~(1 << RXCIE1); |
87 | UCSR1B &= ~(1 << RXCIE1); |
88 | // disable TX-Interrupt |
88 | // disable TX-Interrupt |
Line 95... | Line 95... | ||
95 | DDRD &= ~(1 << DDD2); |
95 | DDRD &= ~(1 << DDD2); |
Line 96... | Line 96... | ||
96 | 96 | ||
97 | // set TXD1 (PD3) as an output pin |
97 | // set TXD1 (PD3) as an output pin |
98 | PORTD |= (1 << PORTD3); |
98 | PORTD |= (1 << PORTD3); |
99 | DDRD |= (1 << DDD3); |
99 | DDRD |= (1 << DDD3); |
100 | 100 | ||
101 | // USART0 Baud Rate Register |
101 | // USART0 Baud Rate Register |
102 | // set clock divider |
102 | // set clock divider |
103 | UBRR1H = (uint8_t)(ubrr>>8); |
103 | UBRR1H = (uint8_t)(ubrr>>8); |
104 | UBRR1L = (uint8_t)ubrr; |
104 | UBRR1L = (uint8_t)ubrr; |
Line 124... | Line 124... | ||
124 | while(UCSR1A & (1<<RXC1)) UDR1; |
124 | while(UCSR1A & (1<<RXC1)) UDR1; |
125 | // enable RX-interrupts at the end |
125 | // enable RX-interrupts at the end |
126 | UCSR1B |= (1 << RXCIE1); |
126 | UCSR1B |= (1 << RXCIE1); |
127 | // -- End of USART1 initialisation |
127 | // -- End of USART1 initialisation |
128 | // restore global interrupt flags |
128 | // restore global interrupt flags |
129 | 129 | ||
130 | SREG = sreg; |
130 | SREG = sreg; |
131 | return; |
131 | return; |
132 | } |
132 | } |
Line 133... | Line 133... | ||
133 | 133 | ||
Line 293... | Line 293... | ||
293 | { |
293 | { |
294 | signal = Channel & 0x7ff; |
294 | signal = Channel & 0x7ff; |
295 | signal -= 0x400; // Offset, range 0x000..0x7ff? |
295 | signal -= 0x400; // Offset, range 0x000..0x7ff? |
296 | signal = signal/6; // scaling to fit PPM resolution |
296 | signal = signal/6; // scaling to fit PPM resolution |
297 | index = (ByteHigh >> 3) & 0x0f; |
297 | index = (ByteHigh >> 3) & 0x0f; |
298 | } |
298 | } |
299 | else |
299 | else |
300 | //if(EE_Parameter.Receiver == RECEIVER_SPEKTRUM_LOW_RES) |
300 | //if(EE_Parameter.Receiver == RECEIVER_SPEKTRUM_LOW_RES) |
301 | { |
301 | { |
302 | signal = Channel & 0x3ff; |
302 | signal = Channel & 0x3ff; |
303 | signal -= 360; // Offset, range 0x000..0x3ff? |
303 | signal -= 360; // Offset, range 0x000..0x3ff? |
Line 307... | Line 307... | ||
307 | 307 | ||
308 | index++; |
308 | index++; |
309 | if(index < 13) |
309 | if(index < 13) |
310 | { |
310 | { |
311 | // Stabiles Signal |
311 | // Stabiles Signal |
312 | #ifdef RECEIVER_SPEKTRUM_EXP |
312 | #if defined (RECEIVER_SPEKTRUM_DX7EXP) || defined (RECEIVER_SPEKTRUM_DX8EXP) |
313 | if (index == 2) index = 4; // Analog channel reassigment (2 <-> 4) for logical numbering (1,2,3,4) |
313 | if (index == 2) index = 4; // Analog channel reassigment (2 <-> 4) for logical numbering (1,2,3,4) |
314 | else if (index == 4) index = 2; |
314 | else if (index == 4) index = 2; |
315 | #endif |
315 | #endif |
316 | if(abs(signal - PPM_in[index]) < 6) |
316 | if(abs(signal - PPM_in[index]) < 6) |
317 | { |
317 | { |
318 | if(SenderOkay < 200) SenderOkay += 10; |
318 | if(SenderOkay < 200) SenderOkay += 10; |
319 | else |
319 | else |
320 | { |
320 | { |
321 | SenderOkay = 200; |
321 | SenderOkay = 200; |
- | 322 | TIMSK1 &= ~_BV(ICIE1); // disable PPM-Input |
|
322 | TIMSK1 &= ~_BV(ICIE1); // disable PPM-Input |
323 | } |
323 | } |
- | |
324 | } |
324 | } |
325 | tmp = (3 * (PPM_in[index]) + signal) / 4; |
325 | tmp = (3 * (PPM_in[index]) + signal) / 4; |
326 | if(tmp > signal+1) tmp--; else |
326 | if(tmp > signal+1) tmp--; else |
327 | if(tmp < signal-1) tmp++; |
327 | if(tmp < signal-1) tmp++; |
328 | 328 | ||
329 | #ifdef RECEIVER_SPEKTRUM_EXP |
329 | #ifdef RECEIVER_SPEKTRUM_DX7EXP |
330 | if(index == 6) // FLIGHT-MODE - The channel used for our data uplink |
330 | if(index == 6) // FLIGHT-MODE - The channel used for our data uplink |
- | 331 | { |
|
331 | { |
332 | if (signal > 100) // SYNC received |
332 | if (signal > 100) // SYNC received |
- | |
333 | { |
333 | { |
334 | if (s_exdata[s_excnt] == 125) s_exparity = ~s_exparity; // Bit = 1 -> Re-Invert parity bit |
334 | if (s_exdata[s_excnt] == 125) s_exparity = ~s_exparity; // Bit = 1 -> Re-Invert parity bit |
335 | 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 | 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 |
336 | { |
336 | { |
337 | if (s_exdata[1] == 125 && s_exdata[2] == -125) PPM_in[5] = -125; // Reconstruct tripole Flight-Mode value (CH5) |
337 | if (s_exdata[1] == 125 && s_exdata[2] == -125) PPM_in[5] = -125; // Reconstruct tripole Flight-Mode value (CH5) |
338 | 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] = 0; // Reconstruct tripole Flight-Mode value (CH5) |
339 | else if (s_exdata[1] == -125 && s_exdata[2] == 125) PPM_in[5] = 125; // Reconstruct tripole Flight-Mode value (CH5) |
339 | else if (s_exdata[1] == -125 && s_exdata[2] == 125) PPM_in[5] = 125; // Reconstruct tripole Flight-Mode value (CH5) |
340 | PPM_in[6] = s_exdata[3]; // Elevator (CH6) |
340 | PPM_in[6] = s_exdata[3]; // Elevator (CH6) |
341 | PPM_in[11] = s_exdata[4]; // Aileron (CH11) |
341 | PPM_in[11] = s_exdata[4]; // Aileron (CH11) |
342 | PPM_in[12] = s_exdata[5]; // Rudder (CH12) |
342 | PPM_in[12] = s_exdata[5]; // Rudder (CH12) |
- | 343 | ||
343 | 344 | if (s_excnt == 9) // New Mode (12 Channels) |
|
344 | if (s_excnt == 9) // New Mode (12 Channels) |
- | |
345 | { |
345 | { |
346 | if (s_exdata[7] == 125) PPM_in[8] += 5; // Hover Pitch UP (CH8) |
346 | if (s_exdata[7] == 125) PPM_in[8] += 5; // Hover Pitch UP (CH8) |
347 | if (s_exdata[8] == 125) PPM_in[8] -= 5; // Hover Pitch DN (CH8) |
347 | if (s_exdata[8] == 125) PPM_in[8] -= 5; // Hover Pitch DN (CH8) |
348 | if (PPM_in[8] < -125) PPM_in[8] = -125; // Range-Limit |
348 | if (PPM_in[8] < -125) PPM_in[8] = -125; // Range-Limit |
- | 349 | else if (PPM_in[8] > 125) PPM_in[8] = 125; // Range-Limit |
|
349 | else if (PPM_in[8] > 125) PPM_in[8] = 125; // Range-Limit |
350 | PPM_in[10] = s_exdata[6]; // AUX2 (CH10) |
350 | PPM_in[10] = s_exdata[6]; // AUX2 (CH10) |
351 | } |
351 | } |
- | |
352 | } |
352 | } |
353 | 353 | ||
- | 354 | s_excnt = 0; // Reset bitcounter |
|
354 | s_excnt = 0; // Reset bitcounter |
355 | s_exparity = 0; // Reset parity bit |
355 | s_exparity = 0; // Reset parity bit |
- | |
356 | } |
356 | } |
357 | 357 | ||
358 | if (signal < 10) s_exdata[++s_excnt] = -125; // Bit = 0 -> value = -125 (min) |
358 | if (signal < 10) s_exdata[++s_excnt] = -125; // Bit = 0 -> value = -125 (min) |
359 | if (s_excnt == 10) s_excnt = 0; // Overflow protection |
359 | if (s_excnt == 10) s_excnt = 0; // Overflow protection |
360 | if (signal < -100) |
360 | if (signal < -100) |
361 | { |
361 | { |
362 | s_exdata[s_excnt] = 125; // Bit = 1 -> value = 125 (max) |
362 | s_exdata[s_excnt] = 125; // Bit = 1 -> value = 125 (max) |
- | 363 | s_exparity = ~s_exparity; // Bit = 1 -> Invert parity bit |
|
363 | s_exparity = ~s_exparity; // Bit = 1 -> Invert parity bit |
364 | } |
- | 365 | ||
Line -... | Line 366... | ||
- | 366 | } |
|
- | 367 | ||
- | 368 | #elif defined RECEIVER_SPEKTRUM_DX8EXP |
|
- | 369 | if(index == 6) // FLIGHT-MODE - The channel used for our data uplink |
|
- | 370 | { |
|
- | 371 | if (signal > 100) // SYNC received |
|
- | 372 | { |
|
- | 373 | if (s_exdata[s_excnt] == 125) s_exparity = ~s_exparity; // Bit = 1 -> Re-Invert parity bit |
|
- | 374 | if (s_excnt == 9 && ((s_exparity == 0 && s_exdata[s_excnt] == -125) || (s_exparity != 0 && s_exdata[s_excnt] == 125))) // Parity check |
|
- | 375 | { |
|
- | 376 | if (s_exdata[1] == 125 && s_exdata[2] == -125) PPM_in[5] = -125; // Reconstruct tripole Flight-Mode value (CH5) |
|
364 | } |
377 | else if (s_exdata[1] == -125 && s_exdata[2] == -125) PPM_in[5] = 0; // Reconstruct tripole Flight-Mode value (CH5) |
- | 378 | else if (s_exdata[1] == -125 && s_exdata[2] == 125) PPM_in[5] = 125; // Reconstruct tripole Flight-Mode value (CH5) |
|
- | 379 | ||
- | 380 | if (s_exdata[3] == 125 && s_exdata[6] == -125) PPM_in[6] = 125; // Reconstruct tripole Elev D/R value (CH6) |
|
- | 381 | else if (s_exdata[3] == -125 && s_exdata[6] == -125) PPM_in[6] = 0; // Reconstruct tripole Elev D/R value (CH6) |
|
- | 382 | else if (s_exdata[3] == -125 && s_exdata[6] == 125) PPM_in[6] = -125; // Reconstruct tripole Elev D/R value (CH6) |
|
- | 383 | ||
- | 384 | ||
- | 385 | if (s_exdata[7] == 125 && s_exdata[8] == -125) PPM_in[9] = -125; // Reconstruct tripole AIL D/R value (CH9) |
|
- | 386 | else if (s_exdata[7] == -125 && s_exdata[8] == -125) PPM_in[9] = 0; // Reconstruct tripole AIL D/R value (CH9) |
|
- | 387 | else if (s_exdata[7] == -125 && s_exdata[8] == 125) PPM_in[9] = 125; // Reconstruct tripole AIL D/R value (CH9) |
|
- | 388 | ||
- | 389 | PPM_in[10] = s_exdata[5]; // Gear (CH10) |
|
- | 390 | PPM_in[12] = s_exdata[4]; // Mix (CH12) |
|
- | 391 | } |
|
- | 392 | ||
- | 393 | s_excnt = 0; // Reset bitcounter |
|
- | 394 | s_exparity = 0; // Reset parity bit |
|
- | 395 | } |
|
- | 396 | ||
- | 397 | if (signal < 10) s_exdata[++s_excnt] = -125; // Bit = 0 -> value = -125 (min) |
|
- | 398 | if (s_excnt == 10) s_excnt = 0; // Overflow protection |
|
- | 399 | if (signal < -100) |
|
- | 400 | { |
|
- | 401 | s_exdata[s_excnt] = 125; // Bit = 1 -> value = 125 (max) |
|
- | 402 | s_exparity = ~s_exparity; // Bit = 1 -> Invert parity bit |
|
- | 403 | } |
|
365 | 404 | ||
366 | } |
405 | } |
367 | #endif |
406 | #endif |
Line 368... | Line 407... | ||
368 | if(SenderOkay >= 180) PPM_diff[index] = ((tmp - PPM_in[index]) / 3) * 3; |
407 | if(SenderOkay >= 180) PPM_diff[index] = ((tmp - PPM_in[index]) / 3) * 3; |
369 | else PPM_diff[index] = 0; |
408 | else PPM_diff[index] = 0; |
370 | 409 | ||
371 | #ifdef RECEIVER_SPEKTRUM_EXP |
410 | #ifdef RECEIVER_SPEKTRUM_DX7EXP |
- | 411 | if (index < 5 ) PPM_in[index] = tmp; // Update normal potis (CH1-4) |
|
- | 412 | else if (index == 5) PPM_in[7] = signal; // Gear (CH7) |
|
- | 413 | else if (index == 7) PPM_in[9] = signal; // Hover Throttle (CH9) |
|
- | 414 | #elif defined RECEIVER_SPEKTRUM_DX8EXP |
|
- | 415 | if (index < 5 ) PPM_in[index] = tmp; // Update normal potis (CH1-4) |
|
372 | if (index < 5 ) PPM_in[index] = tmp; // Update normal potis (CH1-4) |
416 | else if (index == 7) PPM_in[7] = signal; // R Trim (CH7) |
373 | else if (index == 5) PPM_in[7] = signal; // Gear (CH7) |
417 | else if (index == 5) PPM_in[8] = signal; // AUX2 (CH8) |
374 | else if (index == 7) PPM_in[9] = signal; // Hover Throttle (CH9) |
418 | else if (index == 8) PPM_in[11] = signal; // AUX3 (CH11) |
375 | #else |
419 | #else |
376 | PPM_in[index] = tmp; |
420 | PPM_in[index] = tmp; |
377 | #endif |
421 | #endif |
378 | } |
422 | } |
379 | else if(index > 17) ReSync = 1; // hier stimmt was nicht: neu synchronisieren |
423 | else if(index > 17) ReSync = 1; // hier stimmt was nicht: neu synchronisieren |
380 | } |
424 | } |
Line 403... | Line 447... | ||
403 | Sync = 0; |
447 | Sync = 0; |
404 | SpektrumTimer = MIN_FRAMEGAP; |
448 | SpektrumTimer = MIN_FRAMEGAP; |
405 | } |
449 | } |
406 | } |
450 | } |
407 | } |
451 | } |
- | 452 |