Subversion Repositories FlightCtrl

Rev

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

Rev 885 Rev 886
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 excample: selling of MikroKopters, selling of PCBs, assembly, ...) is only permitted 
35
// +     Commercial use (for excample: 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
#include "main.h"
52
#include <avr/boot.h>
53
 
-
 
54
unsigned char EEPromArray[E2END+1] EEMEM;
-
 
55
unsigned char PlatinenVersion = 10;
-
 
56
unsigned char SendVersionToNavi = 1;
-
 
57
// -- Parametersatz aus EEPROM lesen ---
-
 
58
// number [0..5]   
-
 
59
void ReadParameterSet(unsigned char number, unsigned char *buffer, unsigned char length)
-
 
60
{
-
 
61
   if (number > 5) number = 5;
-
 
62
   eeprom_read_block(buffer, &EEPromArray[EEPROM_ADR_PARAM_BEGIN + length * number], length);
-
 
63
}
-
 
64
 
-
 
65
 
-
 
66
// -- Parametersatz ins EEPROM schreiben ---
53
 
67
// number [0..5]   
-
 
68
void WriteParameterSet(unsigned char number, unsigned char *buffer, unsigned char length)
-
 
69
{
54
#include <avr/io.h>
70
   if(number > 5) number = 5;  
-
 
71
   eeprom_write_block(buffer, &EEPromArray[EEPROM_ADR_PARAM_BEGIN + length * number], length);
-
 
72
   eeprom_write_byte(&EEPromArray[EEPROM_ADR_ACTIVE_SET], number);                              // diesen Parametersatz als aktuell merken
-
 
-
 
55
#include <avr/interrupt.h>
-
 
56
 
-
 
57
#include "main.h"
-
 
58
#include "timer0.h"
73
}
59
#include "timer2.h"
-
 
60
#include "uart.h"
74
 
61
#if defined (__AVR_ATmega644P__)
-
 
62
#include "uart1.h"
-
 
63
#endif
-
 
64
#include "led.h"
-
 
65
#include "menu.h"
75
unsigned char GetActiveParamSetNumber(void)
66
#include "fc.h"
-
 
67
#include "rc.h"
76
{
68
#include "analog.h"
77
 unsigned char set;
69
#include "printf_P.h"
78
 set = eeprom_read_byte(&EEPromArray[EEPROM_ADR_ACTIVE_SET]);
70
#ifdef USE_KILLAGREG
-
 
71
#include "mm3.h"
-
 
72
#endif
79
 if(set > 5)
73
#ifdef USE_NAVICTRL
80
  {
74
#include "spi.h"
-
 
75
#endif
81
   set = 2;  
76
#if !defined (USE_KILLAGREG) && !defined (USE_NAVICTRL)
82
   eeprom_write_byte(&EEPromArray[EEPROM_ADR_ACTIVE_SET], set);                                 // diesen Parametersatz als aktuell merken
77
#include "mk3mag.h"
83
  }
78
#endif
-
 
79
#include "twimaster.h"
84
 return(set);
-
 
85
}
-
 
86
 
-
 
87
void CalMk3Mag(void)
-
 
88
{
-
 
89
 static unsigned char stick = 1;
-
 
90
 
-
 
91
 if(PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] > -20) stick = 0;
-
 
92
 if((PPM_in[EE_Parameter.Kanalbelegung[K_NICK]] < -70) && !stick)
-
 
93
  {
-
 
94
   stick = 1;
-
 
95
   WinkelOut.CalcState++;
80
#include "eeprom.h"
96
   if(WinkelOut.CalcState > 4)
-
 
97
    {
-
 
98
//     WinkelOut.CalcState = 0; // in Uart.c
-
 
99
     beeptime = 1000;
-
 
100
    }
-
 
101
   else Piep(WinkelOut.CalcState);
81
#include "_Settings.h"
102
  }
82
 
103
  DebugOut.Analog[19] = WinkelOut.CalcState;
