auto-sync

This commit is contained in:
rusEfi 2014-11-11 08:03:18 -06:00
parent 6593f7573d
commit 703fd24d18
4 changed files with 13 additions and 12 deletions

View File

@ -32,9 +32,9 @@ void Engine::updateSlowSensors() {
engineState.clt = getCoolantTemperature(this); engineState.clt = getCoolantTemperature(this);
} }
void Engine::onTriggerEvent(uint64_t nowUs) { void Engine::onTriggerEvent(uint64_t nowNt) {
isSpinning = true; isSpinning = true;
lastTriggerEventTimeUs = nowUs; lastTriggerEventTimeNt = nowNt;
} }
Engine::Engine() { Engine::Engine() {
@ -76,7 +76,7 @@ void Engine::watchdog() {
} }
return; return;
} }
uint64_t nowUs = getTimeNowUs(); uint64_t nowNt = getTimeNowNt();
/** /**
* Lowest possible cranking is about 240 RPM, that's 4 revolutions per second. * Lowest possible cranking is about 240 RPM, that's 4 revolutions per second.
* 0.25 second is 250000 uS * 0.25 second is 250000 uS
@ -84,7 +84,7 @@ void Engine::watchdog() {
* todo: better watch dog implementation should be implemented - see * todo: better watch dog implementation should be implemented - see
* http://sourceforge.net/p/rusefi/tickets/96/ * http://sourceforge.net/p/rusefi/tickets/96/
*/ */
if (nowUs - lastTriggerEventTimeUs < 250000) { if (nowNt - lastTriggerEventTimeNt < US2NT(250000LL)) {
return; return;
} }
isSpinning = false; isSpinning = false;

View File

@ -35,9 +35,9 @@ public:
Thermistor iat; Thermistor iat;
Thermistor clt; Thermistor clt;
void onTriggerEvent(uint64_t nowUs); void onTriggerEvent(uint64_t nowNt);
EngineState engineState; EngineState engineState;
uint64_t lastTriggerEventTimeUs; uint64_t lastTriggerEventTimeNt;
/** /**
* This coefficient translates ADC value directly into voltage adjusted according to * This coefficient translates ADC value directly into voltage adjusted according to

View File

@ -29,7 +29,7 @@ WaveChart waveChart;
static histogram_s triggerCallback; static histogram_s triggerCallback;
// we need this initial to have not_running at first invocation // we need this initial to have not_running at first invocation
static volatile uint64_t previousShaftEventTime = (efitimems_t) -10 * US_PER_SECOND; static volatile uint64_t previousShaftEventTimeNt = (efitimems_t) -10 * US2NT(US_PER_SECOND_LL);
TriggerCentral triggerCentral; TriggerCentral triggerCentral;
@ -98,12 +98,13 @@ static void reportEventToWaveChart(trigger_event_e ckpSignalType, int index) {
void TriggerCentral::handleShaftSignal(Engine *engine, trigger_event_e signal) { void TriggerCentral::handleShaftSignal(Engine *engine, trigger_event_e signal) {
efiAssertVoid(engine!=NULL, "configuration"); efiAssertVoid(engine!=NULL, "configuration");
uint64_t nowUs = getTimeNowUs(); uint64_t nowNt = getTimeNowNt();
uint64_t nowUs = NT2US(nowNt);
efiAssertVoid(engine->engineConfiguration!=NULL, "engineConfiguration"); efiAssertVoid(engine->engineConfiguration!=NULL, "engineConfiguration");
efiAssertVoid(engine->engineConfiguration2!=NULL, "engineConfiguration2"); efiAssertVoid(engine->engineConfiguration2!=NULL, "engineConfiguration2");
engine->onTriggerEvent(nowUs); engine->onTriggerEvent(nowNt);
#if EFI_HISTOGRAMS && EFI_PROD_CODE #if EFI_HISTOGRAMS && EFI_PROD_CODE
int beforeCallback = hal_lld_get_counter_value(); int beforeCallback = hal_lld_get_counter_value();
@ -112,14 +113,14 @@ void TriggerCentral::handleShaftSignal(Engine *engine, trigger_event_e signal) {
efiAssertVoid(eventIndex >= 0 && eventIndex < HW_EVENT_TYPES, "signal type"); efiAssertVoid(eventIndex >= 0 && eventIndex < HW_EVENT_TYPES, "signal type");
hwEventCounters[eventIndex]++; hwEventCounters[eventIndex]++;
if (nowUs - previousShaftEventTime > US_PER_SECOND) { if (nowNt - previousShaftEventTimeNt > US2NT(US_PER_SECOND_LL)) {
/** /**
* We are here if there is a time gap between now and previous shaft event - that means the engine is not runnig. * We are here if there is a time gap between now and previous shaft event - that means the engine is not runnig.
* That means we have lost synchronization since the engine is not running :) * That means we have lost synchronization since the engine is not running :)
*/ */
triggerState.shaft_is_synchronized = false; triggerState.shaft_is_synchronized = false;
} }
previousShaftEventTime = nowUs; previousShaftEventTimeNt = nowNt;
trigger_shape_s * triggerShape = &engine->engineConfiguration2->triggerShape; trigger_shape_s * triggerShape = &engine->engineConfiguration2->triggerShape;

View File

@ -252,5 +252,5 @@ void firmwareError(const char *fmt, ...) {
} }
int getRusEfiVersion(void) { int getRusEfiVersion(void) {
return 20141110; return 20141111;
} }