Subversion Repositories FlightCtrl

Compare Revisions

Ignore whitespace Rev 1774 → Rev 1775

/branches/dongfang_FC_rewrite/mk3mag.c
52,7 → 52,8
#include <stdlib.h>
#include <inttypes.h>
#include "timer0.h"
#include "rc.h"
// #include "rc.h"
#include "attitude.h"
#include "eeprom.h"
#include "mk3mag.h"
 
99,7 → 100,7
if (PWMCount > 400)
{
if(PWMTimeout) PWMTimeout--; // decrement timeout
CompassHeading = -1; // unknown heading
compassHeading = -1; // unknown heading
PWMCount = 0; // reset PWM Counter
}
 
108,9 → 109,9
{ // ignore pwm values values of 0 and higher than 37 ms;
if((PWMCount) && (PWMCount < 362)) // 362 * 102.4us = 37.0688 ms
{
if(PWMCount <10) CompassHeading = 0;
else CompassHeading = ((uint32_t)(PWMCount - 10) * 1049L)/1024; // correct timebase and offset
CompassOffCourse = ((540 + CompassHeading - CompassCourse) % 360) - 180;
if(PWMCount <10) compassHeading = 0;
else compassHeading = ((uint32_t)(PWMCount - 10) * 1049L)/1024; // correct timebase and offset
compassOffCourse = ((540 + compassHeading - compassCourse) % 360) - 180;
PWMTimeout = 12; // if 12 periodes long no valid PWM was detected the data are invalid
// 12 * 362 counts * 102.4 us
}