Subversion Repositories FlightCtrl

Rev

Rev 1812 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
1819 - 1
/******************************************************************************************************************
2
V0.82b-Arthur-P 2010-12-18
3
------------------------------------------------------------------------------------------------------------------
4
Version includes only support for external HEF4017 for FC1.x hardware, NOT for Twi2Ppm converters for ESCs.
5
 
6
2010-12-18 Chanded the if(Platinenversion < 20) statement within this file to correctly identify external HEF4017.
7
Arthur P. Modified to use several parameters for servo control:
8
User_Parameter4:
9
User_Parameter5:
10
User_Parameter6:
11
User_Parameter7:
12
User_Parameter8: Use external HEF4017 if bit 8 is set (>127). The remaining 7 bits are used
13
                 for the shutter cycle counter: the value is multiplied by 5 programmatically,
14
                                 resulting in steps of approx. 0.1sec. Minimum value to start using the
15
                                 interval timer is 10 (approx. 1 sec, or countervalue of 50). Note that this
16
                                 was originally done through user para 6.
17
******************************************************************************************************************/
1 ingob 18
/*#######################################################################################
1561 killagreg 19
Decodieren eines RC Summen Signals
1 ingob 20
#######################################################################################*/
21
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1338 ingob 22
// + Copyright (c) Holger Buss, Ingo Busker
1 ingob 23
// + only for non-profit use
24
// + www.MikroKopter.com
1356 hbuss 25
// + porting the sources to other systems or using the software on other systems (except hardware from www.mikrokopter.de) is not allowed
1 ingob 26
// + see the File "License.txt" for further Informations
27
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
28
 
29
#include "rc.h"
30
#include "main.h"
1638 holgerb 31
// Achtung: ACT_S3D_SUMMENSIGNAL wird in der Main.h gesetzt
1 ingob 32
 
1377 hbuss 33
volatile int PPM_in[26];
34
volatile int PPM_diff[26];  // das diffenzierte Stick-Signal
1268 hbuss 35
volatile char Channels,tmpChannels = 0;
1 ingob 36
volatile unsigned char NewPpmData = 1;
37
 
38
//############################################################################
39
//zum decodieren des PPM-Signals wird Timer1 mit seiner Input
40
//Capture Funktion benutzt:
41
void rc_sum_init (void)
42
//############################################################################
43
{
1377 hbuss 44
 unsigned char i;
45
 for(i=0;i<26;i++)
46
  {
47
   PPM_in[i] = 0;
48
   PPM_diff[i] = 0;
49
  }
1438 ingob 50
 
1 ingob 51
    AdNeutralGier = 0;
52
    AdNeutralRoll = 0;
53
    AdNeutralNick = 0;
54
    return;
55
}
1309 hbuss 56
 
