Subversion Repositories FlightCtrl

Rev

Rev 35 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 35 Rev 127
1
/*#######################################################################################
1
/*#######################################################################################
2
Decodieren eines RC Summen Signals
2
Decodieren eines RC Summen Signals
3
#######################################################################################*/
3
#######################################################################################*/
4
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
4
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
5
// + Copyright (c) 04.2007 Holger Buss
5
// + Copyright (c) 04.2007 Holger Buss
6
// + only for non-profit use
6
// + only for non-profit use
7
// + www.MikroKopter.com
7
// + www.MikroKopter.com
8
// + see the File "License.txt" for further Informations
8
// + see the File "License.txt" for further Informations
9
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
9
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
10
 
10
 
11
#include "rc.h"
11
#include "rc.h"
12
#include "main.h"
12
#include "main.h"
13
 
13
 
14
volatile int PPM_in[11];
14
volatile int PPM_in[15];
15
volatile int PPM_diff[11];  // das diffenzierte Stick-Signal
15
volatile int PPM_diff[15];  // das diffenzierte Stick-Signal
16
volatile unsigned char NewPpmData = 1;
16
volatile unsigned char NewPpmData = 1;
17
 
17
 
18
//############################################################################
18
//############################################################################
19
//zum decodieren des PPM-Signals wird Timer1 mit seiner Input
19
//zum decodieren des PPM-Signals wird Timer1 mit seiner Input
20
//Capture Funktion benutzt:
20
//Capture Funktion benutzt:
21
void rc_sum_init (void)
21
void rc_sum_init (void)
22
//############################################################################
22
//############################################################################
23
{
23
{
24
        TCCR1B=(1<<CS11)|(1<<CS10)|(1<<ICES1)|(1<<ICNC1);//|(1 << WGM12); //timer1 prescale 64
24
        TCCR1B=(1<<CS11)|(1<<CS10)|(1<<ICES1)|(1<<ICNC1);//|(1 << WGM12); //timer1 prescale 64
25
 
25
 
26
 
26
 
27
// PWM
27
// PWM
28
//TCCR1A = (1 << COM1B1) | (1 << WGM11) | (1 << WGM10);
28
//TCCR1A = (1 << COM1B1) | (1 << WGM11) | (1 << WGM10);
29
//TCCR1B |= (1 << WGM12);
29
//TCCR1B |= (1 << WGM12);
30
//OCR1B = 55;
30
//OCR1B = 55;
31
   
31
   
32
    TIMSK1 |= _BV(ICIE1);
32
    TIMSK1 |= _BV(ICIE1);
33
    AdNeutralGier = 0;
33
    AdNeutralGier = 0;
34
    AdNeutralRoll = 0;
34
    AdNeutralRoll = 0;
35
    AdNeutralNick = 0;
35
    AdNeutralNick = 0;
36
    return;
36
    return;
37
}
37
}
38
 
38
 
39
//############################################################################
39
//############################################################################
40
//Diese Routine startet und inizialisiert den Timer für RC
40
//Diese Routine startet und inizialisiert den Timer für RC
41
SIGNAL(SIG_INPUT_CAPTURE1)
41
SIGNAL(SIG_INPUT_CAPTURE1)
42
//############################################################################
42
//############################################################################
43
 
43
 
44
{
44
{
45
        static unsigned int AltICR=0;
45
        static unsigned int AltICR=0;
46
    signed int signal = 0;
46
    signed int signal = 0;
47
        static int index;              
47
        static int index;              
48
               
48
               
49
        signal = (unsigned int) ICR1 - AltICR;         
49
        signal = (unsigned int) ICR1 - AltICR;         
50
        AltICR = ICR1; 
50
        AltICR = ICR1; 
51
       
51
       
52
    //Syncronisationspause?
52
    //Syncronisationspause?
53
        if ((signal > 1500) && (signal < 8000))  
53
        if ((signal > 1000) && (signal < 5000))  
54
        {
54
        {
55
        index = 1;             
55
        index = 1;             
56
        NewPpmData = 0;  // Null bedeutet: Neue Daten
56
        NewPpmData = 0;  // Null bedeutet: Neue Daten
57
//        OCR2A = Poti2/2 + 80;
57
//        OCR2A = Poti2/2 + 80;
58
       
58
       
59
        }
59
        }
60
        else
60
        else
61
        {
61
        {
62
        if(index < 10)
62
        if(index < 14)
63
            {
63
            {
64
            if((signal > 250) && (signal < 687))
64
            if((signal > 250) && (signal < 687))
65
                {
65
            {
66
                signal -= 466;
66
                signal -= 466; // Stabiles Signal
-
 
67
               
67
                // Stabiles Signal
68
                if(abs(signal - PPM_in[index]) < 6)
-
 
69
                                {
68
                if(abs(signal - PPM_in[index]) < 6) { if(SenderOkay < 200) SenderOkay += 10;}
70
                                        if(SenderOkay < 200) SenderOkay += 10;
-
 
71
                                }
69
                signal = (3 * (PPM_in[index]) + signal) / 4;  
72
                signal = (3 * (PPM_in[index]) + signal) / 4;  
70
                //373 entspricht ca. 1.5ms also Mittelstellung
73
                //373 entspricht ca. 1.5ms also Mittelstellung
71
                PPM_diff[index] = signal - PPM_in[index];
74
                PPM_diff[index] = signal - PPM_in[index];
72
                PPM_in[index] = signal;
75
                PPM_in[index] = signal;
73
                }
76
            }
74
            index++;  
77
            index++;  
75
    /*     if(index == 5) PORTD |= 0x20; else PORTD &= ~0x20;  // Servosignal an J3 anlegen
-
 
76
         if(index == 6) PORTD |= 0x10; else PORTD &= ~0x10;  // Servosignal an J4 anlegen
-
 
77
         if(index == 7) PORTD |= 0x08; else PORTD &= ~0x08;  // Servosignal an J5 anlegen */
-
 
78
        }
78
        }
79
        }
79
        }
80
}
80
}
81
 
81
 
82
 
82
 
83
 
83
 
84
 
84
 
85
 
85
 
86
 
86