87,9 → 87,13 |
// in other words 100us/° with a +1ms offset. |
// The signal goes low for 65ms between pulses, |
// so the cycle time is 65mS + the pulse width. |
|
// pwm is high |
|
if (debugCounter++ == 5000) { |
DebugOut.Digital[0] ^= DEBUG_MK3MAG; |
debugCounter = 0; |
} |
|
if (PINC & (1 << PINC4)) { |
// If PWM signal is high increment PWM high counter |
// This counter is incremented by a periode of 102.4us, |
103,26 → 107,34 |
PWMCount = 0; // reset PWM Counter |
} |
} else { // pwm is low |
// ignore pwm values values of 0 and higher than 37 ms; |
// 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 |
else { |
compassHeading = ((uint32_t) (PWMCount - 10) * 1049L) / 1024; // correct timebase and offset |
compassOffCourse = ((540 + compassHeading - compassCourse) % 360) - 180; |
DebugOut.Digital[1] ^= DEBUG_MK3MAG; // correct signal recd. |
} |
/* |
compassHeading - compassCourse on a -180..179 range. |
compassHeading 20 compassCourse 30 --> ((540 - 10)%360) - 180 = -10 |
compassHeading 30 compassCourse 20 --> ((540 + 10)%360) - 180 = 10 |
compassHeading 350 compassCourse 10 --> ((540 + 340)%360) - 180 = -20 |
compassHeading 10 compassCourse 350 --> ((540 - 340)%360) - 180 = 20 |
*/ |
//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 |
} |
PWMCount = 0; // reset pwm counter |
DebugOut.Digital[0] ^= DEBUG_MK3MAG; |
DebugOut.Digital[1] &= ~DEBUG_MK3MAG; |
} if (!PWMTimeout) { |
} |
if (!PWMTimeout) { |
if (CheckDelay(BeepDelay)) { |
if (!BeepTime) |
BeepTime = 100; // make noise with 10Hz to signal the compass problem |
BeepDelay = SetDelay(100); |
DebugOut.Digital[1] |= DEBUG_MK3MAG; |
} |
} |
} |
|
|