Subversion Repositories FlightCtrl

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
787 Nick666 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
{
857 Nick666 24
        TCCR1B=(1<<CS11)|(1<<CS10)|(1<<ICES1)|(1<<ICNC1);//|(1 << WGM12); //timer1 prescale 64    
787 Nick666 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;
39
    signed int signal = 0,tmp;
40
        static int index;              
41
 
42
        signal = (unsigned int) ICR1 - AltICR;         
43
        AltICR = ICR1; 
44
 
45
    //Syncronisationspause?
46
//      if((signal > (int) Parameter_UserParam2 * 10) && (signal < 8000))        
47
        if((signal > 1100) && (signal < 8000))   
48
        {
49
        if(index >= 4)  NewPpmData = 0;  // Null bedeutet: Neue Daten
50
        index = 1;             
51
        }
52
        else
53
        {
54
        if(index < 10)
55
            {
56
            if((signal > 250) && (signal < 687))
57
                {
58
                signal -= 466;
59
                // Stabiles Signal
857 Nick666 60
                if(abs(signal - PPM_in[index]) < 6) {if(SenderOkay < 200) SenderOkay += 10;}  
787 Nick666 61
                tmp = (3 * (PPM_in[index]) + signal) / 4;  
62
                if(tmp > signal+1) tmp--; else
63
                if(tmp < signal-1) tmp++;
64
                if(SenderOkay >= 195)  PPM_diff[index] = ((tmp - PPM_in[index]) / 3) * 3;
65
                else PPM_diff[index] = 0;
66
                PPM_in[index] = tmp;
857 Nick666 67
                }
68
            index++;
787 Nick666 69
         //if(index == 5) PORTD |= 0x20; else PORTD &= ~0x20;  // Servosignal an J3 anlegen
70
         //if(index == 6) PORTD |= 0x10; else PORTD &= ~0x10;  // Servosignal an J4 anlegen
71
         //if(index == 7) PORTD |= 0x08; else PORTD &= ~0x08;  // Servosignal an J5 anlegen 
72
        }
73
        }
74
}
75
 
76
 
77
 
78
 
79