Subversion Repositories FlightCtrl

Rev

Rev 2035 | Rev 2052 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 2035 Rev 2036
Line 1... Line -...
1
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
-
 
2
// + Copyright (c) 04.2007 Holger Buss
-
 
3
// + Nur f�r den privaten Gebrauch
-
 
4
// + www.MikroKopter.com
-
 
5
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
-
 
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.
-
 
8
// + Sollten direkte oder indirekte kommerzielle Absichten verfolgt werden, ist mit uns (info@mikrokopter.de) Kontakt
-
 
9
// + bzgl. der Nutzungsbedingungen aufzunehmen.
-
 
10
// + Eine kommerzielle Nutzung ist z.B.Verkauf von MikroKoptern, Best�ckung und Verkauf von Platinen oder Baus�tzen,
-
 
11
// + Verkauf von Luftbildaufnahmen, usw.
-
 
12
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
-
 
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
-
 
15
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
-
 
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"
-
 
18
// + eindeutig als Ursprung verlinkt und genannt werden
-
 
19
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
-
 
20
// + Keine Gew�hr auf Fehlerfreiheit, Vollst�ndigkeit oder Funktion
-
 
21
// + Benutzung auf eigene Gefahr
-
 
22
// + Wir �bernehmen keinerlei Haftung f�r direkte oder indirekte Personen- oder Sachsch�den
-
 
23
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
-
 
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
-
 
26
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
-
 
27
// + Die Funktion printf_P() unterliegt ihrer eigenen Lizenz und ist hiervon nicht betroffen
-
 
28
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
-
 
29
// + Redistributions of source code (with or without modifications) must retain the above copyright notice,
-
 
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
-
 
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
-
 
34
// +     for non-commercial use (directly or indirectly)
-
 
35
// +     Commercial use (for example: selling of MikroKopters, selling of PCBs, assembly, ...) is only permitted
-
 
36
// +     with our written permission
-
 
37
// +   * If sources or documentations are redistributet on other webpages, out webpage (http://www.MikroKopter.de) must be
-
 
38
// +     clearly linked as origin
-
 
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"
-
 
41
// +  AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
-
 
42
// +  IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
-
 
43
// +  ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
-
 
44
// +  LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
-
 
45
// +  CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
-
 
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
-
 
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
-
 
50
// +  POSSIBILITY OF SUCH DAMAGE.
-
 
51
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
-
 
52
#include <avr/io.h>
1
#include <avr/io.h>
53
#include <avr/interrupt.h>
2
#include <avr/interrupt.h>
54
#include <avr/pgmspace.h>
3
#include <avr/pgmspace.h>
Line 55... Line 4...
55
 
4
 
Line 174... Line 123...
174
 
123
 
175
// Value of AIRPRESSURE_OVERSAMPLING samples, with range, filtered.
124
// Value of AIRPRESSURE_OVERSAMPLING samples, with range, filtered.
176
int32_t filteredAirPressure;
125
int32_t filteredAirPressure;
Line 177... Line 126...
177
int32_t lastFilteredAirPressure;
126
int32_t lastFilteredAirPressure;
178
 
127
 
179
#define MAX_AIRPRESSURE_WINDOW_LENGTH 64
128
#define MAX_AIRPRESSURE_WINDOW_LENGTH 32
180
int16_t airPressureWindow[MAX_AIRPRESSURE_WINDOW_LENGTH];
129
int16_t airPressureWindow[MAX_AIRPRESSURE_WINDOW_LENGTH];
Line 181... Line 130...
181
int32_t windowedAirPressure;
130
int32_t windowedAirPressure;
Line 273... Line 222...
273
        ADCSRB &= ~((1<<ADTS2)|(1<<ADTS1)|(1<<ADTS0));
222
        ADCSRB &= ~((1<<ADTS2)|(1<<ADTS1)|(1<<ADTS0));
Line 274... Line 223...
274
 
223
 
275
        for (uint8_t i=0; i<MAX_AIRPRESSURE_WINDOW_LENGTH; i++) {
224
        for (uint8_t i=0; i<MAX_AIRPRESSURE_WINDOW_LENGTH; i++) {
276
          airPressureWindow[i] = 0;
225
          airPressureWindow[i] = 0;
277
        }
-
 
278
 
226
        }
Line 279... Line 227...
279
        windowedAirPressure = 0;
227
    windowedAirPressure = 0;
Line 280... Line 228...
280
 
228
 
Line 511... Line 459...
511
      // The best oversampling count is 14.5. We add a quarter of the double ADC value to get the final half.
459
      // The best oversampling count is 14.5. We add a quarter of the double ADC value to get the final half.
512
      airPressureSum += simpleAirPressure >> 2;
460
      airPressureSum += simpleAirPressure >> 2;
Line 513... Line 461...
513
 
461
 
Line -... Line 462...
-
 
462
      lastFilteredAirPressure = filteredAirPressure;
514
      lastFilteredAirPressure = filteredAirPressure;
463
 
515
 
464
 
516
      if (!staticParams.airpressureWindowLength) {
465
      if (!staticParams.airpressureWindowLength) {
517
          filteredAirPressure = (filteredAirPressure * (staticParams.airpressureFilterConstant - 1)
466
          filteredAirPressure = (filteredAirPressure * (staticParams.airpressureFilterConstant - 1)
518
                          + airPressureSum + staticParams.airpressureFilterConstant / 2) / staticParams.airpressureFilterConstant;
467
                          + airPressureSum + staticParams.airpressureFilterConstant / 2) / staticParams.airpressureFilterConstant;
519
      } else {
-
 
520
          // use windowed.
-
 
521
          filteredAirPressure = windowedAirPressure / staticParams.airpressureWindowLength;
-
 
522
      }
-
 
523
      pressureMeasurementCount = airPressureSum = 0;
-
 
524
    }
-
 
525
    //int16_t airPressureWindow[MAX_AIRPRESSURE_WINDOW_LENGTH];
-
 
526
    //int32_t windowedAirPressure = 0;
468
      } else {
527
    //uint8_t windowPtr;
469
          // use windowed.
528
    windowedAirPressure += simpleAirPressure;
470
          windowedAirPressure += simpleAirPressure;
529
    windowedAirPressure -= airPressureWindow[windowPtr];
471
          windowedAirPressure -= airPressureWindow[windowPtr];
-
 
472
          airPressureWindow[windowPtr] = simpleAirPressure;
-
 
473
          windowPtr = (windowPtr+1) % staticParams.airpressureWindowLength;
-
 
474
          filteredAirPressure = windowedAirPressure / staticParams.airpressureWindowLength;
-
 
475
      }
-
 
476
 
530
    airPressureWindow[windowPtr] = simpleAirPressure;
477
      pressureMeasurementCount = airPressureSum = 0;
531
    windowPtr = (windowPtr+1) % staticParams.airpressureWindowLength;
478
    }
Line 532... Line 479...
532
  }
479
  }
533
}
480
}