From 00a0995823518bdce3a509fad94044211e5c6928 Mon Sep 17 00:00:00 2001 From: rusEfi Date: Sun, 31 Jan 2016 21:02:03 -0500 Subject: [PATCH] auto-sync --- firmware/console/status_loop.cpp | 2 +- firmware/controllers/sensors/tps.cpp | 15 +++++++++------ firmware/controllers/sensors/tps.h | 5 ++++- firmware/controllers/settings.cpp | 2 +- firmware/hw_layer/adc_inputs.cpp | 2 +- firmware/hw_layer/hardware.cpp | 4 ++-- firmware/rusefi.cpp | 2 +- unit_tests/test_sensors.cpp | 4 ++-- unit_tests/test_trigger_decoder.cpp | 11 ++++++----- 9 files changed, 27 insertions(+), 20 deletions(-) diff --git a/firmware/console/status_loop.cpp b/firmware/console/status_loop.cpp index 7dc435e51b..b9b5c07700 100644 --- a/firmware/console/status_loop.cpp +++ b/firmware/console/status_loop.cpp @@ -586,7 +586,7 @@ void updateTunerStudioState(TunerStudioOutputChannels *tsOutputChannels DECLARE_ if (hasVBatt(PASS_ENGINE_PARAMETER_F)) { tsOutputChannels->vBatt = getVBatt(PASS_ENGINE_PARAMETER_F); } - tsOutputChannels->tpsADC = getTPS10bitAdc(PASS_ENGINE_PARAMETER_F); + tsOutputChannels->tpsADC = getTPS12bitAdc(PASS_ENGINE_PARAMETER_F) / TPS_TS_CONVERSION; #if EFI_ANALOG_SENSORS || defined(__DOXYGEN__) tsOutputChannels->baroPressure = hasBaroSensor() ? getBaroPressure() : 0; #endif /* EFI_ANALOG_SENSORS */ diff --git a/firmware/controllers/sensors/tps.cpp b/firmware/controllers/sensors/tps.cpp index 6804354b40..bfd21afebb 100644 --- a/firmware/controllers/sensors/tps.cpp +++ b/firmware/controllers/sensors/tps.cpp @@ -20,7 +20,8 @@ */ static tps_roc_s states[2]; -int tpsFastAdc = 0; +// todo if TPS_FAST_ADC +//int tpsFastAdc = 0; static volatile int tpsRocIndex = 0; @@ -61,7 +62,7 @@ percent_t getTpsValue(int adc DECLARE_ENGINE_PARAMETER_S) { warning(OBD_PCM_Processor_Fault, "Invalid TPS configuration: same value %d", engineConfiguration->tpsMin); return NAN; } - float result = interpolate(engineConfiguration->tpsMin, 0, engineConfiguration->tpsMax, 100, adc); + float result = interpolate(TPS_TS_CONVERSION * engineConfiguration->tpsMin, 0, TPS_TS_CONVERSION * engineConfiguration->tpsMax, 100, adc); // this would put the value into the 0-100 range return maxF(0, minF(100, result)); } @@ -78,15 +79,17 @@ float getTPSVoltage(DECLARE_ENGINE_PARAMETER_F) { * We need ADC value because TunerStudio has a nice TPS configuration wizard, and this wizard * wants a TPS value. */ -int getTPS10bitAdc(DECLARE_ENGINE_PARAMETER_F) { +int getTPS12bitAdc(DECLARE_ENGINE_PARAMETER_F) { #if !EFI_PROD_CODE if (mockTps != MOCK_UNDEFINED) return mockTps; #endif - if(engineConfiguration->tpsAdcChannel==EFI_ADC_NONE) + if (engineConfiguration->tpsAdcChannel == EFI_ADC_NONE) return -1; #if EFI_PROD_CODE - return tpsFastAdc / 4; + + return getAdcValue("tps10", engineConfiguration->tpsAdcChannel); + // return tpsFastAdc / 4; #else return 0; #endif /* EFI_PROD_CODE */ @@ -96,7 +99,7 @@ int getTPS10bitAdc(DECLARE_ENGINE_PARAMETER_F) { * @brief Position on physical primary TPS */ static percent_t getPrimatyRawTPS(DECLARE_ENGINE_PARAMETER_F) { - percent_t tpsValue = getTpsValue(getTPS10bitAdc(PASS_ENGINE_PARAMETER_F) PASS_ENGINE_PARAMETER); + percent_t tpsValue = getTpsValue(getTPS12bitAdc(PASS_ENGINE_PARAMETER_F) PASS_ENGINE_PARAMETER); return tpsValue; } diff --git a/firmware/controllers/sensors/tps.h b/firmware/controllers/sensors/tps.h index 99ba9f7819..70fe6f95c7 100644 --- a/firmware/controllers/sensors/tps.h +++ b/firmware/controllers/sensors/tps.h @@ -13,6 +13,9 @@ #include "global.h" #include "engine_configuration.h" +// we have 12 bit precision and TS uses 10 bit precision +#define TPS_TS_CONVERSION 4 + bool hasPedalPositionSensor(DECLARE_ENGINE_PARAMETER_F); percent_t getPedalPosition(DECLARE_ENGINE_PARAMETER_F); /** @@ -22,7 +25,7 @@ percent_t getPedalPosition(DECLARE_ENGINE_PARAMETER_F); */ percent_t getTPS(DECLARE_ENGINE_PARAMETER_F); int convertVoltageTo10bitADC(float voltage); -int getTPS10bitAdc(DECLARE_ENGINE_PARAMETER_F); +int getTPS12bitAdc(DECLARE_ENGINE_PARAMETER_F); float getTPSVoltage(DECLARE_ENGINE_PARAMETER_F); percent_t getTpsValue(int adc DECLARE_ENGINE_PARAMETER_S); diff --git a/firmware/controllers/settings.cpp b/firmware/controllers/settings.cpp index 48e05679f0..ee87bae8e0 100644 --- a/firmware/controllers/settings.cpp +++ b/firmware/controllers/settings.cpp @@ -418,7 +418,7 @@ static void printTPSInfo(void) { scheduleMsg(&logger, "tps min %d/max %d v=%f @%s%d", engineConfiguration->tpsMin, engineConfiguration->tpsMax, getTPSVoltage(PASS_ENGINE_PARAMETER_F), portname(port), pin); #endif - scheduleMsg(&logger, "current 10bit=%d value=%f rate=%f", getTPS10bitAdc(), getTPS(PASS_ENGINE_PARAMETER_F), + scheduleMsg(&logger, "current 10bit=%d value=%f rate=%f", getTPS12bitAdc() / TPS_TS_CONVERSION, getTPS(PASS_ENGINE_PARAMETER_F), getTpsRateOfChange()); } diff --git a/firmware/hw_layer/adc_inputs.cpp b/firmware/hw_layer/adc_inputs.cpp index f6950acd66..463144e34d 100644 --- a/firmware/hw_layer/adc_inputs.cpp +++ b/firmware/hw_layer/adc_inputs.cpp @@ -495,11 +495,11 @@ static void configureInputs(void) { memset(adcHwChannelEnabled, 0, sizeof(adcHwChannelEnabled)); memset(adcHwChannelUsage, 0, sizeof(adcHwChannelUsage)); - addChannel("TPS", engineConfiguration->tpsAdcChannel, ADC_FAST); addChannel("MAP", engineConfiguration->map.sensor.hwChannel, ADC_FAST); addChannel("MAF", engineConfiguration->mafAdcChannel, ADC_FAST); addChannel("hip", engineConfiguration->hipOutputChannel, ADC_FAST); + addChannel("TPS", engineConfiguration->tpsAdcChannel, ADC_SLOW); addChannel("fuel", engineConfiguration->fuelLevelSensor, ADC_SLOW); addChannel("pPS", engineConfiguration->pedalPositionChannel, ADC_SLOW); addChannel("VBatt", engineConfiguration->vbattAdcChannel, ADC_SLOW); diff --git a/firmware/hw_layer/hardware.cpp b/firmware/hw_layer/hardware.cpp index 1f58c36ce2..426644448c 100644 --- a/firmware/hw_layer/hardware.cpp +++ b/firmware/hw_layer/hardware.cpp @@ -170,8 +170,8 @@ void adc_callback_fast(ADCDriver *adcp, adcsample_t *buffer, size_t n) { hipAdcCallback(fastAdc.samples[hipSampleIndex]); } #endif - if(tpsSampleIndex!=TPS_IS_SLOW) { - tpsFastAdc = fastAdc.samples[tpsSampleIndex]; + if (tpsSampleIndex != TPS_IS_SLOW) { +// tpsFastAdc = fastAdc.samples[tpsSampleIndex]; } } } diff --git a/firmware/rusefi.cpp b/firmware/rusefi.cpp index 08e7d33f34..87dc2b933f 100644 --- a/firmware/rusefi.cpp +++ b/firmware/rusefi.cpp @@ -275,5 +275,5 @@ int getRusEfiVersion(void) { return 123; // this is here to make the compiler happy about the unused array if (UNUSED_CCM_SIZE[0] * 0 != 0) return 3211; // this is here to make the compiler happy about the unused array - return 20160128; + return 20160131; } diff --git a/unit_tests/test_sensors.cpp b/unit_tests/test_sensors.cpp index 3283c7310b..25ebdda8f1 100644 --- a/unit_tests/test_sensors.cpp +++ b/unit_tests/test_sensors.cpp @@ -35,12 +35,12 @@ void testTps(void) { engineConfiguration->tpsMin = 43; engineConfiguration->tpsMax = 193; - assertEquals(49.3333, getTpsValue(117 PASS_ENGINE_PARAMETER)); + assertEquals(49.3333, getTpsValue(4 * 117 PASS_ENGINE_PARAMETER)); engineConfiguration->tpsMin = 193; engineConfiguration->tpsMax = 43; - assertEquals(50.6667, getTpsValue(117 PASS_ENGINE_PARAMETER)); + assertEqualsM("test#2", 50.6667, getTpsValue(4 * 117 PASS_ENGINE_PARAMETER)); } void testTpsRateOfChange(void) { diff --git a/unit_tests/test_trigger_decoder.cpp b/unit_tests/test_trigger_decoder.cpp index 1a0dcff13e..f35babc486 100644 --- a/unit_tests/test_trigger_decoder.cpp +++ b/unit_tests/test_trigger_decoder.cpp @@ -20,6 +20,7 @@ #include "algo.h" #include "trigger_mazda.h" #include "trigger_chrysler.h" +#include "tps.h" #include "trigger_central.h" #include "main_trigger_callback.h" @@ -252,11 +253,11 @@ static void testStartupFuelPumping(void) { engine->engineConfiguration->tpsMin = 0; engine->engineConfiguration->tpsMax = 10; - mockTps = 6; + mockTps = TPS_TS_CONVERSION * 6; sf.update(PASS_ENGINE_PARAMETER_F); assertEqualsM("pc#1", 1, sf.pumpsCounter); - mockTps = 3; + mockTps = TPS_TS_CONVERSION * 3; sf.update(PASS_ENGINE_PARAMETER_F); assertEqualsM("pc#2", 1, sf.pumpsCounter); @@ -267,16 +268,16 @@ static void testStartupFuelPumping(void) { sf.update(PASS_ENGINE_PARAMETER_F); assertEqualsM("pc#4", 0, sf.pumpsCounter); - mockTps = 7; + mockTps = TPS_TS_CONVERSION * 7; engine->rpmCalculator.mockRpm = 0; sf.update(PASS_ENGINE_PARAMETER_F); assertEqualsM("pc#5", 1, sf.pumpsCounter); - mockTps = 3; + mockTps = TPS_TS_CONVERSION * 3; sf.update(PASS_ENGINE_PARAMETER_F); assertEqualsM("pc#6", 1, sf.pumpsCounter); - mockTps = 7; + mockTps = TPS_TS_CONVERSION * 7; sf.update(PASS_ENGINE_PARAMETER_F); assertEqualsM("pc#7", 2, sf.pumpsCounter); }