1356 hbuss 57
#ifndef ACT_S3D_SUMMENSIGNAL
1278 hbuss 58
//############################################################################
59
//Diese Routine startet und inizialisiert den Timer für RC
1561 killagreg 60
ISR(TIMER1_CAPT_vect)
1278 hbuss 61
//############################################################################
62
{
1309 hbuss 63
if(!(EE_Parameter.ExtraConfig & CFG_SENSITIVE_RC))
64
 {
1278 hbuss 65
        static unsigned int AltICR=0;
66
    signed int signal = 0,tmp;
1561 killagreg 67
        static int index;
68
 
69
        signal = (unsigned int) ICR1 - AltICR;
70
        AltICR = ICR1;
1283 hbuss 71
    //Syncronisationspause? (3.52 ms < signal < 25.6 ms)
1561 killagreg 72
        if((signal > 1100) && (signal < 8000))
1278 hbuss 73
        {
1320 hbuss 74
        Channels = index;
1278 hbuss 75
        if(index >= 4)  NewPpmData = 0;  // Null bedeutet: Neue Daten
1561 killagreg 76
        index = 1;
77
        }
78
        else
1278 hbuss 79
        {
1377 hbuss 80
        if(index < 13)
1278 hbuss 81
            {
1561 killagreg 82
            if((signal > 250) && (signal < 687))
83
                {
1278 hbuss 84
                signal -= 466;
85
                // Stabiles Signal
86
                if(abs(signal - PPM_in[index]) < 6) { if(SenderOkay < 200) SenderOkay += 10; else SenderOkay = 200;}
1561 killagreg 87
                tmp = (3 * (PPM_in[index]) + signal) / 4;
1278 hbuss 88
                if(tmp > signal+1) tmp--; else
1561 killagreg 89
                if(tmp < signal-1) tmp++;
90
                if(SenderOkay >= 195)  PPM_diff[index] = ((tmp - PPM_in[index]) / 3) * 3;
1278 hbuss 91
                else PPM_diff[index] = 0;
92
                PPM_in[index] = tmp;
1561 killagreg 93
                }
94
            index++;
1819 - 95
/******************************************************************************************************************
96
Arthur P: Modified the code to check the value of parameter 8. If 128 or higher then a HEF4017 is
97
expected and will be used. Else J7 and J9 are seen as separate normal outputs.
98
if((PlatinenVersion < 20)
99
20100802 Inserted changes into v.0.82b code.
100
******************************************************************************************************************/    
101
 
102
//      if(PlatinenVersion < 20)
103
 
104
        if((PlatinenVersion < 20) && (Parameter_UserParam8 < 128 ))
105
/******************************************************************************************************************
106
Arthur P: End of modification ot if statement. 
107
******************************************************************************************************************/    
1639 holgerb 108
            {  
109
             if(index == 5) J3High; else J3Low;  // Servosignal an J3 anlegen
110
             if(index == 6) J4High; else J4Low;  // Servosignal an J4 anlegen
111
             if(index == 7) J5High; else J5Low;  // Servosignal an J5 anlegen
112
                        }
1278 hbuss 113
        }
114
        }
1309 hbuss 115
 }
1561 killagreg 116
 else
1309 hbuss 117
 {
1 ingob 118
        static unsigned int AltICR=0;
1377 hbuss 119
    static int ppm_in[13];
1561 killagreg 120
    static int ppm_diff[13];
1377 hbuss 121
    static int old_ppm_in[13];
1561 killagreg 122
    static int old_ppm_diff[13];
173 holgerb 123
    signed int signal = 0,tmp;
1561 killagreg 124
        static unsigned char index, okay_cnt = 0;
125
        signal = (unsigned int) ICR1 - AltICR;
126
        AltICR = ICR1;
1283 hbuss 127
    //Syncronisationspause? (3.52 ms < signal < 25.6 ms)
1561 killagreg 128
        if((signal > 1100) && (signal < 8000))
1 ingob 129
        {
1268 hbuss 130
        tmpChannels = index;
1561 killagreg 131
        if(tmpChannels >= 4 && Channels == tmpChannels)
1268 hbuss 132
                 {
1276 hbuss 133
          if(okay_cnt > 10)
1268 hbuss 134
                   {
135
                   NewPpmData = 0;  // Null bedeutet: Neue Daten
1377 hbuss 136
                   for(index = 0; index < 13; index++)
1268 hbuss 137
                    {
1561 killagreg 138
                         if(okay_cnt > 30)
1268 hbuss 139
                          {
140
                           old_ppm_in[index] = PPM_in[index];
141
                           old_ppm_diff[index] = PPM_diff[index];
1561 killagreg 142
                          }
1268 hbuss 143
                     PPM_in[index] = ppm_in[index];
144
                     PPM_diff[index] = ppm_diff[index];
145
                    }
146
                   }
147
          if(okay_cnt < 255) okay_cnt++;
148
                 }
1561 killagreg 149
         else
1278 hbuss 150
                  {
151
                   if(okay_cnt > 100) okay_cnt = 10; else okay_cnt = 0;
152
                   ROT_ON;
153
                  }
1561 killagreg 154
        index = 1;
1268 hbuss 155
        if(!MotorenEin) Channels = tmpChannels;
1561 killagreg 156
        }
157
        else
1 ingob 158
        {
1377 hbuss 159
        if(index < 13)
1 ingob 160
            {
1561 killagreg 161
            if((signal > 250) && (signal < 687))
162
                {
1 ingob 163
                signal -= 466;
164
                // Stabiles Signal
1271 hbuss 165
                if((abs(signal - ppm_in[index]) < 6))
166
                                 {
1276 hbuss 167
                                  if(okay_cnt > 25)  SenderOkay += 10;
1561 killagreg 168
                                  else
169
                                  if(okay_cnt > 10)  SenderOkay += 2;
1276 hbuss 170
                                  if(SenderOkay > 200) SenderOkay = 200;
1271 hbuss 171
                                 }
1561 killagreg 172
                tmp = (3 * (ppm_in[index]) + signal) / 4;
604 hbuss 173
                if(tmp > signal+1) tmp--; else
1561 killagreg 174
                if(tmp < signal-1) tmp++;
175
                if(SenderOkay >= 190)  ppm_diff[index] = ((tmp - ppm_in[index]) / 3) * 3;
1268 hbuss 176
                else ppm_diff[index] = 0;
177
                ppm_in[index] = tmp;
1561 killagreg 178
                }
1268 hbuss 179
                        else ROT_ON;
1819 - 180
/******************************************************************************************************************
181
Arthur P: Modified the code to check the value of parameter 8. If 128 or higher then a HEF4017 is
182
expected and will be used. Else J7 and J9 are seen as separate normal outputs.
183
if((PlatinenVersion < 20)
184
20100802 Inserted changes into v.0.82b code.
185
******************************************************************************************************************/    
186
 
187
//      if(PlatinenVersion < 20)
188
 
189
        if((PlatinenVersion < 20) && (Parameter_UserParam8 < 128 ))
190
/******************************************************************************************************************
191
Arthur P: End of modification ot if statement. 
192
******************************************************************************************************************/    
1639 holgerb 193
            {  
194
             if(index == 5) J3High; else J3Low;  // Servosignal an J3 anlegen
195
             if(index == 6) J4High; else J4Low;  // Servosignal an J4 anlegen
196
             if(index == 7) J5High; else J5Low;  // Servosignal an J5 anlegen
197
                        }
1268 hbuss 198
          }
1561 killagreg 199
                  if(index < 20) index++;
1276 hbuss 200
          else
1561 killagreg 201
                  if(index == 20)
1268 hbuss 202
                  {
1276 hbuss 203
            unsigned char i;
1278 hbuss 204
            ROT_ON;
1276 hbuss 205
                    index = 30;
1377 hbuss 206
            for(i=0;i<13;i++) // restore from older data
1268 hbuss 207
                         {
1276 hbuss 208
                      PPM_in[i] = old_ppm_in[i];
209
                      PPM_diff[i] = 0;
210
//                        okay_cnt /= 2;
1268 hbuss 211
                 }
212
                  }
213
            }
1309 hbuss 214
 }
1171 hbuss 215
}
216
 
