Subversion Repositories FlightCtrl

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
1 ingob 1
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2
// + www.MikroKopter.com
3
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2050 holgerb 4
// + Software Nutzungsbedingungen (english version: see below)
5
// + der Fa. HiSystems GmbH, Flachsmeerstrasse 2, 26802 Moormerland - nachfolgend Lizenzgeber genannt -
6
// + Der Lizenzgeber räumt dem Kunden ein nicht-ausschließliches, zeitlich und räumlich* unbeschränktes Recht ein, die im den
7
// + Mikrocontroller verwendete Firmware für die Hardware Flight-Ctrl, Navi-Ctrl, BL-Ctrl, MK3Mag & PC-Programm MikroKopter-Tool 
8
// + - nachfolgend Software genannt - nur für private Zwecke zu nutzen.
9
// + Der Einsatz dieser Software ist nur auf oder mit Produkten des Lizenzgebers zulässig.
1 ingob 10
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2050 holgerb 11
// + Die vom Lizenzgeber gelieferte Software ist urheberrechtlich geschützt. Alle Rechte an der Software sowie an sonstigen im
12
// + Rahmen der Vertragsanbahnung und Vertragsdurchführung überlassenen Unterlagen stehen im Verhältnis der Vertragspartner ausschließlich dem Lizenzgeber zu.
13
// + Die in der Software enthaltenen Copyright-Vermerke, Markenzeichen, andere Rechtsvorbehalte, Seriennummern sowie
14
// + sonstige der Programmidentifikation dienenden Merkmale dürfen vom Kunden nicht verändert oder unkenntlich gemacht werden.
15
// + Der Kunde trifft angemessene Vorkehrungen für den sicheren Einsatz der Software. Er wird die Software gründlich auf deren
16
// + Verwendbarkeit zu dem von ihm beabsichtigten Zweck testen, bevor er diese operativ einsetzt.
17
// + Die Haftung des Lizenzgebers wird - soweit gesetzlich zulässig - begrenzt in Höhe des typischen und vorhersehbaren
18
// + Schadens. Die gesetzliche Haftung bei Personenschäden und nach dem Produkthaftungsgesetz bleibt unberührt. Dem Lizenzgeber steht jedoch der Einwand 
19
// + des Mitverschuldens offen.
20
// + Der Kunde trifft angemessene Vorkehrungen für den Fall, dass die Software ganz oder teilweise nicht ordnungsgemäß arbeitet.
21
// + Er wird die Software gründlich auf deren Verwendbarkeit zu dem von ihm beabsichtigten Zweck testen, bevor er diese operativ einsetzt.
22
// + Der Kunde wird er seine Daten vor Einsatz der Software nach dem Stand der Technik sichern.
23
// + Der Kunde ist darüber unterrichtet, dass der Lizenzgeber seine Daten im zur Vertragsdurchführung erforderlichen Umfang
24
// + und auf Grundlage der Datenschutzvorschriften erhebt, speichert, verarbeitet und, sofern notwendig, an Dritte übermittelt.
25
// + *) Die räumliche Nutzung bezieht sich nur auf den Einsatzort, nicht auf die Reichweite der programmierten Software.
26
// + #### ENDE DER NUTZUNGSBEDINGUNGEN ####'
27
// +  Hinweis: Informationen über erweiterte Nutzungsrechte (wie z.B. Nutzung für nicht-private Zwecke) sind auf Anfrage per Email an info(@)hisystems.de verfügbar.
1 ingob 28
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2050 holgerb 29
// + Software LICENSING TERMS
1 ingob 30
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2050 holgerb 31
// + of HiSystems GmbH, Flachsmeerstrasse 2, 26802 Moormerland, Germany - the Licensor -
32
// + The Licensor grants the customer a non-exclusive license to use the microcontroller firmware of the Flight-Ctrl, Navi-Ctrl, BL-Ctrl, and MK3Mag hardware 
33
// + (the Software) exclusively for private purposes. The License is unrestricted with respect to time and territory*.
34
// + The Software may only be used with the Licensor's products.
35
// + The Software provided by the Licensor is protected by copyright. With respect to the relationship between the parties to this
36
// + agreement, all rights pertaining to the Software and other documents provided during the preparation and execution of this
37
// + agreement shall be the property of the Licensor.
38
// + The information contained in the Software copyright notices, trademarks, other legal reservations, serial numbers and other
39
// + features that can be used to identify the program may not be altered or defaced by the customer.
40
// + The customer shall be responsible for taking reasonable precautions
41
// + for the safe use of the Software. The customer shall test the Software thoroughly regarding its suitability for the
42
// + intended purpose before implementing it for actual operation. The Licensor's liability shall be limited to the extent of typical and
43
// + foreseeable damage to the extent permitted by law, notwithstanding statutory liability for bodily injury and product
44
// + liability. However, the Licensor shall be entitled to the defense of contributory negligence.
45
// + The customer will take adequate precautions in the case, that the software is not working properly. The customer will test
46
// + the software for his purpose before any operational usage. The customer will backup his data before using the software.
47
// + The customer understands that the Licensor collects, stores and processes, and, where required, forwards, customer data
48
// + to third parties to the extent necessary for executing the agreement, subject to applicable data protection and privacy regulations.
49
// + *) The territory aspect only refers to the place where the Software is used, not its programmed range.
50
// + #### END OF LICENSING TERMS ####
51
// + Note: For information on license extensions (e.g. commercial use), please contact us at info(@)hisystems.de.
1 ingob 52
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
53
#include "main.h"
1913 holgerb 54
unsigned char DisableRcOffBeeping = 0;
173 holgerb 55
unsigned char PlatinenVersion = 10;
1232 hbuss 56
unsigned char BattLowVoltageWarning = 94;
2416 holgerb 57
unsigned char BattAutoLandingVoltage = 0, BattComingHomeVoltage = 0;
1298 hbuss 58
unsigned int FlugMinuten = 0,FlugMinutenGesamt = 0;
1512 holgerb 59
unsigned int FlugSekunden = 0;
1444 ingob 60
pVoidFnct_pVoidFnctChar_const_fmt _printf_P;
1702 holgerb 61
unsigned char FoundMotors = 0;
1834 holgerb 62
unsigned char JetiBeep = 0; // to allow any Morse-Beeping of the Jeti-Box
2333 holgerb 63
unsigned char ActiveParamSet = 3;
2402 holgerb 64
unsigned char LipoCells = 4;
2418 holgerb 65
unsigned char RedundanceBlOperation = 0;
1444 ingob 66
 
