Subversion Repositories FlightCtrl

Rev

Rev 1226 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
1 ingob 1
/*#######################################################################################
2
Decodieren eines RC Summen Signals
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
 
11
#include "rc.h"
12
#include "main.h"
13
 
14
volatile int PPM_in[11];
15
volatile int PPM_diff[11];  // das diffenzierte Stick-Signal
16
volatile unsigned char NewPpmData = 1;
17
 
18
//############################################################################
19
//zum decodieren des PPM-Signals wird Timer1 mit seiner Input
20
//Capture Funktion benutzt:
21
void rc_sum_init (void)
22
//############################################################################
23
{
24
        TCCR1B=(1<<CS11)|(1<<CS10)|(1<<ICES1)|(1<<ICNC1);//|(1 << WGM12); //timer1 prescale 64
1171 hbuss 25
//      TCCR1B=(1<<CS11)|(0<<CS10)|(1<<ICES1)|(1<<ICNC1); //timer1 prescale 64
1 ingob 26
    TIMSK1 |= _BV(ICIE1);
27
    AdNeutralGier = 0;
28
    AdNeutralRoll = 0;
29
    AdNeutralNick = 0;
30
    return;
31
}
32
 
33
//############################################################################
34
//Diese Routine startet und inizialisiert den Timer für RC
35
SIGNAL(SIG_INPUT_CAPTURE1)
36
//############################################################################
37
 
38
{
39
        static unsigned int AltICR=0;
173 holgerb 40
    signed int signal = 0,tmp;
1 ingob 41
        static int index;              
42
 
43
        signal = (unsigned int) ICR1 - AltICR;         
44
        AltICR = ICR1; 
45
    //Syncronisationspause?
513 hbuss 46
        if((signal > 1100) && (signal < 8000))   
1 ingob 47
        {
513 hbuss 48
        if(index >= 4)  NewPpmData = 0;  // Null bedeutet: Neue Daten
1 ingob 49
        index = 1;             
50
        }
51
        else
52
        {
53
        if(index < 10)
54
            {
55
            if((signal > 250) && (signal < 687))
56
                {
57
                signal -= 466;
58
                // Stabiles Signal
1172 hbuss 59
                if(abs(signal - PPM_in[index]) < 6) { if(SenderOkay < 200) SenderOkay += 10; else SenderOkay = 200;}
614 hbuss 60
                tmp = (3 * (PPM_in[index]) + signal) / 4;  
604 hbuss 61
                if(tmp > signal+1) tmp--; else
62
                if(tmp < signal-1) tmp++;
1286 MartinR 63
                                //if(SenderOkay >= 195)  PPM_diff[index] = ((tmp - PPM_in[index]) / 3) * 3; // MartinR: so war es
64
                                if(SenderOkay >= 195)  PPM_diff[index] = (tmp - PPM_in[index]); // MartinR: Optimiert
604 hbuss 65
                else PPM_diff[index] = 0;
173 holgerb 66
                PPM_in[index] = tmp;
1 ingob 67
                }
68
            index++;  
1224 hbuss 69
         if(index == 5) J3High; else J3Low;  // Servosignal an J3 anlegen
70
         if(index == 6) J4High; else J4Low;  // Servosignal an J4 anlegen
71
         if(index == 7) J5High; else J5Low;  // Servosignal an J5 anlegen 
1171 hbuss 72
        }
73
        }
74
}
75
 
76
/*
77
//############################################################################
78
//Diese Routine startet und inizialisiert den Timer für RC
79
SIGNAL(SIG_INPUT_CAPTURE1)
80
//############################################################################
81
 
82
{
83
        static unsigned int AltICR=0;
84
    signed int signal = 0,tmp;
85
        static int index;              
86
 
87
        signal = (unsigned int) ICR1 - AltICR;         
88
DebugOut.Analog[16] = signal;
89
        signal /= 2;
90
        AltICR = ICR1; 
91
    //Syncronisationspause?
92
        if((signal > 1100*2) && (signal < 8000*2))       
93
        {
94
        if(index >= 4)  NewPpmData = 0;  // Null bedeutet: Neue Daten
95
        index = 1;             
96
        }
97
        else
98
        {
99
        if(index < 10)
100
            {
101
            if((signal > 250) && (signal < 687*2))
102
                {
103
                signal -= 962;
104
                // Stabiles Signal
105
                if(abs(signal - PPM_in[index]) < 6) { if(SenderOkay < 200) SenderOkay += 10;}
106
                tmp = (3 * (PPM_in[index]) + signal) / 4;  
107
                if(tmp > signal+1) tmp--; else
108
                if(tmp < signal-1) tmp++;
109
                if(SenderOkay >= 195)  PPM_diff[index] = ((tmp - PPM_in[index]) / 3) * 3;
110
                else PPM_diff[index] = 0;
111
                PPM_in[index] = tmp;
112
                }
113
            index++;  
1155 hbuss 114
         if(index == 5) J3High; else J3Low;  // Servosignal an J3 anlegen
1171 hbuss 115
         if(index == 2) J4High; else J4Low;  // Servosignal an J4 anlegen
1155 hbuss 116
         if(index == 7) J5High; else J5Low;  // Servosignal an J5 anlegen
1 ingob 117
        }
118
        }
119
}
1171 hbuss 120
*/
1 ingob 121
 
122
 
123