Subversion Repositories FlightCtrl

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
2751 - 1
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2
// + www.MikroKopter.com
3
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
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.
10
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
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.
28
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
29
// + Software LICENSING TERMS
30
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
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.
52
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
53
#include "main.h"
54
unsigned char DisableRcOffBeeping = 0;
55
unsigned char PlatinenVersion = 10;
56
unsigned char BattLowVoltageWarning = 94;
57
unsigned char BattAutoLandingVoltage = 0, BattComingHomeVoltage = 0;
58
unsigned int FlugMinuten = 0,FlugMinutenGesamt = 0;
59
unsigned int FlugSekunden = 0;
60
pVoidFnct_pVoidFnctChar_const_fmt _printf_P;
61
unsigned char FoundMotors = 0;
62
unsigned char JetiBeep = 0; // to allow any Morse-Beeping of the Jeti-Box
63
unsigned char ActiveParamSet = 3;
64
unsigned char LipoCells = 4;
65
unsigned char RedundanceBlOperation = 0;
66
 
67
void PrintLine(void)
68
{
69
 printf("\n\r===================================");
70
}
71
 
72
 
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++;
81
   if(WinkelOut.CalcState > 4)
82
    {
83
//     WinkelOut.CalcState = 0; // in Uart.c
84
     beeptime = 1000;
85
    }
86
   else Piep(WinkelOut.CalcState,150);
87
  }
88
}
89
 
90
 
91
void LipoDetection(unsigned char print)
92
{
93
        #define MAX_CELL_VOLTAGE 43 // max cell voltage for LiPO
94
        if(print)
95
         {
96
          printf("\n\rBatt:");
97
          LipoCells = 1 + UBat / MAX_CELL_VOLTAGE;
98
          if(LipoCells > 6) LipoCells = 6;
99
         }
100
 
101
        if(EE_Parameter.UnterspannungsWarnung < 50)
102
        {
103
                BattLowVoltageWarning = LipoCells * EE_Parameter.UnterspannungsWarnung;
104
                if(print)
105
                {
106
                        Piep(LipoCells, 200);
107
                        printf(" %d Cells ", LipoCells);
108
                }
109
        }
110
        else BattLowVoltageWarning = EE_Parameter.UnterspannungsWarnung;
111
 
112
        // automatische Zellenerkennung
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;
115
 
116
        if(BattAutoLandingVoltage > BattLowVoltageWarning) BattAutoLandingVoltage = BattLowVoltageWarning - 1;
117
        if(BattComingHomeVoltage  >= BattLowVoltageWarning) BattComingHomeVoltage  = BattLowVoltageWarning - 1;
118
        if(BattAutoLandingVoltage >= BattComingHomeVoltage && EE_Parameter.ComingHomeVoltage) BattAutoLandingVoltage = BattComingHomeVoltage - 1;
119
 
120
        if(print)
121
         {
122
          printf(" Low warning: %d.%dV",BattLowVoltageWarning/10,BattLowVoltageWarning%10);
123
          if(BattComingHomeVoltage) printf("  Auto-CH: %d.%dV",BattComingHomeVoltage/10,BattComingHomeVoltage%10);
124
          if(BattAutoLandingVoltage) printf("  Autolanding: %d.%dV",BattAutoLandingVoltage/10,BattAutoLandingVoltage%10);
125
         }
126
 
127
}
128
 
