diff --git a/firmware/config/engines/bmw_e34.cpp b/firmware/config/engines/bmw_e34.cpp index 4133f846a6..da6a388be7 100644 --- a/firmware/config/engines/bmw_e34.cpp +++ b/firmware/config/engines/bmw_e34.cpp @@ -65,6 +65,8 @@ void setBmwE34(DECLARE_ENGINE_PARAMETER_F) { setConstantDwell(3 PASS_ENGINE_PARAMETER); // a bit shorter dwell engineConfiguration->ignMathCalculateAtIndex = 14; + engineConfiguration->mapAveragingSchedulingAtIndex = 6; + // Cranking engineConfiguration->cranking.rpm = 600; engineConfiguration->crankingInjectionMode = IM_BATCH; diff --git a/firmware/controllers/algo/engine_configuration_generated_structures.h b/firmware/controllers/algo/engine_configuration_generated_structures.h index 33ecf85d3a..4b48882940 100644 --- a/firmware/controllers/algo/engine_configuration_generated_structures.h +++ b/firmware/controllers/algo/engine_configuration_generated_structures.h @@ -1,4 +1,4 @@ -// this section was generated by config_definition.jar on Wed Apr 15 12:11:02 EDT 2015 +// this section was generated by config_definition.jar on Sat Apr 18 18:59:21 EDT 2015 // begin #include "rusefi_types.h" typedef struct { @@ -1099,7 +1099,11 @@ typedef struct { /** * offset 1648 */ - int unused3[134]; + int mapAveragingSchedulingAtIndex; + /** + * offset 1652 + */ + int unused3[133]; /** * offset 2184 */ @@ -1279,4 +1283,4 @@ typedef struct { } persistent_config_s; // end -// this section was generated by config_definition.jar on Wed Apr 15 12:11:02 EDT 2015 +// this section was generated by config_definition.jar on Sat Apr 18 18:59:21 EDT 2015 diff --git a/firmware/controllers/map_averaging.cpp b/firmware/controllers/map_averaging.cpp index c10b870dd6..21bd4a43cd 100644 --- a/firmware/controllers/map_averaging.cpp +++ b/firmware/controllers/map_averaging.cpp @@ -32,6 +32,7 @@ #include "interpolation.h" #include "signal_executor.h" #include "engine.h" +#include "engine_math.h" #if EFI_ANALOG_CHART #include "analog_chart.h" @@ -168,7 +169,7 @@ static void endAveraging(void *arg) { static void mapAveragingCallback(trigger_event_e ckpEventType, uint32_t index DECLARE_ENGINE_PARAMETER_S) { // this callback is invoked on interrupt thread engine->m.beforeMapAveragingCb = GET_TIMESTAMP(); - if (index != 0) + if (index != engineConfiguration->mapAveragingSchedulingAtIndex) return; int rpm = engine->rpmCalculator.rpmValue; @@ -180,17 +181,23 @@ static void mapAveragingCallback(trigger_event_e ckpEventType, uint32_t index DE MAP_sensor_config_s * config = &engineConfiguration->map; - angle_t samplingStart = interpolate2d(rpm, config->samplingAngleBins, config->samplingAngle, MAP_ANGLE_SIZE); + angle_t currentAngle = TRIGGER_SHAPE(eventAngles[index]); + + angle_t samplingStart = interpolate2d(rpm, config->samplingAngleBins, config->samplingAngle, MAP_ANGLE_SIZE) - currentAngle; angle_t samplingDuration = interpolate2d(rpm, config->samplingWindowBins, config->samplingWindow, MAP_WINDOW_SIZE); if (samplingDuration <= 0) { firmwareError("map sampling angle should be positive"); return; } + fixAngle(samplingStart); + + angle_t samplingEnd = samplingStart + samplingDuration; + fixAngle(samplingEnd); 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], samplingStart + samplingDuration, endAveraging, NULL, &engine->rpmCalculator); + scheduleByAngle(rpm, &endTimer[structIndex], samplingEnd, endAveraging, NULL, &engine->rpmCalculator); engine->m.mapAveragingCbTime = GET_TIMESTAMP() - engine->m.beforeMapAveragingCb; } diff --git a/firmware/integration/rusefi_config.txt b/firmware/integration/rusefi_config.txt index 46b8b30d4d..a280552425 100644 --- a/firmware/integration/rusefi_config.txt +++ b/firmware/integration/rusefi_config.txt @@ -487,7 +487,10 @@ custom pin_input_mode_e 4 scalar, F32, @OFFSET@, "ms", 1, 0, 0, 200, 1 brain_pin_e stepperEnablePin; float noAccelAfterHardLimitPeriodSecs;;"sec", 1, 0, 0, 60, 0 - int[134] unused3; + +int mapAveragingSchedulingAtIndex; + + int[133] unused3; int tpsAccelLength;;"len", 1, 0, 1, 200, 3 float tpsAccelEnrichmentThreshold;;"roc", 1, 0, 0, 200, 3 diff --git a/java_console/autotest/src/com/rusefi/AutoTest.java b/java_console/autotest/src/com/rusefi/AutoTest.java index bdbff3d0db..d59b61ca17 100644 --- a/java_console/autotest/src/com/rusefi/AutoTest.java +++ b/java_console/autotest/src/com/rusefi/AutoTest.java @@ -62,6 +62,8 @@ public class AutoTest { x = 688.464; assertWave(msg, chart, WaveChart.SPARK_1, 0.0597999999, x, x + 180, x + 360, x + 540); + + assertWave(msg, chart, WaveChart.MAP_AVERAGING, 0.139, 17.784); } private static void testMitsu() { diff --git a/java_console/models/src/com/rusefi/waves/WaveChart.java b/java_console/models/src/com/rusefi/waves/WaveChart.java index a7340d0f01..b09d868f6b 100644 --- a/java_console/models/src/com/rusefi/waves/WaveChart.java +++ b/java_console/models/src/com/rusefi/waves/WaveChart.java @@ -29,6 +29,7 @@ public class WaveChart { public static final String TRIGGER_1 = "t1"; public static final String TRIGGER_2 = "t2"; + public static final String MAP_AVERAGING = "map"; public final Map map;