Subversion Repositories FlightCtrl

Rev

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

Rev 1224 Rev 1268
Line 11... Line 11...
11
#include "rc.h"
11
#include "rc.h"
12
#include "main.h"
12
#include "main.h"
Line 13... Line 13...
13
 
13
 
14
volatile int PPM_in[11];
14
volatile int PPM_in[11];
-
 
15
volatile int PPM_diff[11];  // das diffenzierte Stick-Signal
15
volatile int PPM_diff[11];  // das diffenzierte Stick-Signal
16
volatile char Channels,tmpChannels = 0;
Line 16... Line 17...
16
volatile unsigned char NewPpmData = 1;
17
volatile unsigned char NewPpmData = 1;
17
 
18
 
18
//############################################################################
19
//############################################################################
Line 35... Line 36...
35
SIGNAL(SIG_INPUT_CAPTURE1)
36
SIGNAL(SIG_INPUT_CAPTURE1)
36
//############################################################################
37
//############################################################################
Line 37... Line 38...
37
 
38
 
38
{
39
{
-
 
40
        static unsigned int AltICR=0;
-
 
41
    static int ppm_in[11];
-
 
42
    static int ppm_diff[11];  
-
 
43
    static int old_ppm_in[11];
39
        static unsigned int AltICR=0;
44
    static int old_ppm_diff[11];  
40
    signed int signal = 0,tmp;
45
    signed int signal = 0,tmp;
41
        static int index;              
-
 
42
               
46
        static unsigned char index, okay_cnt = 0;              
43
        signal = (unsigned int) ICR1 - AltICR;         
47
        signal = (unsigned int) ICR1 - AltICR;         
44
        AltICR = ICR1; 
48
        AltICR = ICR1; 
45
    //Syncronisationspause?
49
    //Syncronisationspause?
46
        if((signal > 1100) && (signal < 8000))   
50
        if((signal > 1100) && (signal < 8000))   
-
 
51
        {
-
 
52
        tmpChannels = index;
-
 
53
        if(tmpChannels >= 4 && Channels == tmpChannels)  
-
 
54
                 {
-
 
55
          if(okay_cnt > 5)
47
        {
56
                   {
-
 
57
                   NewPpmData = 0;  // Null bedeutet: Neue Daten
-
 
58
                   for(index = 0; index < 11; index++)
-
 
59
                    {
-
 
60
                         if(okay_cnt > 30)
-
 
61
                          {
-
 
62
                           old_ppm_in[index] = PPM_in[index];
-
 
63
                           old_ppm_diff[index] = PPM_diff[index];
-
 
64
                          }
-
 
65
                     PPM_in[index] = ppm_in[index];
-
 
66
                     PPM_diff[index] = ppm_diff[index];
-
 
67
                    }
-
 
68
                   }
-
 
69
          if(okay_cnt < 255) okay_cnt++;
-
 
70
                 }
48
        if(index >= 4)  NewPpmData = 0;  // Null bedeutet: Neue Daten
71
         else okay_cnt = 0;
-
 
72
        index = 1;             
49
        index = 1;             
73
        if(!MotorenEin) Channels = tmpChannels;
50
        }
74
        }
51
        else
75
        else
52
        {
76
        {
53
        if(index < 10)
77
        if(index < 10)
54
            {
78
            {
55
            if((signal > 250) && (signal < 687))
79
            if((signal > 250) && (signal < 687))
56
                {
80
                {
57
                signal -= 466;
81
                signal -= 466;
58
                // Stabiles Signal
82
                // Stabiles Signal
59
                if(abs(signal - PPM_in[index]) < 6) { if(SenderOkay < 200) SenderOkay += 10; else SenderOkay = 200;}
83
                if((abs(signal - ppm_in[index]) < 6) && okay_cnt > 30) { if(SenderOkay < 200) SenderOkay += 5; else SenderOkay = 200;}
60
                tmp = (3 * (PPM_in[index]) + signal) / 4;  
84
                tmp = (3 * (ppm_in[index]) + signal) / 4;  
61
                if(tmp > signal+1) tmp--; else
85
                if(tmp > signal+1) tmp--; else
62
                if(tmp < signal-1) tmp++;
86
                if(tmp < signal-1) tmp++;
63
                if(SenderOkay >= 195)  PPM_diff[index] = ((tmp - PPM_in[index]) / 3) * 3;
87
                if(SenderOkay >= 190)  ppm_diff[index] = ((tmp - ppm_in[index]) / 3) * 3;
64
                else PPM_diff[index] = 0;
88
                else ppm_diff[index] = 0;
65
                PPM_in[index] = tmp;
89
                ppm_in[index] = tmp;
66
                }
90
                }
67
            index++;  
91
                        else ROT_ON;
68
         if(index == 5) J3High; else J3Low;  // Servosignal an J3 anlegen
92
            if(index == 5) J3High; else J3Low;  // Servosignal an J3 anlegen
69
         if(index == 6) J4High; else J4Low;  // Servosignal an J4 anlegen
93
            if(index == 6) J4High; else J4Low;  // Servosignal an J4 anlegen
70
         if(index == 7) J5High; else J5Low;  // Servosignal an J5 anlegen 
94
            if(index == 7) J5High; else J5Low;  // Servosignal an J5 anlegen 
-
 
95
          }
-
 
96
                  else ROT_ON;
-
 
97
                  if(index < 20) index++;
-
 
98
                  else
-
 
99
                  {
-
 
100
                   unsigned char i;
-
 
101
            for(i=0;i<11;i++) // restore from older data
-
 
102
                         {
-
 
103
                      PPM_in[i] = old_ppm_in[index];
-
 
104
                      PPM_diff[index] = 0;
-
 
105
                          okay_cnt = 0;
71
        }
106
                 }
-
 
107
                  }
-
 
108
            }
72
        }
109
DebugOut.Analog[16] = okay_cnt;
Line 73... Line 110...
73
}
110
}
74
 
111
 
75
/*
112
/*