2030 holgerb 67
void PrintLine(void)
68
{
69
 printf("\n\r===================================");
70
}
71
 
72
 
819 hbuss 73
void CalMk3Mag(void)
74
{
75
 static unsigned char stick = 1;
76
 if(PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] > -20) stick = 0;
77
 if((PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] < -70) && !stick)
78
  {
79
   stick = 1;
80
   WinkelOut.CalcState++;
1051 killagreg 81
   if(WinkelOut.CalcState > 4)
82
    {
819 hbuss 83
//     WinkelOut.CalcState = 0; // in Uart.c
84
     beeptime = 1000;
1051 killagreg 85
    }
1232 hbuss 86
   else Piep(WinkelOut.CalcState,150);
819 hbuss 87
  }
88
}
89
 
1438 ingob 90
 
1268 hbuss 91
void LipoDetection(unsigned char print)
92
{
2407 holgerb 93
        #define MAX_CELL_VOLTAGE 43 // max cell voltage for LiPO
2408 holgerb 94
        if(print)
95
         {
96
          printf("\n\rBatt:");
97
          LipoCells = 1 + UBat / MAX_CELL_VOLTAGE;
2416 holgerb 98
          if(LipoCells > 6) LipoCells = 6;
2408 holgerb 99
         }
2416 holgerb 100
 
2390 holgerb 101
        if(EE_Parameter.UnterspannungsWarnung < 50)
1654 killagreg 102
        {
2402 holgerb 103
                BattLowVoltageWarning = LipoCells * EE_Parameter.UnterspannungsWarnung;
1654 killagreg 104
                if(print)
105
                {
2402 holgerb 106
                        Piep(LipoCells, 200);
107
                        printf(" %d Cells ", LipoCells);
1420 killagreg 108
                }
1654 killagreg 109
        }
110
        else BattLowVoltageWarning = EE_Parameter.UnterspannungsWarnung;
2390 holgerb 111
 
112
        // automatische Zellenerkennung
2416 holgerb 113
        if(EE_Parameter.AutoLandingVoltage < 50) BattAutoLandingVoltage = LipoCells * EE_Parameter.AutoLandingVoltage; else BattAutoLandingVoltage = EE_Parameter.AutoLandingVoltage;
114
        if(EE_Parameter.ComingHomeVoltage < 50)  BattComingHomeVoltage = LipoCells * EE_Parameter.ComingHomeVoltage; else BattComingHomeVoltage = EE_Parameter.ComingHomeVoltage;
2390 holgerb 115
 
2416 holgerb 116
        if(BattAutoLandingVoltage > BattLowVoltageWarning) BattAutoLandingVoltage = BattLowVoltageWarning - 1;
117
        if(BattComingHomeVoltage  >= BattLowVoltageWarning) BattComingHomeVoltage  = BattLowVoltageWarning - 1;
118
        if(BattAutoLandingVoltage >= BattComingHomeVoltage && EE_Parameter.ComingHomeVoltage) BattAutoLandingVoltage = BattComingHomeVoltage - 1;
2408 holgerb 119
 
2390 holgerb 120
        if(print)
121
         {
2408 holgerb 122
          printf(" Low warning: %d.%dV",BattLowVoltageWarning/10,BattLowVoltageWarning%10);
2416 holgerb 123
          if(BattComingHomeVoltage) printf("  Auto-CH: %d.%dV",BattComingHomeVoltage/10,BattComingHomeVoltage%10);
124
          if(BattAutoLandingVoltage) printf("  Autolanding: %d.%dV",BattAutoLandingVoltage/10,BattAutoLandingVoltage%10);
2390 holgerb 125
         }
2416 holgerb 126
 
1268 hbuss 127
}
128
 