83
 
104
}
84
uint8_t BoardRelease = 10;
105
 
85
 
106
 
86
 
107
//############################################################################
87
//############################################################################
108
//Hauptprogramm
88
//Hauptprogramm
109
int main (void)
89
int main (void)
110
//############################################################################
90
//############################################################################
111
{
91
{
112
        unsigned int timer;
92
        unsigned int timer;
113
 
93
 
-
 
94
        // disable interrupts global
-
 
95
        cli();
-
 
96
 
114
        //unsigned int timer2 = 0;
97
        // get board release
115
    DDRB  = 0x00;
98
    DDRB  = 0x00;
116
    PORTB = 0x00;
99
    PORTB = 0x00;
117
    for(timer = 0; timer < 1000; timer++); // verzögern
100
    for(timer = 0; timer < 1000; timer++); // make some delay
118
    if(PINB & 0x01) PlatinenVersion = 11; else PlatinenVersion = 10;
101
    if(PINB & (1<<PINB0)) BoardRelease = 11;
-
 
102
    else BoardRelease = 10;
119
    DDRC  = 0x81; // SCL
103
 
120
    PORTC = 0xff; // Pullup SDA
104
        // set LED ports as output
121
    DDRB  = 0x1B; // LEDs und Druckoffset
105
        DDRB |= (1<<DDB1)|(1<<DDB0);
122
    PORTB = 0x01; // LED_Rot
-
 
123
    DDRD  = 0x3E; // Speaker & TXD & J3 J4 J5
106
        ROT_ON;
124
    DDRD  |=0x80; // J7
107
        GRN_OFF;
125
   
108
 
126
        PORTD = 0xF7; // LED
-
 
127
 
-
 
128
   
109
        // disable watchdog
129
    MCUSR &=~(1<<WDRF);
110
    MCUSR &=~(1<<WDRF);
130
    WDTCSR |= (1<<WDCE)|(1<<WDE);
111
    WDTCSR |= (1<<WDCE)|(1<<WDE);
131
    WDTCSR = 0;
112
    WDTCSR = 0;
132
 
113
 
133
    beeptime = 2000;
114
    BeepTime = 2000;
-
 
115
 
-
 
116
        PPM_in[CH_THRUST] = 0;
-
 
117
        StickYaw = 0;
134
 
118
        StickRoll = 0;
135
        StickGier = 0; PPM_in[K_GAS] = 0;StickRoll = 0; StickNick = 0;
119
        StickPitch = 0;
-
 
120
 
-
 
121
    ROT_OFF;
-
 
122
 
136
 
123
        // initalize modules
137
    ROT_OFF;
124
        LED_Init();
-
 
125
    TIMER0_Init();
-
 
126
    TIMER2_Init();
-
 
127
        USART0_Init();
-
 
128
 
-
 
129
        #if defined (__AVR_ATmega644P__)
138
   
130
        if (BoardRelease == 11) USART1_Init();
139
    Timer_Init();
131
        #endif
140
        UART_Init();
132
 
-
 
133
    RC_Init();
-
 
134
        ADC_Init();
-
 
135
        I2C_Init();
-
 
136
 
-
 
137
        #ifdef USE_KILLAGREG
141
    rc_sum_init();
138
        MM3_Init();
-
 
139
        #endif
-
 
140
        #ifdef USE_NAVICTRL
-
 
141
        SPI_MasterInit();
-
 
142
        #endif
-
 
143
        #if !defined (USE_KILLAGREG) && !defined (USE_NAVICTRL)
142
        ADC_Init();
144
        MK3MAG_Init();
-
 
145
        #endif
143
        i2c_init();
146
 
144
        SPI_MasterInit();
147
 
145
   
148
        // enable interrupts global
146
        sei();
149
        sei();
147
 
150
 
148
    VersionInfo.Hauptversion = VERSION_HAUPTVERSION;
151
    VersionInfo.Major = VERSION_MAJOR;
149
    VersionInfo.Nebenversion = VERSION_NEBENVERSION;
152
    VersionInfo.Minor = VERSION_MINOR;
150
    VersionInfo.PCKompatibel = VERSION_KOMPATIBEL;
153
    VersionInfo.PCCompatible = VERSION_COMPATIBLE;
151
   
154
 
152
        printf("\n\rFlightControl\n\rHardware:%d.%d\n\rSoftware:V%d.%d%c ",PlatinenVersion/10,PlatinenVersion%10, VERSION_HAUPTVERSION, VERSION_NEBENVERSION,VERSION_INDEX + 'a');
155
        printf("\n\rFlightControl\n\rHardware:%d.%d\n\rSoftware:V%d.%d%c ",BoardRelease/10,BoardRelease%10, VERSION_MAJOR, VERSION_MINOR,VERSION_INDEX + 'a');
153
        printf("\n\r==============================");
156
        printf("\n\r==============================");
154
        GRN_ON;
157
        GRN_ON;
155
 
-
 
156
#define EE_DATENREVISION 70 // wird angepasst, wenn sich die EEPROM-Daten geändert haben
-
 
157
    if(eeprom_read_byte(&EEPromArray[EEPROM_ADR_VALID]) != EE_DATENREVISION)
-
 
158
        {
-
 
159
          printf("\n\rInit. EEPROM: Generiere Default-Parameter...");
158
 
160
          DefaultKonstanten1();
159
        // Parameter set handling
161
          for (unsigned char i=0;i<6;i++)  
-
 
162
      {
-
 
163
       if(i==2) DefaultKonstanten2(); // Kamera
-
 
164
       if(i==3) DefaultKonstanten3(); // Beginner
-
 
165
       if(i>3)  DefaultKonstanten2(); // Kamera
-
 
166
       WriteParameterSet(i, (unsigned char *) &EE_Parameter.Kanalbelegung[0], STRUCT_PARAM_LAENGE);
-
 
167
      }
-
 
168
          eeprom_write_byte(&EEPromArray[EEPROM_ADR_ACTIVE_SET], 3); // default-Setting
-
 
169
          eeprom_write_byte(&EEPromArray[EEPROM_ADR_VALID], EE_DATENREVISION);
-
 
170
        }
160
        ParamSet_Init();
171
 
161
 
172
    if(eeprom_read_byte(&EEPromArray[EEPROM_ADR_ACC_NICK]) > 4)
162
    if(GetParamWord(PID_ACC_PITCH) > 1023)
173
     {
163
     {
174
       printf("\n\rACC nicht abgeglichen!");
164
       printf("\n\rACC not calibrated!");
175
     }
165
     }
-
 
166
 
-
 
167
        //wait for a short time (otherwise the RC channel check won't work below)
-
 
168
        timer = SetDelay(500);
-
 
169
        while(!CheckDelay(timer));
-
 
170
 
176
       
171
 
-
 
172
        #if !defined (USE_KILLAGREG) && !defined (USE_NAVICTRL)
177
        ReadParameterSet(GetActiveParamSetNumber(), (unsigned char *) &EE_Parameter.Kanalbelegung[0], STRUCT_PARAM_LAENGE);
173
        printf("\n\rSupport for MK3MAG Compass");
178
    printf("\n\rBenutze Parametersatz %d", GetActiveParamSetNumber());
174
        #endif
179
 
175
 
180
   
176
 
181
        if(EE_Parameter.GlobalConfig & CFG_HOEHENREGELUNG)
177
        if(ParamSet.GlobalConfig & CFG_HEIGHT_CONTROL)
182
         {
178
         {
183
           printf("\n\rAbgleich Luftdrucksensor..");
179
           printf("\n\rCalibrating air pressure sensor..");
184
           timer = SetDelay(1000);  
180
           timer = SetDelay(1000);
185
       SucheLuftruckOffset();
181
       SearchAirPressureOffset();
186
           while (!CheckDelay(timer));
182
           while (!CheckDelay(timer));
187
       printf("OK\n\r");
183
       printf("OK\n\r");
188
        }
184
        }
189
       
185
 
-
 
186
        #ifdef USE_KILLAGREG
-
 
187
        printf("\n\rSupport for MicroMag3 Compass");
-
 
188
        #if defined (__AVR_ATmega644P__)
-
 
189
        if(BoardRelease == 10)
-
 
190
        {
-
 
191
                printf("\n\rSupport for GPS at 1st UART");
-
 
192
        }
-
 
193
        else
-
 
194
        {
-
 
195
                printf("\n\rSupport for GPS at 2nd UART");
-
 
196
        }
-
 
197
        #else // (__AVR_ATmega644__)
-
 
198
                printf("\n\rSupport for GPS at 1st UART");
-
 
199
        #endif
-
 
200
        #endif
-
 
201
 
190
        SetNeutral();
202
        SetNeutral();
191
 
203
 
192
        ROT_OFF;
204
        ROT_OFF;
193
   
205
 
194
    beeptime = 2000;
206
    BeepTime = 2000;
195
    ExternControl.Digital[0] = 0x55;   
207
    ExternControl.Digital[0] = 0x55;
196
 
208
 
197
   
209
 
198
        printf("\n\rSteuerung: ");
210
        printf("\n\rControl: ");
199
        if (EE_Parameter.GlobalConfig & CFG_HEADING_HOLD) printf("HeadingHold");
211
        if (ParamSet.GlobalConfig & CFG_HEADING_HOLD) printf("HeadingHold");
200
        else printf("Neutral");
212
        else printf("Neutral");
201
       
213
 
202
        printf("\n\n\r");
214
        printf("\n\n\r");
203
               
215
 
204
    LcdClear();
216
    LCD_Clear();
-
 
217
 
205
    I2CTimeout = 5000;
218
    I2CTimeout = 5000;
206
    WinkelOut.Orientation = 1;
-
 
-
 
219
 
207
        while (1)
220
        while (1)
208
        {
221
        {
209
       
-
 
210
                if(UpdateMotor)      // ReglerIntervall
222
        if(UpdateMotor)      // control interval
211
            {
223
        {
212
                    UpdateMotor=0;
224
                        UpdateMotor=0; // reset Flag, is enabled every 2 ms by isr of timer0
213
//PORTD |= 0x08;
225
                        //PORTD |= (1<<PORTD4);
214
            if(WinkelOut.CalcState) CalMk3Mag();
-
 
215
            else MotorRegler();  
226
            MotorControl();
216
//PORTD &= ~0x08;
227
                        //PORTD &= ~(1<<PORTD4);
-
 
228
 
217
            SendMotorData();
229
                        SendMotorData();
-
 
230
 
218
            ROT_OFF;
231
            ROT_OFF;
-
 
232
 
219
            if(PcZugriff) PcZugriff--;
233
            if(PcAccess) PcAccess--;
220
             else
234
            else
221
              {
235
            {
222
               DubWiseKeys[0] = 0;
236
               DubWiseKeys[0] = 0;
223
               DubWiseKeys[1] = 0;
237
               DubWiseKeys[1] = 0;
224
                           ExternControl.Config = 0;
238
                           ExternControl.Config = 0;
225
               ExternStickNick = 0;
239
               ExternStickPitch= 0;
226
               ExternStickRoll = 0;
240
               ExternStickRoll = 0;
227
               ExternStickGier = 0;
241
               ExternStickYaw = 0;
228
              }
242
            }
229
            if(SenderOkay)  SenderOkay--;
-
 
-
 
243
 
230
            if(!I2CTimeout)
244
            if(!I2CTimeout)
-
 
245
            {
-
 
246
                                I2CTimeout = 5;
-
 
247
                                I2C_Reset();
-
 
248
                                if((BeepModulation == 0xFFFF) && MotorsOn)
-
 
249
                                {
-
 
250
                                        BeepTime = 10000; // 1 second
-
 
251
                                        BeepModulation = 0x0080;
-
 
252
                                }
-
 
253
                        }
-
 
254
                        else
-
 
255
                        {
-
 
256
                                I2CTimeout--;
-
 
257
                                ROT_OFF;
-
 
258
                        }
-
 
259
 
-
 
260
                        if(SIO_DEBUG && (!UpdateMotor || !MotorsOn))
-
 
261
                        {
-
 
262
                                USART0_TransmitTxData();
-
 
263
                                USART0_ProcessRxData();
-
 
264
                        }
-
 
265
                        else USART0_ProcessRxData();
-
 
266
 
-
 
267
                        if(CheckDelay(timer))
-
 
268
                        {
-
 
269
                if(UBat < ParamSet.LowVoltageWarning)
231
                {
270
                {
232
                 I2CTimeout = 5;
-
 
233
                 i2c_reset();
-
 
234
                  if((BeepMuster == 0xffff) && MotorenEin)
-
 
235
                   {
-
 
236
                    beeptime = 10000;
-
 
237
                    BeepMuster = 0x0080;
271
                                        if(BeepModulation == 0xFFFF)
238
                   }
-
 
239
                }
-
 
240
            else        
-
 
241
                {
-
 
242
                 I2CTimeout--;
-
 
243
                 ROT_OFF;
-
 
244
                }
-
 
245
            if(SIO_DEBUG && (!UpdateMotor || !MotorenEin))
-
 
246
              {
-
 
247
               DatenUebertragung();
-
 
248
               BearbeiteRxDaten();
-
 
249
              }
-
 
250
              else BearbeiteRxDaten();
-
 
251
         if(CheckDelay(timer))
-
 
252
            {
272
                                        {
253
            if(UBat < EE_Parameter.UnterspannungsWarnung)
-
 
254
                {    
-
 
255
                  if(BeepMuster == 0xffff)
-
 
256
                   {
-
 
257
                    beeptime = 6000;
273
                                                BeepTime = 6000; // 0.6 seconds
258
                    BeepMuster = 0x0300;
274
                        BeepModulation = 0x0300;
259
                   }
275
                                        }
260
                }
276
                }
-
 
277
                                #ifdef USE_NAVICTRL
261
/*           if(SendVersionToNavi)
278
                                SPI_StartTransmitPacket();
262
              {
279
                                SendSPI = 4;
263
               SPI_StartTransmitPacket(SPI_CMD_VERSION);//#
280
                                #endif
264
               SendVersionToNavi = 0;
281
                                timer = SetDelay(20); // every 20 ms
265
              }
282
            }
266
              else  SPI_StartTransmitPacket(SPI_CMD_VALUE);//#
-
 
267
*/
283
                }
268
             SPI_StartTransmitPacket();//#
-
 
269
 
284
 
270
             SendSPI = 4;
285
                #ifdef USE_NAVICTRL
271
                         timer = SetDelay(20);  
286
                if(!SendSPI)
272
            }
287
                {       // SendSPI is decremented in timer0.c with a rate of 9.765 kHz.
273
           //if(UpdateMotor) DebugOut.Analog[26]++;
288
                        // within the SPI_TransmitByte() routine the value is set to 4.
274
          }
289
                        // I.e. the SPI_TransmitByte() is called at a rate of 9.765 kHz/4= 2441.25 Hz,
-
 
290
                        // and therefore the time of transmission of a complete spi-packet (32 bytes) is 32*4/9.765 kHz = 13.1 ms.
275
     if(!SendSPI) { SPI_TransmitByte(); }
291
                        SPI_TransmitByte();
-
 
292
                }
-
 
293
                #endif
276
    }
294
    }
277
 return (1);
295
        return (1);
278
}
296
}
279
 
297
 
280
 
298