Subversion Repositories FlightCtrl

Rev

Rev 2049 | Rev 2055 | Go to most recent revision | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 2049 Rev 2052
1
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2
// + Copyright (c) 04.2007 Holger Buss
2
// + Copyright (c) 04.2007 Holger Buss
3
// + Nur für den privaten Gebrauch
3
// + Nur für den privaten Gebrauch
4
// + www.MikroKopter.com
4
// + www.MikroKopter.com
5
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
5
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
6
// + Es gilt für das gesamte Projekt (Hardware, Software, Binärfiles, Sourcecode und Dokumentation),
6
// + Es gilt für das gesamte Projekt (Hardware, Software, Binärfiles, Sourcecode und Dokumentation),
7
// + dass eine Nutzung (auch auszugsweise) nur f�r den privaten und nicht-kommerziellen Gebrauch zulässig ist.
7
// + dass eine Nutzung (auch auszugsweise) nur f�r den privaten und nicht-kommerziellen Gebrauch zulässig ist.
8
// + Sollten direkte oder indirekte kommerzielle Absichten verfolgt werden, ist mit uns (info@mikrokopter.de) Kontakt
8
// + Sollten direkte oder indirekte kommerzielle Absichten verfolgt werden, ist mit uns (info@mikrokopter.de) Kontakt
9
// + bzgl. der Nutzungsbedingungen aufzunehmen.
9
// + bzgl. der Nutzungsbedingungen aufzunehmen.
10
// + Eine kommerzielle Nutzung ist z.B.Verkauf von MikroKoptern, Bestückung und Verkauf von Platinen oder Bausätzen,
10
// + Eine kommerzielle Nutzung ist z.B.Verkauf von MikroKoptern, Bestückung und Verkauf von Platinen oder Bausätzen,
11
// + Verkauf von Luftbildaufnahmen, usw.
11
// + Verkauf von Luftbildaufnahmen, usw.
12
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
12
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
13
// + Werden Teile des Quellcodes (mit oder ohne Modifikation) weiterverwendet oder veröffentlicht,
13
// + Werden Teile des Quellcodes (mit oder ohne Modifikation) weiterverwendet oder veröffentlicht,
14
// + unterliegen sie auch diesen Nutzungsbedingungen und diese Nutzungsbedingungen incl. Copyright müssen dann beiliegen
14
// + unterliegen sie auch diesen Nutzungsbedingungen und diese Nutzungsbedingungen incl. Copyright müssen dann beiliegen
15
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
15
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
16
// + Sollte die Software (auch auszugesweise) oder sonstige Informationen des MikroKopter-Projekts
16
// + Sollte die Software (auch auszugesweise) oder sonstige Informationen des MikroKopter-Projekts
17
// + auf anderen Webseiten oder Medien veröffentlicht werden, muss unsere Webseite "http://www.mikrokopter.de"
17
// + auf anderen Webseiten oder Medien veröffentlicht werden, muss unsere Webseite "http://www.mikrokopter.de"
18
// + eindeutig als Ursprung verlinkt und genannt werden
18
// + eindeutig als Ursprung verlinkt und genannt werden
19
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
19
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
20
// + Keine Gewähr auf Fehlerfreiheit, Vollständigkeit oder Funktion
20
// + Keine Gewähr auf Fehlerfreiheit, Vollständigkeit oder Funktion
21
// + Benutzung auf eigene Gefahr
21
// + Benutzung auf eigene Gefahr
22
// + Wir übernehmen keinerlei Haftung für direkte oder indirekte Personen- oder Sachschäden
22
// + Wir übernehmen keinerlei Haftung für direkte oder indirekte Personen- oder Sachschäden
23
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
23
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
24
// + Die Portierung der Software (oder Teile davon) auf andere Systeme (ausser der Hardware von www.mikrokopter.de) ist nur
24
// + Die Portierung der Software (oder Teile davon) auf andere Systeme (ausser der Hardware von www.mikrokopter.de) ist nur
25
// + mit unserer Zustimmung zulässig
25
// + mit unserer Zustimmung zulässig
26
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
26
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
27
// + Die Funktion printf_P() unterliegt ihrer eigenen Lizenz und ist hiervon nicht betroffen
27
// + Die Funktion printf_P() unterliegt ihrer eigenen Lizenz und ist hiervon nicht betroffen
28
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
28
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
29
// + Redistributions of source code (with or without modifications) must retain the above copyright notice,
29
// + Redistributions of source code (with or without modifications) must retain the above copyright notice,
30
// + this list of conditions and the following disclaimer.
30
// + this list of conditions and the following disclaimer.
31
// +   * Neither the name of the copyright holders nor the names of contributors may be used to endorse or promote products derived
31
// +   * Neither the name of the copyright holders nor the names of contributors may be used to endorse or promote products derived
32
// +     from this software without specific prior written permission.
32
// +     from this software without specific prior written permission.
33
// +   * The use of this project (hardware, software, binary files, sources and documentation) is only permittet
33
// +   * The use of this project (hardware, software, binary files, sources and documentation) is only permittet
34
// +     for non-commercial use (directly or indirectly)
34
// +     for non-commercial use (directly or indirectly)
35
// +     Commercial use (for example: selling of MikroKopters, selling of PCBs, assembly, ...) is only permitted
35
// +     Commercial use (for example: selling of MikroKopters, selling of PCBs, assembly, ...) is only permitted
36
// +     with our written permission
36
// +     with our written permission
37
// +   * If sources or documentations are redistributet on other webpages, out webpage (http://www.MikroKopter.de) must be
37
// +   * If sources or documentations are redistributet on other webpages, out webpage (http://www.MikroKopter.de) must be
38
// +     clearly linked as origin
38
// +     clearly linked as origin
39
// +   * porting to systems other than hardware from www.mikrokopter.de is not allowed
39
// +   * porting to systems other than hardware from www.mikrokopter.de is not allowed
40
// +  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
40
// +  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
41
// +  AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
41
// +  AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
42
// +  IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
42
// +  IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
43
// +  ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
43
// +  ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
44
// +  LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
44
// +  LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
45
// +  CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
45
// +  CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
46
// +  SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
46
// +  SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
47
// +  INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
47
// +  INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
48
// +  CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
48
// +  CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
49
// +  ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
49
// +  ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
50
// +  POSSIBILITY OF SUCH DAMAGE.
50
// +  POSSIBILITY OF SUCH DAMAGE.
51
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
51
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
52
 
