Subversion Repositories FlightCtrl

Rev

Rev 304 | Rev 401 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
1 ingob 1
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2
// + Copyright (c) 04.2007 Holger Buss
3
// + only for non-profit use
4
// + www.MikroKopter.com
5
// + see the File "License.txt" for further Informations
6
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
7
 
8
#include "main.h"
9
 
10
volatile int  Aktuell_Nick,Aktuell_Roll,Aktuell_Gier,Aktuell_ax, Aktuell_ay,Aktuell_az, UBat = 100;
380 hbuss 11
volatile int  AdWertNick = 0, AdWertRoll = 0, AdWertGier = 0;
12
volatile int  AdWertAccRoll = 0,AdWertAccNick = 0,AdWertAccHoch = 0;
1 ingob 13
volatile char MessanzahlNick = 0, MessanzahlRoll = 0, MessanzahlGier = 0;
14
volatile char messanzahl_AccNick = 0, messanzahl_AccRoll = 0, messanzahl_AccHoch = 0;
15
volatile long Luftdruck = 32000;
16
volatile int  StartLuftdruck;
17
volatile unsigned int  MessLuftdruck = 1023;
18
unsigned char DruckOffsetSetting;
19
volatile int HoeheD = 0;
20
volatile char messanzahl_Druck;
21
volatile int  tmpLuftdruck;
22
volatile unsigned int ZaehlMessungen = 0;
23
 
24
//#######################################################################################
25
//
26
void ADC_Init(void)
27
//#######################################################################################
28
{
29
    ADMUX = 0;//Referenz ist extern
30
    ADCSRA=(1<<ADEN)|(1<<ADSC)|(1<<ADATE)|(1<<ADPS2)|(1<<ADPS1)|(1<<ADPS0)|(1<<ADIE);
31
    //Free Running Mode, Division Factor 128, Interrupt on
32
}
33
 
34
void SucheLuftruckOffset(void)
35
{
36
 unsigned int off;
173 holgerb 37
 off = eeprom_read_byte(&EEPromArray[EEPROM_ADR_LAST_OFFSET]);
38
 if(off > 20) off -= 10;
39
 OCR0A = off;
380 hbuss 40
 Delay_ms_Mess(100);
173 holgerb 41
 if(MessLuftdruck < 850) off = 0;
42
 for(; off < 250;off++)
1 ingob 43
  {
44
  OCR0A = off;
380 hbuss 45
  Delay_ms_Mess(50);
1 ingob 46
  printf(".");  
47
  if(MessLuftdruck < 900) break;
48
  }
173 holgerb 49
 eeprom_write_byte(&EEPromArray[EEPROM_ADR_LAST_OFFSET], off);
50
 DruckOffsetSetting = off;
380 hbuss 51
 Delay_ms_Mess(300);
1 ingob 52
}
53
 
54
 
55
//#######################################################################################
56
//
57
SIGNAL(SIG_ADC)
58
//#######################################################################################
59
{
60
    static unsigned char kanal=0,state = 0;
61
    ANALOG_OFF;
62
    switch(state++)
63
        {
64
        case 0:
380 hbuss 65
            AdWertGier = ADC;
1 ingob 66
            kanal = 1;
67
            ZaehlMessungen++;
68
            break;
69
        case 1:
380 hbuss 70
            AdWertRoll = ADC;
1 ingob 71
            kanal = 2;
72
            break;
73
        case 2:
380 hbuss 74
            AdWertNick = ADC;
1 ingob 75
            kanal = 4;
76
            break;
77
        case 3:
78
            UBat = (3 * UBat + ADC / 3) / 4;//(UBat + ((ADC * 39) / 256) + 19)  / 2;
79
            kanal = 6;
80
            break;
81
        case 4:
82
            Aktuell_ay = NeutralAccY - ADC;
380 hbuss 83
            AdWertAccRoll = Aktuell_ay;
1 ingob 84
            kanal = 7;
85
            break;
86
        case 5:
128 ingob 87
            Aktuell_ax = ADC - NeutralAccX;
380 hbuss 88
            AdWertAccNick =  Aktuell_ax;
1 ingob 89
                    kanal = 5;
90
            break;
91
        case 6:
380 hbuss 92
            AdWertAccHoch =  (signed int) ADC - NeutralAccZ;
93
            AdWertAccHoch += abs(Aktuell_ay) / 4 + abs(Aktuell_ax) / 4;
94
            if(AdWertAccHoch > 1)
1 ingob 95
             {
96
              if(NeutralAccZ < 800) NeutralAccZ+= 0.02;
97
             }  
380 hbuss 98
             else if(AdWertAccHoch < -1)
1 ingob 99
             {
100
              if(NeutralAccZ > 600) NeutralAccZ-= 0.02;
101
             }
102
            messanzahl_AccHoch = 1;
103
            Aktuell_az = ADC;
380 hbuss 104
            Mess_Integral_Hoch += AdWertAccHoch;      // Integrieren
1 ingob 105
            Mess_Integral_Hoch -= Mess_Integral_Hoch / 1024; // dämfen
380 hbuss 106
                kanal = 3;
1 ingob 107
            break;
108
        case 7:
109
            tmpLuftdruck += ADC;
110
            if(++messanzahl_Druck >= 5)
111
                {
112
                MessLuftdruck = ADC;
113
                messanzahl_Druck = 0;
114
                                HoeheD = (int)(StartLuftdruck - tmpLuftdruck - HoehenWert);  // D-Anteil = neuerWert - AlterWert
115
                Luftdruck = (tmpLuftdruck + 3 * Luftdruck) / 4;
116
                HoehenWert = StartLuftdruck - Luftdruck;
117
                tmpLuftdruck = 0;
118
                }
119
            kanal = 0;
120
            state = 0;
121
            break;
122
        default:
123
            kanal = 0;
124
            state = 0;
125
            break;
126
        }
127
    ADMUX = kanal;
380 hbuss 128
    if(state != 0) ANALOG_ON;
1 ingob 129
}