Subversion Repositories FlightCtrl

Compare Revisions

Ignore whitespace Rev 2039 → Rev 2041

/branches/dongfang_FC_rewrite/mk3mag.c
80,7 → 80,7
void MK3MAG_periodicTask(void) {// called every 102.4 us by timer 0 ISR
static uint16_t PWMCount = 0;
static uint16_t beepDelay = 0;
static uint16_t debugCounter = 0;
// static uint16_t debugCounter = 0;
// The pulse width varies from 1ms (0°) to 36.99ms (359.9°)
// in other words 100us/° with a +1ms offset.
// The signal goes low for 65ms between pulses,
87,10 → 87,10
// so the cycle time is 65mS + the pulse width.
// pwm is high
 
if (debugCounter++ == 5000) {
// DebugOut.Digital[0] ^= DEBUG_MK3MAG;
debugCounter = 0;
}
// if (debugCounter++ == 5000) {
// DebugOut.Digital[0] ^= DEBUG_MK3MAG;
// debugCounter = 0;
// }
 
if (PINC & (1 << PINC4)) {
// If PWM signal is high increment PWM high counter
101,7 → 101,7
if (PWMCount > 400) {
if (PWMTimeout)
PWMTimeout--; // decrement timeout
compassHeading = -1; // unknown heading
magneticHeading = -1; // unknown heading
PWMCount = 0; // reset PWM Counter
}
} else { // pwm is low
108,9 → 108,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;
magneticHeading = 0;
else {
compassHeading = ((uint32_t) (PWMCount - 10) * 1049L) / 1024; // correct timebase and offset
magneticHeading = ((uint32_t) (PWMCount - 10) * 1049L) / 1024; // correct timebase and offset
//DebugOut.Digital[1] ^= DEBUG_MK3MAG; // correct signal recd.
}
/*
126,10 → 126,11
}
PWMCount = 0; // reset pwm counter
}
 
if (!PWMTimeout) {
if (checkDelay(beepDelay)) {
if (!beepTime)
beepTime = 100; // make noise with 10Hz to signal the compass problem
beep(100); // make noise with 10Hz to signal the compass problem
beepDelay = setDelay(100);
}
}