52
 
53
#include <avr/boot.h>
53
#include <avr/boot.h>
54
#include <avr/io.h>
54
#include <avr/io.h>
55
#include <avr/interrupt.h>
55
#include <avr/interrupt.h>
56
#include <util/delay.h>
56
#include <util/delay.h>
57
 
57
 
58
#include "timer0.h"
58
#include "timer0.h"
59
#include "timer2.h"
59
#include "timer2.h"
60
#include "uart0.h"
60
#include "uart0.h"
61
#include "uart1.h"
61
#include "uart1.h"
62
#include "output.h"
62
#include "output.h"
63
#include "menu.h"
63
#include "menu.h"
64
#include "attitude.h"
64
#include "attitude.h"
65
#include "flight.h"
65
#include "flight.h"
66
#include "rc.h"
66
#include "rc.h"
67
#include "analog.h"
67
#include "analog.h"
68
#include "configuration.h"
68
#include "configuration.h"
69
#include "printf_P.h"
69
#include "printf_P.h"
70
#include "twimaster.h"
70
#include "twimaster.h"
71
#include "controlMixer.h"
71
#include "controlMixer.h"
72
#ifdef USE_NAVICTRL
72
#ifdef USE_NAVICTRL
73
#include "spi.h"
73
#include "spi.h"
74
#endif
74
#endif
75
#ifdef USE_DIRECT_GPS
75
#ifdef USE_MK3MAG
76
#include "mk3mag.h"
76
#include "mk3mag.h"
77
#endif
77
#endif
78
#include "eeprom.h"
78
#include "eeprom.h"
79
 
79
 
