Subversion Repositories FlightCtrl

Rev

Go to most recent revision | Details | 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
25
    TIMSK1 |= _BV(ICIE1);
26
    AdNeutralGier = 0;
27
    AdNeutralRoll = 0;
28
    AdNeutralNick = 0;
29
    return;
30
}
31
 
32
//############################################################################
33
//Diese Routine startet und inizialisiert den Timer für RC
34
SIGNAL(SIG_INPUT_CAPTURE1)
35
//############################################################################
36
 
37
{
38
        static unsigned int AltICR=0;
173 holgerb 39
    signed int signal = 0,tmp;
1 ingob 40
        static int index;              
41
 
42
        signal = (unsigned int) ICR1 - AltICR;         
43
        AltICR = ICR1; 
44
    //Syncronisationspause?
513 hbuss 45
        if((signal > 1100) && (signal < 8000))   
1 ingob 46
        {
513 hbuss 47
        if(index >= 4)  NewPpmData = 0;  // Null bedeutet: Neue Daten
1 ingob 48
        index = 1;             
49
        }
50
        else
51
        {
52
        if(index < 10)
53
            {
54
            if((signal > 250) && (signal < 687))
55
                {
56
                signal -= 466;
57
                // Stabiles Signal
58
                if(abs(signal - PPM_in[index]) < 6) { if(SenderOkay < 200) SenderOkay += 10;}
614 hbuss 59
                tmp = (3 * (PPM_in[index]) + signal) / 4;  
604 hbuss 60
                if(tmp > signal+1) tmp--; else
61
                if(tmp < signal-1) tmp++;
62
                if(SenderOkay >= 195)  PPM_diff[index] = ((tmp - PPM_in[index]) / 3) * 3;
63
                else PPM_diff[index] = 0;
173 holgerb 64
                PPM_in[index] = tmp;
1 ingob 65
                }
66
            index++;  
1155 hbuss 67
         if(index == 5) J3High; else J3Low;  // Servosignal an J3 anlegen
68
         if(index == 6) J4High; else J4Low;  // Servosignal an J4 anlegen
69
         if(index == 7) J5High; else J5Low;  // Servosignal an J5 anlegen 
1 ingob 70
        }
71
        }
72
}
73
 
74
 
75
 
76
 
77