129
//############################################################################
130
//Hauptprogramm
131
int main (void)
132
//############################################################################
133
{
134
        unsigned int timer,i,timer2 = 0, timerPolling;
135
        unsigned char update_spi = 1;
136
    DDRB  = 0x00;
137
    PORTB = 0x00;
138
    DDRD  = 0x0A; // UART & J3 J4 J5
139
        PORTD = 0x5F; // PPM-Input & UART
140
    for(timer = 0; timer < 1000; timer++); // verzögern
141
#if (defined(__AVR_ATmega1284__) || defined(__AVR_ATmega1284P__))
142
        unsigned char AccZ_ErrorCnt = 0;
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
     {
150
          PlatinenVersion = 25; ACC_AltitudeControl = 1;
151
         }  
152
#else
153
        if(PINB & 0x01)
154
     {
155
      if(PINB & 0x02) PlatinenVersion = 13;
156
       else           PlatinenVersion = 11;
157
     }
158
    else
159
     {
160
      if(PINB & 0x02) PlatinenVersion = 20;
161
       else          
162
            {
163
                 PlatinenVersion = 10;
164
                 DDRD  = 0x3E; // Speaker & TXD & J3 J4 J5
165
             PORTD = 0x47; // 
166
                }
167
     }
168
#endif
169
 
170
    DDRC  = 0x81; // I2C, Spaker
171
    DDRC  |=0x40; // HEF4017 Reset
172
    PORTC = 0xff; // Pullup SDA
173
    DDRB  = 0x1B; // LEDs und Druckoffset
174
    PORTB = 0x01; // LED_Rot
175
 
176
    HEF4017Reset_ON;
177
    MCUSR &=~(1<<WDRF);
178
    WDTCSR |= (1<<WDCE)|(1<<WDE);
179
    WDTCSR = 0;
180
 
181
    beeptime = 2500;
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
184
    ROT_OFF;
185
    GRN_ON;
186
 
187
    Timer_Init();
188
        TIMER2_Init();
189
        UART_Init();
190
    rc_sum_init();
191
        ADC_Init();
192
        I2C_Init(1);
193
        SPI_MasterInit();
194
        Capacity_Init();
195
        LIBFC_Init(LIB_FC_COMPATIBLE);
196
        GRN_ON;
197
    sei();
198
        ParamSet_Init();
199
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
200
    if(PlatinenVersion < 20)
201
        {
202
            wdt_enable(WDTO_250MS); // Reset-Commando
203
                while(1) printf("\n\rOld FC Hardware not supported by this Firmware!");
204
        }
205
#ifndef REDUNDANT_FC_SLAVE
206
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
207
// + Check connected BL-Ctrls
208
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
209
        // Check connected BL-Ctrls
210
        BLFlags |= BLFLAG_READ_VERSION;
211
        motor_read = 0;  // read the first I2C-Data
212
        for(i=0; i < 500; i++)
213
        {
214
         SendMotorData();
215
         timer = SetDelay(5);
216
         while(!(BLFlags & BLFLAG_TX_COMPLETE) && !CheckDelay(timer)); //wait for complete transfer
217
    }
218
    printf("\n\rFound BL-Ctrl: ");
219
//    timer = SetDelay(1000);
220
        for(i=0; i < MAX_MOTORS; i++)
221
        {
222
//              SendMotorData();
223
//              while(!(BLFlags & BLFLAG_TX_COMPLETE)  && !CheckDelay(timer)); //wait for complete transfer
224
                if(Mixer.Motor[i][0] > 0) // wait max 4 sec for the BL-Ctrls to wake up
225
                {
226
                        while(!CheckDelay(timer) && !(Motor[i].State & MOTOR_STATE_PRESENT_MASK) )
227
                        {
228
                                SendMotorData();
229
                                while(!(BLFlags & BLFLAG_TX_COMPLETE) && !CheckDelay(timer)); //wait for complete transfer
230
                        }
231
                }
232
                if(Motor[i].State & MOTOR_STATE_PRESENT_MASK)
233
                {
234
                    unsigned char vers;
235
                        printf("%d",(i+1)%10);
236
                        FoundMotors++;
237
                        vers = Motor[i].VersionMajor * 100 + Motor[i].VersionMinor; // creates 104 from 1.04
238
                        if(vers && VersionInfo.BL_Firmware > vers) VersionInfo.BL_Firmware = vers;
239
//                      if(Motor[i].Version & MOTOR_STATE_FAST_MODE) printf("(fast)\n\r");
240
//                      else if(Motor[i].Version & MOTOR_STATE_NEW_PROTOCOL_MASK) printf("(new)\n\r");
241
//                      printf(":V%03d\n\r",vers);
242
                }
243
        }
244
        for(i=0; i < MAX_MOTORS; i++)
245
        {
246
                if(!(Motor[i].State & MOTOR_STATE_PRESENT_MASK) && Mixer.Motor[i][0] > 0)
247
                {
248
                        printf("\n\r\n\r!! MISSING BL-CTRL: %d !!",i+1);
249
                        ServoActive = 2; // just in case the FC would be used as camera-stabilizer
250
                }
251
                Motor[i].State &= ~MOTOR_STATE_ERROR_MASK; // clear error counter
252
        }
253
#if (defined(__AVR_ATmega1284__) || defined(__AVR_ATmega1284P__))
254
   if(VersionInfo.BL_Firmware != 255)
255
    {
256
         printf("\n\rBL-Firmware %d.%02d",VersionInfo.BL_Firmware/100,VersionInfo.BL_Firmware%100);
257
         if(VersionInfo.BL_Firmware >= 100 && VersionInfo.BL_Firmware <= 102) printf("<-- warning old Version!");
258
        }
259
#endif
260
 
261
   PrintLine();// ("\n\r===================================");
262
    if(RequiredMotors < FoundMotors) VersionInfo.HardwareError[1] |= FC_ERROR1_MIXER;
263
        if(RequiredMotors > 8) Max_I2C_Packets = 8; else Max_I2C_Packets = RequiredMotors;
264
#else
265
 printf("\n\r\n\r--> REDUNDANT SLAVE <---\n\r");
266
#endif
267
 
268
#ifdef REDUNDANT_FC_MASTER
269
 printf("\n\r\n\r--> REDUNDANT MASTER <---\n\r");
270
#endif
271
 
272
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
273
// Calibrating altitude sensor
274
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
275
        //if(EE_Parameter.GlobalConfig & CFG_HOEHENREGELUNG)
276
        {
277
                printf("\n\rCalibrating pressure sensor..");
278
                timer = SetDelay(1000);
279
                SucheLuftruckOffset();
280
                while (!CheckDelay(timer));
281
                printf("OK\n\r");
282
        }
283
 
284
#ifdef REDUNDANT_FC_SLAVE
285
VersionInfo.HardwareError[0] = 0;
286
VersionInfo.HardwareError[1] = 0;
287
#endif
288
 
289
        SetNeutral(0);
290
 
291
        ROT_OFF;
292
 
293
    beeptime = 2000;
294
    ExternControl.Digital[0] = 0x55;
295
 
296
 
297
        FlugMinuten = (unsigned int)GetParamByte(PID_FLIGHT_MINUTES) * 256 + (unsigned int)GetParamByte(PID_FLIGHT_MINUTES + 1);
298
        FlugMinutenGesamt = (unsigned int)GetParamByte(PID_FLIGHT_MINUTES_TOTAL) * 256 + (unsigned int)GetParamByte(PID_FLIGHT_MINUTES_TOTAL + 1);
299
 
300
        if((FlugMinutenGesamt == 0xFFFF) || (FlugMinuten == 0xFFFF))
301
        {
302
                FlugMinuten = 0;
303
                FlugMinutenGesamt = 0;
304
        }
305
    printf("\n\rFlight-time %u min Total:%u min", FlugMinuten, FlugMinutenGesamt);
306
    LcdClear();
307
    I2CTimeout = 5000;
308
    WinkelOut.Orientation = 1;
309
    LipoDetection(1);
310
        LIBFC_ReceiverInit(EE_Parameter.Receiver);
311
    PrintLine();// ("\n\r===================================");
312
        //SpektrumBinding();
313
    timer = SetDelay(2000);
314
        timerPolling = SetDelay(250);
315
 
316
        Debug(ANSI_CLEAR "FC-Start!\n\rFlugzeit: %d min", FlugMinutenGesamt);   // Note: this won't waste flash memory, if #DEBUG is not active
317
//printf("\n\rEE_Parameter size:%i\n\r", PARAMSET_STRUCT_LEN);
318
 
319
    DebugOut.Status[0] = 0x01 | 0x02;
320
        JetiBeep = 0;
321
    if(EE_Parameter.ExtraConfig & CFG_NO_RCOFF_BEEPING)   DisableRcOffBeeping = 1;
322
        ReadBlSize = 3; // don't read the version any more
323
#ifdef REDUNDANT_FC_SLAVE
324
        timer = SetDelay(2500);
325
        while(!CheckDelay(timer));
326
        printf("\n\rStart\n\r");
327
#endif
328
        while(1)
329
        {
330
        EEAR = EE_DUMMY;  // Set the EEPROM Address pointer to an unused space
331
        if(ReceiverUpdateModeActive) while (1) PORTC &= ~(1<<7); // Beeper off
332
        if(UpdateMotor && AdReady)      // ReglerIntervall
333
            {
334
cli();
335
                        UpdateMotor--;    
336
sei();
337
            if(WinkelOut.CalcState) CalMk3Mag();
338
            else  MotorRegler();
339
                        SendMotorData();
340
            ROT_OFF;
341
            if(SenderOkay)  { SenderOkay--; /*VersionInfo.HardwareError[1] &= ~FC_ERROR1_PPM;*/ }
342
                        else
343
                        {
344
                                TIMSK1 |= _BV(ICIE1); // enable PPM-Input
345
                                PPM_in[0] = 0; // set RSSI to zero on data timeout
346
                                VersionInfo.HardwareError[1] |= FC_ERROR1_PPM;
347
                        }
348
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
349
//if(HoehenReglerAktiv && NaviDataOkay && SenderOkay < 160 && SenderOkay > 10 && FromNaviCtrl_Value.SerialDataOkay > 220) SenderOkay = 160;
350
//if(HoehenReglerAktiv && NaviDataOkay && SenderOkay < 101 && SenderOkay > 10 && FromNaviCtrl_Value.SerialDataOkay > 1) SenderOkay = 101;
351
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
352
            if(!--I2CTimeout || MissingMotor)
353
                {
354
                  if(!I2CTimeout)
355
                                   {
356
                                    I2C_Reset();
357
                    I2CTimeout = 5;
358
                                        DebugOut.Analog[28]++; // I2C-Error
359
                                        VersionInfo.HardwareError[1] |= FC_ERROR1_I2C;
360
                                        DebugOut.Status[1] |= 0x02; // BL-Error-Status
361
                                   }
362
                  if((BeepMuster == 0xffff) && MotorenEin)
363
                   {
364
                    beeptime = 25000;
365
                    BeepMuster = 0x0080;
366
                   }
367
                }
368
            else
369
                {
370
                 ROT_OFF;
371
                }
372
                  LIBFC_Polling();
373
 
374
          if(!UpdateMotor)
375
                  {
376
#if (defined(__AVR_ATmega1284__) || defined(__AVR_ATmega1284P__))
377
                   if(NewSBusData) ProcessSBus();  
378
                   else
379
#endif
380
                   {
381
                        if(BytegapSPI == 0)  SPI_TransmitByte();
382
                        if(CalculateServoSignals) CalculateServo();
383
                        DatenUebertragung();
384
                        BearbeiteRxDaten();
385
                        if(CheckDelay(timer))
386
                        {
387
                                static unsigned char second;
388
                                timer += 20; // 20 ms interval
389
                                CalcNickServoValue();
390
#if (defined(__AVR_ATmega1284__) || defined(__AVR_ATmega1284P__))
391
                                if(EE_Parameter.Receiver == RECEIVER_HOTT) HoTT_Menu();
392
                                else
393
                                if(EE_Parameter.Receiver == RECEIVER_JETI) BuildJeti_Vario();
394
                                // ++++++++++++++++++++++++++++
395
                                // + check the ACC-Z range
396
                                if(ACC_AltitudeControl && ((Aktuell_az < 300) || (DebugOut.Analog[7] < (128 * 4) && Aktuell_az > 850))) // DebugOut.Analog[7] = GasMischanteil
397
                                 {
398
                                  if(++AccZ_ErrorCnt > 50)
399
                                   {
400
                                    if(MotorenEin) VersionInfo.HardwareError[0] |= FC_ERROR0_ACC_TOP;
401
                                        else CalibrationDone = 0;
402
                                   }
403
                                 }
404
                                 else AccZ_ErrorCnt = 0;
405
                                // ++++++++++++++++++++++++++++
406
#endif
407
                                if(MissingMotor || Capacity.MinOfMaxPWM < 30)
408
                                 {
409
                                  if(MissingMotor) VersionInfo.HardwareError[1] |= FC_ERROR1_BL_MISSING;
410
                                  DebugOut.Status[1] |= 0x02; // BL-Error-Status
411
                                 }
412
                                 else
413
                                 {
414
                                   if(!beeptime)
415
                                    {
416
                                     if(I2CTimeout > 6) DebugOut.Status[1] &= ~0x02; // BL-Error-Status
417
                                        }
418
                                 }
419
                                if(DisableRcOffBeeping) if(SenderOkay > 150) { DisableRcOffBeeping = 0; beeptime = 5000;};
420
                                if(PcZugriff) PcZugriff--;
421
                                else
422
                                {
423
                                        ExternControl.Config = 0;
424
                                        ExternStickNick = 0;
425
                                        ExternStickRoll = 0;
426
                                        ExternStickGier = 0;
427
                                        if(!SenderOkay)
428
                                        {
429
                                          if(BeepMuster == 0xffff && DisableRcOffBeeping != 2)  
430
                                          {
431
                                                  beeptime = 15000;
432
                                                  BeepMuster = 0x0c00;
433
                                                  if(DisableRcOffBeeping) DisableRcOffBeeping = 2;
434
                                          }
435
                                        }
436
                                }
437
                                if(NaviDataOkay > 200)
438
                                {
439
                                        NaviDataOkay--;
440
                                        VersionInfo.HardwareError[1] &= ~FC_ERROR1_SPI_RX;
441
                                        VersionInfo.Flags |= FC_VERSION_FLAG_NC_PRESENT;
442
                                }
443
                                else
444
                                {
445
                                        if(NC_Version.Compatible)
446
                                         {
447
                                           VersionInfo.HardwareError[1] |= FC_ERROR1_SPI_RX;
448
                                           NC_ErrorCode = 9; // "ERR: no NC communication"
449
                       if(BeepMuster == 0xffff && MotorenEin)
450
                                                {
451
                                                        beeptime = 15000;
452
                                                        BeepMuster = 0xA800;
453
                                                }
454
                                         }
455
                                        GPS_Nick = 0;
456
                                        GPS_Roll = 0;
457
                                        GPS_Aid_StickMultiplikator = 0;
458
                                        GPSInfo.Flags = 0;
459
                                        FromNaviCtrl_Value.Kalman_K = -1;
460
                                        FromNaviCtrl.AccErrorN = 0;
461
                                        FromNaviCtrl.AccErrorR = 0;
462
                    FromNaviCtrl.CompassValue = -1;
463
                                        FromNC_AltitudeSpeed = 0;
464
                                        FromNC_AltitudeSetpoint = 0;
465
                                        VersionInfo.Flags &= ~FC_VERSION_FLAG_NC_PRESENT;
466
                    NaviDataOkay = 0;
467
                                }
468
                           if(UBat <= BattLowVoltageWarning)
469
                                {
470
                                        FC_StatusFlags |= FC_STATUS_LOWBAT;
471
                                        if(BeepMuster == 0xffff && UBat > 10) // Do not beep, if the voltage reading is below 1V (Supplied via MKUSB)
472
                                        {
473
                                                beeptime = 6000;
474
                                                BeepMuster = 0x0300;
475
                                        }
476
                                }
477
                                // +++++++++++++++++++++++++++++++++
478
                                // Sekundentakt
479
                if(++second == 49)
480
                                 {
481
                                   second = 0;
482
/*
483
DebugOut.Analog[16] -= DebugOut.Analog[16] / 128;
484
DebugOut.Analog[17] -= DebugOut.Analog[17] / 128;
485
 
486
if(DebugOut.Analog[16] > 3000) {AdNeutralNick++; DebugOut.Analog[16] = 0;}
487
else
488
if(DebugOut.Analog[16] < -3000) {AdNeutralNick--; DebugOut.Analog[16] = 0;};
489
 
490
if(DebugOut.Analog[17] > 3000) {AdNeutralRoll++; DebugOut.Analog[17] = 0;}
491
else
492
if(DebugOut.Analog[17] < -3000) {AdNeutralRoll--; DebugOut.Analog[17] = 0;};
493
*/
494
 
495
#if (defined(__AVR_ATmega1284__) || defined(__AVR_ATmega1284P__))
496
                                   if(ShowSettingNameTime) ShowSettingNameTime--;
497
#endif                             
498
                                   if(FC_StatusFlags & FC_STATUS_FLY) FlugSekunden++;
499
                                   else timer2 = 1450; // 0,5 Minuten aufrunden
500
                                   if(modell_fliegt < 1024)
501
                                    {
502
                                         if(StartLuftdruck < Luftdruck) StartLuftdruck += 5;
503
                                         else
504
                                         if(StartLuftdruck > Luftdruck) StartLuftdruck -= 5;
505
                                        }
506
                             if(UBat > BattLowVoltageWarning + 1) FC_StatusFlags &= ~FC_STATUS_LOWBAT;
507
                                 }
508
                                // +++++++++++++++++++++++++++++++++
509
                                if(++timer2 == 2930)  // eine Minute
510
                                 {
511
                                   timer2 = 0;
512
                   FlugMinuten++;
513
                       FlugMinutenGesamt++;
514
                   SetParamByte(PID_FLIGHT_MINUTES,FlugMinuten / 256);
515
                   SetParamByte(PID_FLIGHT_MINUTES+1,FlugMinuten % 256);
516
                   SetParamByte(PID_FLIGHT_MINUTES_TOTAL,FlugMinutenGesamt / 256);
517
                   SetParamByte(PID_FLIGHT_MINUTES_TOTAL+1,FlugMinutenGesamt % 256);
518
                                   timer = SetDelay(20); // falls "timer += 20;" mal nicht geht
519
                             }
520
                        }
521
           LED_Update();
522
           Capacity_Update();
523
           }
524
          } //else DebugOut.Analog[18]++;
525
                  if(update_spi) update_spi--;
526
                 } // 500Hz
527
         if(update_spi == 0) // 41Hz
528
          {
529
            if(SPI_StartTransmitPacket()) update_spi = 12;
530
                else
531
                if(BytegapSPI == 0)  SPI_TransmitByte();  
532
           }  
533
         else if(BytegapSPI == 0)  SPI_TransmitByte();
534
    }
535
}
536
//DebugOut.Analog[16]
537