auto-sync

This commit is contained in:
rusEfi 2015-09-06 23:01:28 -04:00
parent 8ff2f31293
commit 849556d02b
2 changed files with 36 additions and 29 deletions

View File

@ -208,7 +208,7 @@ static void periodicFastCallback(DECLARE_ENGINE_PARAMETER_F) {
for (int i = 0; i < engineConfiguration->specs.cylindersCount; i++) { for (int i = 0; i < engineConfiguration->specs.cylindersCount; i++) {
angle_t cylinderOffset = engineConfiguration->engineCycle * i / engineConfiguration->specs.cylindersCount; angle_t cylinderOffset = engineConfiguration->engineCycle * i / engineConfiguration->specs.cylindersCount;
float cylinderStart = start + cylinderOffset - offsetAngle; float cylinderStart = start + cylinderOffset - offsetAngle + tdcPosition();
fixAngle(cylinderStart); fixAngle(cylinderStart);
engine->engineState.mapAveragingStart[i] = cylinderStart; engine->engineState.mapAveragingStart[i] = cylinderStart;
} }

View File

@ -60,7 +60,6 @@ static int readIndex = 0;
static float accumulators[2]; static float accumulators[2];
static int counters[2]; static int counters[2];
/** /**
* Running MAP accumulator * Running MAP accumulator
*/ */
@ -75,10 +74,11 @@ static volatile int mapMeasurementsCounter = 0;
*/ */
static float v_averagedMapValue; static float v_averagedMapValue;
EXTERN_ENGINE; EXTERN_ENGINE
;
static scheduling_s startTimer[2]; static scheduling_s startTimer[INJECTION_PIN_COUNT][2];
static scheduling_s endTimer[2]; static scheduling_s endTimer[INJECTION_PIN_COUNT][2];
/** /**
* that's a performance optimization: let's not bother averaging * that's a performance optimization: let's not bother averaging
@ -116,13 +116,15 @@ void mapAveragingCallback(adcsample_t adcValue) {
measurementsPerRevolutionCounter++; measurementsPerRevolutionCounter++;
efiAssertVoid(getRemainingStack(chThdSelf()) > 128, "lowstck#9a"); efiAssertVoid(getRemainingStack(chThdSelf()) > 128, "lowstck#9a");
#if (EFI_ANALOG_CHART && EFI_ANALOG_SENSORS) || defined(__DOXYGEN__) #if (EFI_ANALOG_CHART && EFI_ANALOG_SENSORS) || defined(__DOXYGEN__)
if (boardConfiguration->sensorChartMode == SC_MAP) { if (boardConfiguration->sensorChartMode == SC_MAP) {
if (measurementsPerRevolutionCounter % FAST_MAP_CHART_SKIP_FACTOR == 0) { if (measurementsPerRevolutionCounter % FAST_MAP_CHART_SKIP_FACTOR
== 0) {
float voltage = adcToVoltsDivided(adcValue); float voltage = adcToVoltsDivided(adcValue);
float currentPressure = getMapByVoltage(voltage); float currentPressure = getMapByVoltage(voltage);
scAddData(getCrankshaftAngleNt(getTimeNowNt() PASS_ENGINE_PARAMETER), currentPressure); scAddData(
getCrankshaftAngleNt(getTimeNowNt() PASS_ENGINE_PARAMETER),
currentPressure);
} }
} }
#endif /* EFI_ANALOG_CHART */ #endif /* EFI_ANALOG_CHART */
@ -156,7 +158,8 @@ static void endAveraging(void *arg) {
isAveraging = false; isAveraging = false;
// with locking we would have a consistent state // with locking we would have a consistent state
#if EFI_PROD_CODE || defined(__DOXYGEN__) #if EFI_PROD_CODE || defined(__DOXYGEN__)
v_averagedMapValue = adcToVoltsDivided(mapAccumulator / mapMeasurementsCounter); v_averagedMapValue = adcToVoltsDivided(
mapAccumulator / mapMeasurementsCounter);
#endif #endif
if (!wasLocked) if (!wasLocked)
chSysUnlockFromIsr() chSysUnlockFromIsr()
@ -167,9 +170,10 @@ static void endAveraging(void *arg) {
/** /**
* Shaft Position callback used to schedule start and end of MAP averaging * Shaft Position callback used to schedule start and end of MAP averaging
*/ */
static void mapAveragingCallback(trigger_event_e ckpEventType, uint32_t index DECLARE_ENGINE_PARAMETER_S) { static void mapAveragingCallback(trigger_event_e ckpEventType,
uint32_t index DECLARE_ENGINE_PARAMETER_S) {
// this callback is invoked on interrupt thread // this callback is invoked on interrupt thread
UNUSED(ckpEventType); UNUSED(ckpEventType);
engine->m.beforeMapAveragingCb = GET_TIMESTAMP(); engine->m.beforeMapAveragingCb = GET_TIMESTAMP();
if (index != CONFIG(mapAveragingSchedulingAtIndex)) if (index != CONFIG(mapAveragingSchedulingAtIndex))
return; return;
@ -181,27 +185,30 @@ static void mapAveragingCallback(trigger_event_e ckpEventType, uint32_t index DE
measurementsPerRevolution = measurementsPerRevolutionCounter; measurementsPerRevolution = measurementsPerRevolutionCounter;
measurementsPerRevolutionCounter = 0; measurementsPerRevolutionCounter = 0;
angle_t samplingStart = ENGINE(engineState.mapAveragingStart[0]); for (int i = 0; i < engineConfiguration->specs.cylindersCount; i++) {
fixAngle(samplingStart); angle_t samplingStart = ENGINE(engineState.mapAveragingStart[i]);
angle_t samplingDuration = ENGINE(engineState.mapAveragingDuration); angle_t samplingDuration = ENGINE(engineState.mapAveragingDuration);
if (samplingDuration <= 0) { if (samplingDuration <= 0) {
firmwareError("map sampling angle should be positive"); firmwareError("map sampling angle should be positive");
return; return;
}
angle_t samplingEnd = samplingStart + samplingDuration;
fixAngle(samplingEnd);
if (!cisnan(samplingEnd)) {
// only if value is already prepared
int structIndex = getRevolutionCounter() % 2;
// todo: schedule this based on closest trigger event, same as ignition works
scheduleByAngle(rpm, &startTimer[i][structIndex], samplingStart,
startAveraging, NULL, &engine->rpmCalculator);
scheduleByAngle(rpm, &endTimer[i][structIndex], samplingEnd,
endAveraging, NULL, &engine->rpmCalculator);
engine->m.mapAveragingCbTime = GET_TIMESTAMP()
- engine->m.beforeMapAveragingCb;
}
} }
angle_t samplingEnd = samplingStart + samplingDuration;
fixAngle(samplingEnd);
if (cisnan(samplingEnd)) {
// value is not yet prepared
return;
}
int structIndex = getRevolutionCounter() % 2;
// todo: schedule this based on closest trigger event, same as ignition works
scheduleByAngle(rpm, &startTimer[structIndex], samplingStart, startAveraging, NULL, &engine->rpmCalculator);
scheduleByAngle(rpm, &endTimer[structIndex], samplingEnd, endAveraging, NULL, &engine->rpmCalculator);
engine->m.mapAveragingCbTime = GET_TIMESTAMP() - engine->m.beforeMapAveragingCb;
} }
static void showMapStats(void) { static void showMapStats(void) {