Subversion Repositories FlightCtrl

Rev

Rev 1612 | Rev 1801 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 1612 Rev 1775
Line 50... Line 50...
50
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
50
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
51
#include <avr/io.h>
51
#include <avr/io.h>
52
#include <stdlib.h>
52
#include <stdlib.h>
53
#include <inttypes.h>
53
#include <inttypes.h>
54
#include "timer0.h"
54
#include "timer0.h"
55
#include "rc.h"
55
// #include "rc.h"
-
 
56
#include "attitude.h"
56
#include "eeprom.h"
57
#include "eeprom.h"
57
#include "mk3mag.h"
58
#include "mk3mag.h"
Line 58... Line 59...
58
 
59
 
59
uint8_t PWMTimeout = 12;
60
uint8_t PWMTimeout = 12;
Line 97... Line 98...
97
      PWMCount++;
98
      PWMCount++;
98
      // pwm overflow?
99
      // pwm overflow?
99
      if (PWMCount > 400)
100
      if (PWMCount > 400)
100
        {
101
        {
101
          if(PWMTimeout) PWMTimeout--; // decrement timeout
102
          if(PWMTimeout) PWMTimeout--; // decrement timeout
102
          CompassHeading = -1; // unknown heading
103
          compassHeading = -1; // unknown heading
103
          PWMCount = 0; // reset PWM Counter
104
          PWMCount = 0; // reset PWM Counter
104
        }
105
        }
Line 105... Line 106...
105
 
106
 
106
    }
107
    }
107
  else // pwm is low
108
  else // pwm is low
108
    {   // ignore pwm values values of 0 and higher than 37 ms;
109
    {   // ignore pwm values values of 0 and higher than 37 ms;
109
      if((PWMCount) && (PWMCount < 362)) // 362 * 102.4us = 37.0688 ms
110
      if((PWMCount) && (PWMCount < 362)) // 362 * 102.4us = 37.0688 ms
110
        {
111
        {
111
          if(PWMCount <10) CompassHeading = 0;
112
          if(PWMCount <10) compassHeading = 0;
112
          else CompassHeading = ((uint32_t)(PWMCount - 10) * 1049L)/1024; // correct timebase and offset
113
          else compassHeading = ((uint32_t)(PWMCount - 10) * 1049L)/1024; // correct timebase and offset
113
          CompassOffCourse = ((540 + CompassHeading - CompassCourse) % 360) - 180;
114
          compassOffCourse = ((540 + compassHeading - compassCourse) % 360) - 180;
114
          PWMTimeout = 12; // if 12 periodes long no valid PWM was detected the data are invalid
115
          PWMTimeout = 12; // if 12 periodes long no valid PWM was detected the data are invalid
115
          // 12 * 362 counts * 102.4 us
116
          // 12 * 362 counts * 102.4 us
116
        }
117
        }
117
      PWMCount = 0; // reset pwm counter
118
      PWMCount = 0; // reset pwm counter