80
int16_t main(void) {
80
int16_t main(void) {
81
  uint16_t timer;
81
  uint16_t timer;
82
 
82
 
83
  // disable interrupts global
83
  // disable interrupts global
84
  cli();
84
  cli();
85
 
85
 
86
  // analyze hardware environment
86
  // analyze hardware environment
87
  CPUType = getCPUType();
87
  CPUType = getCPUType();
88
  boardRelease = getBoardRelease();
88
  boardRelease = getBoardRelease();
89
 
89
 
90
  // disable watchdog
90
  // disable watchdog
91
  MCUSR &= ~(1 << WDRF);
91
  MCUSR &= ~(1 << WDRF);
92
  WDTCSR |= (1 << WDCE) | (1 << WDE);
92
  WDTCSR |= (1 << WDCE) | (1 << WDE);
93
  WDTCSR = 0;
93
  WDTCSR = 0;
94
 
94
 
95
// This is strange: It should NOT be necessarty to do. But the call of the same,
95
// This is strange: It should NOT be necessarty to do. But the call of the same,
96
// in channelMap_readOrDefault (if eeprom read fails) just sets all to 0,0,0,....
96
// in channelMap_readOrDefault (if eeprom read fails) just sets all to 0,0,0,....
97
channelMap_default();
97
channelMap_default();
98
 
98
 
99
  // initalize modules
99
  // initalize modules
100
  output_init();
100
  output_init();
101
  timer0_init();
101
  timer0_init();
102
  timer2_init();
102
  timer2_init();
103
  usart0_init();
103
  usart0_init();
104
  if (CPUType == ATMEGA644P);// usart1_Init();
104
  if (CPUType == ATMEGA644P);// usart1_Init();
105
  RC_Init();
105
  RC_Init();
106
  analog_init();
106
  analog_init();
107
  I2C_init();
107
  I2C_init();
108
#ifdef USE_NAVICTRL
108
#ifdef USE_NAVICTRL
109
  SPI_MasterInit();
109
  SPI_MasterInit();
110
#endif
110
#endif
111
#ifdef USE_DIRECT_GPS
111
#ifdef USE_MK3MAG
112
  MK3MAG_init();
112
  MK3MAG_init();
-
 
113
#endif
-
 
114
#ifdef USE_DIRECT_GPS
113
  usart1_init();
115
  usart1_init();
114
#endif
116
#endif
115
 
117
 
116
  // Parameter Set handling
118
  // Parameter Set handling
117
  channelMap_readOrDefault();
119
  channelMap_readOrDefault();
118
  mixerMatrix_readOrDefault();
120
  mixerMatrix_readOrDefault();
119
  paramSet_readOrDefault();
121
  paramSet_readOrDefault();
120
 
122
 
121
  // enable interrupts global
123
  // enable interrupts global
122
  sei();
124
  sei();
123
 
125
 
124
  printf("\n\r===================================");
126
  printf("\n\r===================================");
125
  printf("\n\rFlightControl");
127
  printf("\n\rFlightControl");
126
  printf("\n\rHardware: Custom");
128
  printf("\n\rHardware: Custom");
127
  printf("\n\r     CPU: Atmega644");
129
  printf("\n\r     CPU: Atmega644");
128
  if (CPUType == ATMEGA644P)
130
  if (CPUType == ATMEGA644P)
129
    printf("p");
131
    printf("p");
130
  printf("\n\rSoftware: V%d.%d%c",VERSION_MAJOR, VERSION_MINOR, VERSION_PATCH + 'a');
132
  printf("\n\rSoftware: V%d.%d%c",VERSION_MAJOR, VERSION_MINOR, VERSION_PATCH + 'a');
131
  printf("\n\r===================================");
133
  printf("\n\r===================================");
132
 
134
 
133
  // Wait for a short time (otherwise the RC channel check won't work below)
135
  // Wait for a short time (otherwise the RC channel check won't work below)
134
  // timer = SetDelay(500);
136
  // timer = SetDelay(500);
135
  // while(!CheckDelay(timer));
137
  // while(!CheckDelay(timer));
136
 
138
 
137
  // Instead, while away the time by flashing the 2 outputs:
139
  // Instead, while away the time by flashing the 2 outputs:
138
  // First J16, then J17. Makes it easier to see which is which.
140
  // First J16, then J17. Makes it easier to see which is which.
139
  timer = setDelay(200);
141
  timer = setDelay(200);
140
  outputSet(0,1);
142
  outputSet(0,1);
141
  GRN_OFF;
143
  GRN_OFF;
142
  RED_ON;
144
  RED_ON;
143
  while (!checkDelay(timer))
145
  while (!checkDelay(timer))
144
    ;
146
    ;
145
 
147
 
146
  timer = setDelay(200);
148
  timer = setDelay(200);
147
  outputSet(0,0);
149
  outputSet(0,0);
148
  outputSet(1,1);
150
  outputSet(1,1);
149
  RED_OFF;
151
  RED_OFF;
150
  GRN_ON;
152
  GRN_ON;
151
  while (!checkDelay(timer))
153
  while (!checkDelay(timer))
152
    ;
154
    ;
153
 
155
 
154
  timer = setDelay(200);
156
  timer = setDelay(200);
155
  while (!checkDelay(timer))
157
  while (!checkDelay(timer))
156
    ;
158
    ;
157
  outputSet(1,0);
159
  outputSet(1,0);
158
  GRN_OFF;
160
  GRN_OFF;
159
 
161
 
160
  twi_diagnostics();
162
  twi_diagnostics();
161
 
163
 
162
  printf("\n\r===================================");
164
  printf("\n\r===================================");
163
 
165
 
164
#ifdef USE_NAVICTRL
166
#ifdef USE_NAVICTRL
165
  printf("\n\rSupport for NaviCtrl");
167
  printf("\n\rSupport for NaviCtrl");
166
#endif
168
#endif
167
 
169
 
168
#ifdef USE_DIRECT_GPS
170
#ifdef USE_DIRECT_GPS
169
  printf("\n\rDirect (no NaviCtrl) navigation");
171
  printf("\n\rDirect (no NaviCtrl) navigation");
170
#endif
172
#endif
171
 
173
 
172
  controlMixer_setNeutral();
174
  controlMixer_setNeutral();
173
 
175
 
174
  // Cal. attitude sensors and reset integrals.
176
  // Cal. attitude sensors and reset integrals.
175
  attitude_setNeutral();
177
  attitude_setNeutral();
176
 
178
 
177
  // Init flight parameters
179
  // Init flight parameters
178
  flight_setNeutral();
180
  flight_setNeutral();
179
 
181
 
180
  beep(2000);
182
  beep(2000);
181
 
183
 
182
  printf("\n\rControl: ");
184
  printf("\n\rControl: ");
183
  if (staticParams.bitConfig & CFG_HEADING_HOLD)
185
  if (staticParams.bitConfig & CFG_HEADING_HOLD)
184
    printf("Heading Hold");
186
    printf("Heading Hold");
185
    else printf("RTL Mode");
187
    else printf("RTL Mode");
186
 
188
 
187
  printf("\n\n\r");
189
  printf("\n\n\r");
188
 
190
 
189
  LCD_clear();
191
  LCD_clear();
190
 
192
 
191
  I2CTimeout = 5000;
193
  I2CTimeout = 5000;
192
 
194
 
193
  while (1) {
195
  while (1) {
194
    if (runFlightControl) { // control interval
196
    if (runFlightControl) { // control interval
195
      runFlightControl = 0; // reset Flag, is enabled every 2 ms by ISR of timer0
197
      runFlightControl = 0; // reset Flag, is enabled every 2 ms by ISR of timer0
196
      if (!analogDataReady) {
198
      if (!analogDataReady) {
197
        // Analog data should have been ready but is not!!
199
        // Analog data should have been ready but is not!!
198
        debugOut.digital[0] |= DEBUG_MAINLOOP_TIMER;
200
        debugOut.digital[0] |= DEBUG_MAINLOOP_TIMER;
199
      } else {
201
      } else {
200
        debugOut.digital[0] &= ~DEBUG_MAINLOOP_TIMER;
202
        debugOut.digital[0] &= ~DEBUG_MAINLOOP_TIMER;
201
 
203
 
202
        J4HIGH;
204
        J4HIGH;
203
        // This is probably the correct order:
205
        // This is probably the correct order:
204
        // The attitude computation should not depend on anything from control (except maybe the estimation of control activity level)
206
        // The attitude computation should not depend on anything from control (except maybe the estimation of control activity level)
205
        // The control may depend on attitude - for example, attitude control uses pitch and roll angles, compass control uses yaw angle etc.
207
        // The control may depend on attitude - for example, attitude control uses pitch and roll angles, compass control uses yaw angle etc.
206
        // Flight control uses results from both.
208
        // Flight control uses results from both.
207
        calculateFlightAttitude();
209
        calculateFlightAttitude();
208
        controlMixer_periodicTask();
210
        controlMixer_periodicTask();
209
        flight_control();
211
        flight_control();
210
        J4LOW;
212
        J4LOW;
211
 
213
 
212
        if (!--I2CTimeout || missingMotor) { // try to reset the i2c if motor is missing or timeout
214
        if (!--I2CTimeout || missingMotor) { // try to reset the i2c if motor is missing or timeout
213
          if (!I2CTimeout) {
215
          if (!I2CTimeout) {
214
            I2C_Reset();
216
            I2C_Reset();
215
            I2CTimeout = 5;
217
            I2CTimeout = 5;
216
          }
218
          }
217
          beepI2CAlarm();
219
          beepI2CAlarm();
218
        }
220
        }
219
       
221
       
220
        // Allow Serial Data Transmit if motors must not updated or motors are not running
222
        // Allow Serial Data Transmit if motors must not updated or motors are not running
221
        if (!runFlightControl || !(MKFlags & MKFLAG_MOTOR_RUN)) {
223
        if (!runFlightControl || !(MKFlags & MKFLAG_MOTOR_RUN)) {
222
          usart0_transmitTxData();
224
          usart0_transmitTxData();
223
        }
225
        }
224
 
226
 
225
        usart0_processRxData();
227
        usart0_processRxData();
226
 
228
 
227
        if (checkDelay(timer)) {
229
        if (checkDelay(timer)) {
228
          if (UBat <= UBAT_AT_5V) {
230
          if (UBat <= UBAT_AT_5V) {
229
            // Do nothing. The voltage on the input side of the regulator is <5V;
231
            // Do nothing. The voltage on the input side of the regulator is <5V;
230
            // we must be running off USB power. Keep it quiet.
232
            // we must be running off USB power. Keep it quiet.
231
          } else if (UBat < staticParams.batteryVoltageWarning) {
233
          } else if (UBat < staticParams.batteryVoltageWarning) {
232
            beepBatteryAlarm();
234
            beepBatteryAlarm();
233
          }
235
          }
234
 
236
 
235
#ifdef USE_NAVICTRL
237
#ifdef USE_NAVICTRL
236
          SPI_StartTransmitPacket();
238
          SPI_StartTransmitPacket();
237
          SendSPI = 4;
239
          SendSPI = 4;
238
#endif
240
#endif
239
          timer = setDelay(20); // every 20 ms
241
          timer = setDelay(20); // every 20 ms
240
        }
242
        }
241
        output_update();
243
        output_update();
242
      }
244
      }
243
 
245
 
244
#ifdef USE_NAVICTRL
246
#ifdef USE_NAVICTRL
245
      if(!SendSPI) {
247
      if(!SendSPI) {
246
        // SendSPI is decremented in timer0.c with a rate of 9.765 kHz.
248
        // SendSPI is decremented in timer0.c with a rate of 9.765 kHz.
247
        // within the SPI_TransmitByte() routine the value is set to 4.
249
        // within the SPI_TransmitByte() routine the value is set to 4.
248
        // I.e. the SPI_TransmitByte() is called at a rate of 9.765 kHz/4= 2441.25 Hz,
250
        // I.e. the SPI_TransmitByte() is called at a rate of 9.765 kHz/4= 2441.25 Hz,
249
        // and therefore the time of transmission of a complete spi-packet (32 bytes) is 32*4/9.765 kHz = 13.1 ms.
251
        // and therefore the time of transmission of a complete spi-packet (32 bytes) is 32*4/9.765 kHz = 13.1 ms.
250
        SPI_TransmitByte();
252
        SPI_TransmitByte();
251
      }
253
      }
252
#endif
254
#endif
253
 
255
 
254
          calculateServoValues();
256
          calculateServoValues();
255
         
257
         
256
          if (runFlightControl) { // Time for the next iteration was up before the current finished. Signal error.
258
          if (runFlightControl) { // Time for the next iteration was up before the current finished. Signal error.
257
        debugOut.digital[1] |= DEBUG_MAINLOOP_TIMER;
259
        debugOut.digital[1] |= DEBUG_MAINLOOP_TIMER;
258
      } else {
260
      } else {
259
        debugOut.digital[1] &= ~DEBUG_MAINLOOP_TIMER;
261
        debugOut.digital[1] &= ~DEBUG_MAINLOOP_TIMER;
260
          }      
262
          }      
261
    }
263
    }
262
  }
264
  }
263
  return (1);
265
  return (1);
264
}
266
}
265
 
267