1561 killagreg 217
#else
1171 hbuss 218
//############################################################################
219
//Diese Routine startet und inizialisiert den Timer für RC
1561 killagreg 220
ISR(TIMER1_CAPT_vect)
1171 hbuss 221
//############################################################################
222
 
223
{
224
        static unsigned int AltICR=0;
225
    signed int signal = 0,tmp;
1561 killagreg 226
        static int index;
227
 
228
        signal = (unsigned int) ICR1 - AltICR;
1171 hbuss 229
        signal /= 2;
1561 killagreg 230
        AltICR = ICR1;
1171 hbuss 231
    //Syncronisationspause?
1561 killagreg 232
        if((signal > 1100*2) && (signal < 8000*2))
1171 hbuss 233
        {
234
        if(index >= 4)  NewPpmData = 0;  // Null bedeutet: Neue Daten
1561 killagreg 235
        index = 1;
236
        }
237
        else
1171 hbuss 238
        {
1377 hbuss 239
        if(index < 13)
1171 hbuss 240
            {
1561 killagreg 241
            if((signal > 250) && (signal < 687*2))
242
                {
1171 hbuss 243
                signal -= 962;
244
                // Stabiles Signal
245
                if(abs(signal - PPM_in[index]) < 6) { if(SenderOkay < 200) SenderOkay += 10;}
1561 killagreg 246
                tmp = (3 * (PPM_in[index]) + signal) / 4;
1171 hbuss 247
                if(tmp > signal+1) tmp--; else
1561 killagreg 248
                if(tmp < signal-1) tmp++;
249
                if(SenderOkay >= 195)  PPM_diff[index] = ((tmp - PPM_in[index]) / 3) * 3;
1171 hbuss 250
                else PPM_diff[index] = 0;
251
                PPM_in[index] = tmp;
1561 killagreg 252
                }
253
            index++;
1 ingob 254
        }
255
        }
256
}
1356 hbuss 257
#endif
1 ingob 258