Subversion Repositories FlightCtrl

Rev

Rev 683 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 683 Rev 685
Line 1... Line 1...
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
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Line -... Line 10...
-
 
10
 
-
 
11
#include <avr/io.h>
-
 
12
#include <avr/interrupt.h>
10
 
13
 
11
#include "rc.h"
14
#include "rc.h"
Line 12... Line 15...
12
#include "main.h"
15
#include "fc.h"
13
 
16
 
14
volatile int PPM_in[11];
17
volatile int PPM_in[11];
Line 25... Line 28...
25
 
28
 
26
// PWM
29
// PWM
27
//TCCR1A = (1 << COM1B1) | (1 << WGM11) | (1 << WGM10);
30
//TCCR1A = (1 << COM1B1) | (1 << WGM11) | (1 << WGM10);
28
//TCCR1B |= (1 << WGM12);
31
//TCCR1B |= (1 << WGM12);
29
//OCR1B = 55;
32
//OCR1B = 55;
30
   
33
 
31
    TIMSK1 |= _BV(ICIE1);
34
    TIMSK1 |= _BV(ICIE1);
32
    AdNeutralGier = 0;
35
    AdNeutralGier = 0;
33
    AdNeutralRoll = 0;
36
    AdNeutralRoll = 0;
34
    AdNeutralNick = 0;
37
    AdNeutralNick = 0;
Line 41... Line 44...
41
//############################################################################
44
//############################################################################
Line 42... Line 45...
42
 
45
 
43
{
46
{
44
        static unsigned int AltICR=0;
47
        static unsigned int AltICR=0;
45
    signed int signal = 0,tmp;
48
    signed int signal = 0,tmp;
46
        static int index;              
49
        static int index;
47
               
50
 
48
        signal = (unsigned int) ICR1 - AltICR;         
51
        signal = (unsigned int) ICR1 - AltICR;
49
        AltICR = ICR1; 
52
        AltICR = ICR1;
50
       
53
 
51
    //Syncronisationspause?
54
    //Syncronisationspause?
52
//      if((signal > (int) Parameter_UserParam2 * 10) && (signal < 8000))        
55
//      if((signal > (int) Parameter_UserParam2 * 10) && (signal < 8000))
53
        if((signal > 1100) && (signal < 8000))   
56
        if((signal > 1100) && (signal < 8000))
54
        {
57
        {
55
        if(index >= 4)  NewPpmData = 0;  // Null bedeutet: Neue Daten
58
        if(index >= 4)  NewPpmData = 0;  // Null bedeutet: Neue Daten
56
        index = 1;             
59
        index = 1;
57
        }
60
        }
58
        else
61
        else
59
        {
62
        {
60
        if(index < 10)
63
        if(index < 10)
61
            {
64
            {
62
            if((signal > 250) && (signal < 687))
65
            if((signal > 250) && (signal < 687))
63
                {
66
                {
64
                signal -= 466;
67
                signal -= 466;
65
                // Stabiles Signal
68
                // Stabiles Signal
66
                if(abs(signal - PPM_in[index]) < 6) { if(SenderOkay < 200) SenderOkay += 10;}
69
                if(abs(signal - PPM_in[index]) < 6) { if(SenderOkay < 200) SenderOkay += 10;}
67
//                tmp = (7 * (PPM_in[index]) + signal) / 8;   
70
//                tmp = (7 * (PPM_in[index]) + signal) / 8;
68
                tmp = (3 * (PPM_in[index]) + signal) / 4;  
71
                tmp = (3 * (PPM_in[index]) + signal) / 4;
69
                if(tmp > signal+1) tmp--; else
72
                if(tmp > signal+1) tmp--; else
70
                if(tmp < signal-1) tmp++;
73
                if(tmp < signal-1) tmp++;
71
                if(SenderOkay >= 195)  PPM_diff[index] = ((tmp - PPM_in[index]) / 3) * 3;
74
                if(SenderOkay >= 195)  PPM_diff[index] = ((tmp - PPM_in[index]) / 3) * 3;
72
                else PPM_diff[index] = 0;
75
                else PPM_diff[index] = 0;
73
                PPM_in[index] = tmp;
76
                PPM_in[index] = tmp;
74
                }
77
                }
75
            index++;  
78
            index++;
76
         if(index == 5) PORTD |= 0x20; else PORTD &= ~0x20;  // Servosignal an J3 anlegen
79
         if(index == 5) PORTD |= 0x20; else PORTD &= ~0x20;  // Servosignal an J3 anlegen
77
         if(index == 6) PORTD |= 0x10; else PORTD &= ~0x10;  // Servosignal an J4 anlegen
80
         if(index == 6) PORTD |= 0x10; else PORTD &= ~0x10;  // Servosignal an J4 anlegen
78
         if(index == 7) PORTD |= 0x08; else PORTD &= ~0x08;  // Servosignal an J5 anlegen 
81
         if(index == 7) PORTD |= 0x08; else PORTD &= ~0x08;  // Servosignal an J5 anlegen
79
        }
82
        }
80
        }
83
        }