Subversion Repositories FlightCtrl

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
1 ingob 1
/*#######################################################################################
685 killagreg 2
Decodieren eines RC Summen Signals
1 ingob 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
 
687 killagreg 11
#include <stdlib.h>
685 killagreg 12
#include <avr/io.h>
13
#include <avr/interrupt.h>
14
 
1 ingob 15
#include "rc.h"
685 killagreg 16
#include "fc.h"
1 ingob 17
 
687 killagreg 18
volatile int16_t PPM_in[11];
19
volatile int16_t PPM_diff[11];  // das diffenzierte Stick-Signal
20
volatile uint8_t NewPpmData = 1;
1 ingob 21
 
687 killagreg 22
/***************************************************************/
23
/* zum decodieren des PPM-Signals wird Timer1 mit seiner Input */
24
/* Capture Funktion benutzt:                                   */
25
/***************************************************************/
26
 
1 ingob 27
void rc_sum_init (void)
28
{
29
        TCCR1B=(1<<CS11)|(1<<CS10)|(1<<ICES1)|(1<<ICNC1);//|(1 << WGM12); //timer1 prescale 64
30
 
31
// PWM
32
//TCCR1A = (1 << COM1B1) | (1 << WGM11) | (1 << WGM10);
33
//TCCR1B |= (1 << WGM12);
34
//OCR1B = 55;
685 killagreg 35
 
1 ingob 36
    TIMSK1 |= _BV(ICIE1);
37
    AdNeutralGier = 0;
38
    AdNeutralRoll = 0;
39
    AdNeutralNick = 0;
40
    return;
41
}
42
 
43
//############################################################################
44
//Diese Routine startet und inizialisiert den Timer für RC
45
SIGNAL(SIG_INPUT_CAPTURE1)
46
//############################################################################
47
 
48
{
49
        static unsigned int AltICR=0;
173 holgerb 50
    signed int signal = 0,tmp;
685 killagreg 51
        static int index;
52
 
53
        signal = (unsigned int) ICR1 - AltICR;
54
        AltICR = ICR1;
55
 
1 ingob 56
    //Syncronisationspause?
685 killagreg 57
//      if((signal > (int) Parameter_UserParam2 * 10) && (signal < 8000))
58
        if((signal > 1100) && (signal < 8000))
1 ingob 59
        {
513 hbuss 60
        if(index >= 4)  NewPpmData = 0;  // Null bedeutet: Neue Daten
685 killagreg 61
        index = 1;
62
        }
63
        else
1 ingob 64
        {
65
        if(index < 10)
66
            {
685 killagreg 67
            if((signal > 250) && (signal < 687))
68
                {
1 ingob 69
                signal -= 466;
70
                // Stabiles Signal
71
                if(abs(signal - PPM_in[index]) < 6) { if(SenderOkay < 200) SenderOkay += 10;}
685 killagreg 72
//                tmp = (7 * (PPM_in[index]) + signal) / 8;
73
                tmp = (3 * (PPM_in[index]) + signal) / 4;
604 hbuss 74
                if(tmp > signal+1) tmp--; else
685 killagreg 75
                if(tmp < signal-1) tmp++;
76
                if(SenderOkay >= 195)  PPM_diff[index] = ((tmp - PPM_in[index]) / 3) * 3;
604 hbuss 77
                else PPM_diff[index] = 0;
173 holgerb 78
                PPM_in[index] = tmp;
685 killagreg 79
                }
80
            index++;
173 holgerb 81
         if(index == 5) PORTD |= 0x20; else PORTD &= ~0x20;  // Servosignal an J3 anlegen
1 ingob 82
         if(index == 6) PORTD |= 0x10; else PORTD &= ~0x10;  // Servosignal an J4 anlegen
685 killagreg 83
         if(index == 7) PORTD |= 0x08; else PORTD &= ~0x08;  // Servosignal an J5 anlegen
1 ingob 84
        }
85
        }
86
}
87
 
88
 
89
 
90
 
91