1 ingob 129
//############################################################################
130
//Hauptprogramm
131
int main (void)
132
//############################################################################
133
{
1424 ingob 134
        unsigned int timer,i,timer2 = 0, timerPolling;
2341 holgerb 135
        unsigned char update_spi = 1;
1051 killagreg 136
    DDRB  = 0x00;
2330 holgerb 137
    PORTB = 0x00;
2309 holgerb 138
    DDRD  = 0x0A; // UART & J3 J4 J5
139
        PORTD = 0x5F; // PPM-Input & UART
188 holgerb 140
    for(timer = 0; timer < 1000; timer++); // verzögern
1660 holgerb 141
#if (defined(__AVR_ATmega1284__) || defined(__AVR_ATmega1284P__))
2334 holgerb 142
        unsigned char AccZ_ErrorCnt = 0;
2309 holgerb 143
    if(PINB & 0x02)
144
         {
145
          if(PIND & 0x10) PlatinenVersion = 21; // No Bridge from J4 to GND
146
          else { PlatinenVersion = 22; ACC_AltitudeControl = 1;};
147
         }
148
     else          
149
     {
2367 holgerb 150
          PlatinenVersion = 25; ACC_AltitudeControl = 1;
2309 holgerb 151
         }  
1660 holgerb 152
#else
153
        if(PINB & 0x01)
918 hbuss 154
     {
1051 killagreg 155
      if(PINB & 0x02) PlatinenVersion = 13;
156
       else           PlatinenVersion = 11;
918 hbuss 157
     }
1051 killagreg 158
    else
1021 hbuss 159
     {
1051 killagreg 160
      if(PINB & 0x02) PlatinenVersion = 20;
2309 holgerb 161
       else          
162
            {
163
                 PlatinenVersion = 10;
164
                 DDRD  = 0x3E; // Speaker & TXD & J3 J4 J5
165
             PORTD = 0x47; // 
166
                }
1021 hbuss 167
     }
1660 holgerb 168
#endif
2316 holgerb 169
 
2309 holgerb 170
    DDRC  = 0x81; // I2C, Spaker
1036 hbuss 171
    DDRC  |=0x40; // HEF4017 Reset
1 ingob 172
    PORTC = 0xff; // Pullup SDA
173
    DDRB  = 0x1B; // LEDs und Druckoffset
174
    PORTB = 0x01; // LED_Rot
2309 holgerb 175
 
2146 holgerb 176
    HEF4017Reset_ON;
1 ingob 177
    MCUSR &=~(1<<WDRF);
178
    WDTCSR |= (1<<WDCE)|(1<<WDE);
179
    WDTCSR = 0;
180
 
1652 holgerb 181
    beeptime = 2500;
1660 holgerb 182
        StickGier = 0; PPM_in[K_GAS] = 0; StickRoll = 0; StickNick = 0;
183
    if(PlatinenVersion >= 20)  GIER_GRAD_FAKTOR = 1220; else GIER_GRAD_FAKTOR = 1291; // unterschiedlich für ME und ENC
1 ingob 184
    ROT_OFF;
2193 holgerb 185
    GRN_ON;
1479 killagreg 186
 
1 ingob 187
    Timer_Init();
1156 hbuss 188
        TIMER2_Init();
1 ingob 189
        UART_Init();
190
    rc_sum_init();
191
        ADC_Init();
1743 holgerb 192
        I2C_Init(1);
597 ingob 193
        SPI_MasterInit();
1486 killagreg 194
        Capacity_Init();
2309 holgerb 195
        LIBFC_Init(LIB_FC_COMPATIBLE);
1431 ingob 196
        GRN_ON;
197
    sei();
1622 killagreg 198
        ParamSet_Init();
1211 hbuss 199
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2426 holgerb 200
    if(PlatinenVersion < 20)
201
        {
202
            wdt_enable(WDTO_250MS); // Reset-Commando
203
                while(1) printf("\n\rFlightControl not supported!");
204
        }
205
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1211 hbuss 206
// + Check connected BL-Ctrls
207
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1648 killagreg 208
        // Check connected BL-Ctrls
209
        BLFlags |= BLFLAG_READ_VERSION;
1662 killagreg 210
        motor_read = 0;  // read the first I2C-Data
1648 killagreg 211
        SendMotorData();
1683 killagreg 212
        timer = SetDelay(500);
213
        while(!(BLFlags & BLFLAG_TX_COMPLETE) && !CheckDelay(timer)); //wait for complete transfer
1654 killagreg 214
 
1648 killagreg 215
    printf("\n\rFound BL-Ctrl: ");
1591 holgerb 216
    timer = SetDelay(4000);
1211 hbuss 217
        for(i=0; i < MAX_MOTORS; i++)
1622 killagreg 218
        {
219
                SendMotorData();
1683 killagreg 220
                while(!(BLFlags & BLFLAG_TX_COMPLETE)  && !CheckDelay(timer)); //wait for complete transfer
1622 killagreg 221
                if(Mixer.Motor[i][0] > 0) // wait max 4 sec for the BL-Ctrls to wake up
222
                {
1648 killagreg 223
                        while(!CheckDelay(timer) && !(Motor[i].State & MOTOR_STATE_PRESENT_MASK) )
224
                        {
225
                                SendMotorData();
1683 killagreg 226
                                while(!(BLFlags & BLFLAG_TX_COMPLETE) && !CheckDelay(timer)); //wait for complete transfer
1648 killagreg 227
                        }
1232 hbuss 228
                }
1648 killagreg 229
                if(Motor[i].State & MOTOR_STATE_PRESENT_MASK)
230
                {
231
                        printf("%d",i+1);
1702 holgerb 232
                        FoundMotors++;
2380 holgerb 233
//                      if(Motor[i].Version & MOTOR_STATE_FAST_MODE) printf("(fast)\n\r");
234
//                      else if(Motor[i].Version & MOTOR_STATE_NEW_PROTOCOL_MASK) printf("(new)\n\r");
1648 killagreg 235
                }
1622 killagreg 236
        }
1211 hbuss 237
        for(i=0; i < MAX_MOTORS; i++)
1051 killagreg 238
        {
1622 killagreg 239
                if(!(Motor[i].State & MOTOR_STATE_PRESENT_MASK) && Mixer.Motor[i][0] > 0)
240
                {
241
                        printf("\n\r\n\r!! MISSING BL-CTRL: %d !!",i+1);
1701 holgerb 242
                        ServoActive = 2; // just in case the FC would be used as camera-stabilizer
1111 hbuss 243
                }
1622 killagreg 244
                Motor[i].State &= ~MOTOR_STATE_ERROR_MASK; // clear error counter
1 ingob 245
        }
2030 holgerb 246
   PrintLine();// ("\n\r===================================");
1648 killagreg 247
 
2030 holgerb 248
 
1765 killagreg 249
    if(RequiredMotors < FoundMotors) VersionInfo.HardwareError[1] |= FC_ERROR1_MIXER;
2407 holgerb 250
        if(RequiredMotors > 8) Max_I2C_Packets = 8; else Max_I2C_Packets = RequiredMotors;
1529 killagreg 251
        //if(EE_Parameter.GlobalConfig & CFG_HOEHENREGELUNG)
1622 killagreg 252
        {
253
                printf("\n\rCalibrating pressure sensor..");
254
                timer = SetDelay(1000);
255
                SucheLuftruckOffset();
256
                while (!CheckDelay(timer));
257
                printf("OK\n\r");
1 ingob 258
        }
1051 killagreg 259
 
2418 holgerb 260
#ifdef REDUNDANT_FC
261
VersionInfo.HardwareError[0] = 0;
262
VersionInfo.HardwareError[1] = 0;
263
#endif
264
 
1622 killagreg 265
        SetNeutral(0);
1 ingob 266
 
267
        ROT_OFF;
1051 killagreg 268
 
1 ingob 269
    beeptime = 2000;
1051 killagreg 270
    ExternControl.Digital[0] = 0x55;
1 ingob 271
 
1051 killagreg 272
 
1652 holgerb 273
        FlugMinuten = (unsigned int)GetParamByte(PID_FLIGHT_MINUTES) * 256 + (unsigned int)GetParamByte(PID_FLIGHT_MINUTES + 1);
274
        FlugMinutenGesamt = (unsigned int)GetParamByte(PID_FLIGHT_MINUTES_TOTAL) * 256 + (unsigned int)GetParamByte(PID_FLIGHT_MINUTES_TOTAL + 1);
1622 killagreg 275
 
1702 holgerb 276
        if((FlugMinutenGesamt == 0xFFFF) || (FlugMinuten == 0xFFFF))
1622 killagreg 277
        {
278
                FlugMinuten = 0;
279
                FlugMinutenGesamt = 0;
280
        }
2034 holgerb 281
    printf("\n\rFlight-time %u min Total:%u min", FlugMinuten, FlugMinutenGesamt);
1 ingob 282
    LcdClear();
173 holgerb 283
    I2CTimeout = 5000;
819 hbuss 284
    WinkelOut.Orientation = 1;
1268 hbuss 285
    LipoDetection(1);
1626 killagreg 286
        LIBFC_ReceiverInit(EE_Parameter.Receiver);
2030 holgerb 287
    PrintLine();// ("\n\r===================================");
1622 killagreg 288
        //SpektrumBinding();
1350 hbuss 289
    timer = SetDelay(2000);
1424 ingob 290
        timerPolling = SetDelay(250);
1648 killagreg 291
 
1636 ingob 292
        Debug(ANSI_CLEAR "FC-Start!\n\rFlugzeit: %d min", FlugMinutenGesamt);   // Note: this won't waste flash memory, if #DEBUG is not active
2340 holgerb 293
//printf("\n\rEE_Parameter size:%i\n\r", PARAMSET_STRUCT_LEN);
294
 
1702 holgerb 295
    DebugOut.Status[0] = 0x01 | 0x02;
1834 holgerb 296
        JetiBeep = 0;
1913 holgerb 297
    if(EE_Parameter.ExtraConfig & CFG_NO_RCOFF_BEEPING)   DisableRcOffBeeping = 1;
2333 holgerb 298
        EEAR = EE_DUMMY;  // Set the EEPROM Address pointer to an unused space
2330 holgerb 299
        while(1)
1 ingob 300
        {
1945 holgerb 301
        if(ReceiverUpdateModeActive) while (1) PORTC &= ~(1<<7); // Beeper off
1930 holgerb 302
//GRN_ON;
1419 ingob 303
        if(UpdateMotor && AdReady)      // ReglerIntervall
1051 killagreg 304
            {
1930 holgerb 305
//GRN_OFF;
2386 holgerb 306
cli();
307
                        UpdateMotor--;    
308
sei();
819 hbuss 309
            if(WinkelOut.CalcState) CalMk3Mag();
1644 holgerb 310
            else  MotorRegler();
311
                        SendMotorData();
1 ingob 312
            ROT_OFF;
1937 holgerb 313
            if(SenderOkay)  { SenderOkay--; /*VersionInfo.HardwareError[1] &= ~FC_ERROR1_PPM;*/ }
1603 killagreg 314
                        else
315
                        {
316
                                TIMSK1 |= _BV(ICIE1); // enable PPM-Input
317
                                PPM_in[0] = 0; // set RSSI to zero on data timeout
1765 killagreg 318
                                VersionInfo.HardwareError[1] |= FC_ERROR1_PPM;
1603 killagreg 319
                        }
1420 killagreg 320
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1481 holgerb 321
//if(HoehenReglerAktiv && NaviDataOkay && SenderOkay < 160 && SenderOkay > 10 && FromNaviCtrl_Value.SerialDataOkay > 220) SenderOkay = 160;
322
//if(HoehenReglerAktiv && NaviDataOkay && SenderOkay < 101 && SenderOkay > 10 && FromNaviCtrl_Value.SerialDataOkay > 1) SenderOkay = 101;
1309 hbuss 323
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1210 hbuss 324
            if(!--I2CTimeout || MissingMotor)
173 holgerb 325
                {
1254 killagreg 326
                  if(!I2CTimeout)
1210 hbuss 327
                                   {
1662 killagreg 328
                                    I2C_Reset();
1210 hbuss 329
                    I2CTimeout = 5;
1322 hbuss 330
                                        DebugOut.Analog[28]++; // I2C-Error
1765 killagreg 331
                                        VersionInfo.HardwareError[1] |= FC_ERROR1_I2C;
1702 holgerb 332
                                        DebugOut.Status[1] |= 0x02; // BL-Error-Status
1322 hbuss 333
                                   }
1051 killagreg 334
                  if((BeepMuster == 0xffff) && MotorenEin)
335
                   {
1936 holgerb 336
                    beeptime = 25000;
173 holgerb 337
                    BeepMuster = 0x0080;
1051 killagreg 338
                   }
1 ingob 339
                }
1051 killagreg 340
            else
1 ingob 341
                {
1051 killagreg 342
                 ROT_OFF;
1944 holgerb 343
                }
1916 holgerb 344
                  LIBFC_Polling();
345
 
1639 holgerb 346
          if(!UpdateMotor)
2012 holgerb 347
                  {
348
#if (defined(__AVR_ATmega1284__) || defined(__AVR_ATmega1284P__))
349
                   if(NewSBusData) ProcessSBus();  
350
                   else
351
#endif
1639 holgerb 352
                   {
2404 holgerb 353
                        if(BytegapSPI == 0)  SPI_TransmitByte();
1760 holgerb 354
                        if(CalculateServoSignals) CalculateServo();
355
                        DatenUebertragung();
356
                        BearbeiteRxDaten();
1254 killagreg 357
                        if(CheckDelay(timer))
358
                        {
1512 holgerb 359
                                static unsigned char second;
1420 killagreg 360
                                timer += 20; // 20 ms interval
2191 holgerb 361
                                CalcNickServoValue();
1925 holgerb 362
#if (defined(__AVR_ATmega1284__) || defined(__AVR_ATmega1284P__))
1917 holgerb 363
                                if(EE_Parameter.Receiver == RECEIVER_HOTT) HoTT_Menu();
2263 holgerb 364
                                else
365
                                if(EE_Parameter.Receiver == RECEIVER_JETI) BuildJeti_Vario();
2334 holgerb 366
                                // ++++++++++++++++++++++++++++
367
                                // + check the ACC-Z range
368
                                if(ACC_AltitudeControl && ((Aktuell_az < 300) || (DebugOut.Analog[7] < (128 * 4) && Aktuell_az > 850))) // DebugOut.Analog[7] = GasMischanteil
369
                                 {
370
                                  if(++AccZ_ErrorCnt > 50)
371
                                   {
372
                                    if(MotorenEin) VersionInfo.HardwareError[0] |= FC_ERROR0_ACC_TOP;
373
                                        else CalibrationDone = 0;
374
                                   }
375
                                 }
376
                                 else AccZ_ErrorCnt = 0;
377
                                // ++++++++++++++++++++++++++++
1925 holgerb 378
#endif
2390 holgerb 379
                                if(MissingMotor || Capacity.MinOfMaxPWM < 30)
1702 holgerb 380
                                 {
2390 holgerb 381
                                  if(MissingMotor) VersionInfo.HardwareError[1] |= FC_ERROR1_BL_MISSING;
1702 holgerb 382
                                  DebugOut.Status[1] |= 0x02; // BL-Error-Status
1765 killagreg 383
                                 }
384
                                 else
1702 holgerb 385
                                 {
1936 holgerb 386
                                   if(!beeptime)
387
                                    {
388
                                     if(I2CTimeout > 6) DebugOut.Status[1] &= ~0x02; // BL-Error-Status
389
                                        }
1765 killagreg 390
                                 }
2029 holgerb 391
                                if(DisableRcOffBeeping) if(SenderOkay > 150) { DisableRcOffBeeping = 0; beeptime = 5000;};
1420 killagreg 392
                                if(PcZugriff) PcZugriff--;
393
                                else
394
                                {
395
                                        ExternControl.Config = 0;
396
                                        ExternStickNick = 0;
397
                                        ExternStickRoll = 0;
398
                                        ExternStickGier = 0;
1913 holgerb 399
                                        if(!SenderOkay)
1420 killagreg 400
                                        {
1914 holgerb 401
                                          if(BeepMuster == 0xffff && DisableRcOffBeeping != 2)  
1913 holgerb 402
                                          {
403
                                                  beeptime = 15000;
404
                                                  BeepMuster = 0x0c00;
1914 holgerb 405
                                                  if(DisableRcOffBeeping) DisableRcOffBeeping = 2;
1913 holgerb 406
                                          }
1914 holgerb 407
                                        }
1420 killagreg 408
                                }
1682 holgerb 409
                                if(NaviDataOkay > 200)
1420 killagreg 410
                                {
411
                                        NaviDataOkay--;
1765 killagreg 412
                                        VersionInfo.HardwareError[1] &= ~FC_ERROR1_SPI_RX;
2342 holgerb 413
                                        VersionInfo.Flags |= FC_VERSION_FLAG_NC_PRESENT;
1420 killagreg 414
                                }
415
                                else
416
                                {
1702 holgerb 417
                                        if(NC_Version.Compatible)
418
                                         {
1930 holgerb 419
                                           VersionInfo.HardwareError[1] |= FC_ERROR1_SPI_RX;
420
                                           NC_ErrorCode = 9; // "ERR: no NC communication"
1702 holgerb 421
                       if(BeepMuster == 0xffff && MotorenEin)
422
                                                {
423
                                                        beeptime = 15000;
424
                                                        BeepMuster = 0xA800;
425
                                                }
1765 killagreg 426
                                         }
1420 killagreg 427
                                        GPS_Nick = 0;
428
                                        GPS_Roll = 0;
1945 holgerb 429
                                        GPS_Aid_StickMultiplikator = 0;
1916 holgerb 430
                                        GPSInfo.Flags = 0;
2348 holgerb 431
                                        FromNaviCtrl_Value.Kalman_K = -1;
1936 holgerb 432
                                        FromNaviCtrl.AccErrorN = 0;
433
                                        FromNaviCtrl.AccErrorR = 0;
1691 holgerb 434
                    FromNaviCtrl.CompassValue = -1;
2342 holgerb 435
                                        FromNC_AltitudeSpeed = 0;
436
                                        FromNC_AltitudeSetpoint = 0;
437
                                        VersionInfo.Flags &= ~FC_VERSION_FLAG_NC_PRESENT;
1703 holgerb 438
                    NaviDataOkay = 0;
1420 killagreg 439
                                }
2390 holgerb 440
                           if(UBat <= BattLowVoltageWarning)
1254 killagreg 441
                                {
1765 killagreg 442
                                        FC_StatusFlags |= FC_STATUS_LOWBAT;
2373 holgerb 443
                                        if(BeepMuster == 0xffff && UBat > 10) // Do not beep, if the voltage reading is below 1V (Supplied via MKUSB)
1254 killagreg 444
                                        {
445
                                                beeptime = 6000;
446
                                                BeepMuster = 0x0300;
447
                                        }
448
                                }
2386 holgerb 449
//                              SendSPI = SPI_BYTEGAP;
2333 holgerb 450
                                EEAR = EE_DUMMY;  // Set the EEPROM Address pointer to an unused space
2009 holgerb 451
                                // +++++++++++++++++++++++++++++++++
452
                                // Sekundentakt
1512 holgerb 453
                if(++second == 49)
454
                                 {
455
                                   second = 0;
2346 holgerb 456
#if (defined(__AVR_ATmega1284__) || defined(__AVR_ATmega1284P__))
2345 holgerb 457
                                   if(ShowSettingNameTime) ShowSettingNameTime--;
2346 holgerb 458
#endif                             
2009 holgerb 459
                                   if(FC_StatusFlags & FC_STATUS_FLY) FlugSekunden++;
2309 holgerb 460
                                   else timer2 = 1450; // 0,5 Minuten aufrunden
461
                                   if(modell_fliegt < 1024)
2009 holgerb 462
                                    {
2309 holgerb 463
                                         if(StartLuftdruck < Luftdruck) StartLuftdruck += 5;
2009 holgerb 464
                                         else
2309 holgerb 465
                                         if(StartLuftdruck > Luftdruck) StartLuftdruck -= 5;
2009 holgerb 466
                                        }
2390 holgerb 467
                             if(UBat > BattLowVoltageWarning + 1) FC_StatusFlags &= ~FC_STATUS_LOWBAT;
1512 holgerb 468
                                 }
2009 holgerb 469
                                // +++++++++++++++++++++++++++++++++
1320 hbuss 470
                                if(++timer2 == 2930)  // eine Minute
1298 hbuss 471
                                 {
472
                                   timer2 = 0;
473
                   FlugMinuten++;
474
                       FlugMinutenGesamt++;
1652 holgerb 475
                   SetParamByte(PID_FLIGHT_MINUTES,FlugMinuten / 256);
476
                   SetParamByte(PID_FLIGHT_MINUTES+1,FlugMinuten % 256);
477
                   SetParamByte(PID_FLIGHT_MINUTES_TOTAL,FlugMinutenGesamt / 256);
478
                   SetParamByte(PID_FLIGHT_MINUTES_TOTAL+1,FlugMinutenGesamt % 256);
1344 hbuss 479
                                   timer = SetDelay(20); // falls "timer += 20;" mal nicht geht
1298 hbuss 480
                             }
1254 killagreg 481
                        }
921 hbuss 482
           LED_Update();
1486 killagreg 483
           Capacity_Update();
2386 holgerb 484
           }
485
          } //else DebugOut.Analog[18]++;
2341 holgerb 486
                  if(update_spi) update_spi--;
487
                 } // 500Hz
2386 holgerb 488
         if(update_spi == 0) // 41Hz
489
          {
490
            if(SPI_StartTransmitPacket()) update_spi = 12;
491
                else
492
                if(BytegapSPI == 0)  SPI_TransmitByte();  
493
           }  
494
         else if(BytegapSPI == 0)  SPI_TransmitByte();
1 ingob 495
    }
496
}
1944 holgerb 497
//DebugOut.Analog[16]
1 ingob 498