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