2015-12-31 13:02:30 -08:00
|
|
|
/**
|
2018-01-21 13:11:39 -08:00
|
|
|
* @file map.cpp
|
2017-06-21 23:23:42 -07:00
|
|
|
*
|
|
|
|
* See also map_averaging.cpp
|
|
|
|
*
|
2020-01-13 18:57:43 -08:00
|
|
|
* @author Andrey Belomutskiy, (c) 2012-2020
|
2015-12-31 13:02:30 -08:00
|
|
|
*/
|
2021-07-25 22:05:17 -07:00
|
|
|
#include "pch.h"
|
|
|
|
|
2019-04-12 19:07:03 -07:00
|
|
|
#if EFI_PROD_CODE
|
2019-11-11 20:32:09 -08:00
|
|
|
#include "digital_input_icu.h"
|
2019-11-03 19:02:52 -08:00
|
|
|
#include "digital_input_exti.h"
|
2015-07-10 06:01:56 -07:00
|
|
|
#endif
|
|
|
|
|
2019-04-12 19:07:03 -07:00
|
|
|
#if EFI_ANALOG_SENSORS
|
2015-07-10 06:01:56 -07:00
|
|
|
|
|
|
|
static FastInterpolation customMap;
|
|
|
|
|
2018-01-03 04:47:44 -08:00
|
|
|
// See 'useFixedBaroCorrFromMap'
|
|
|
|
static float storedInitialBaroPressure = NAN;
|
|
|
|
|
2015-07-10 06:01:56 -07:00
|
|
|
/**
|
|
|
|
* @brief MAP value decoded for a 1.83 Honda sensor
|
|
|
|
* -6.64kPa at zero volts
|
|
|
|
* 182.78kPa at 5 volts
|
|
|
|
*
|
|
|
|
* about 3 volts at 100kPa
|
|
|
|
*
|
|
|
|
* @returns kPa value
|
|
|
|
*/
|
|
|
|
static FastInterpolation denso183(0, -6.64, 5, 182.78);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* MAP sensor output voltage of 3.0v = a gauge reading of 0 in. Hg
|
|
|
|
* MAP sensor output voltage of 0.5v = a gauge reading of 27 in. Hg
|
|
|
|
*/
|
|
|
|
static FastInterpolation honda3bar(0.5, 91.422, 3.0, 0);
|
|
|
|
|
|
|
|
static FastInterpolation subyDenso(0, 0, 5, 200);
|
|
|
|
|
|
|
|
static FastInterpolation gm3bar(0.631, 40, 4.914, 304);
|
|
|
|
|
2021-02-02 06:15:28 -08:00
|
|
|
static FastInterpolation gm2bar(0, 8.8, 5, 208);
|
|
|
|
|
|
|
|
static FastInterpolation gm1bar(0, 10, 5, 105);
|
|
|
|
|
2015-07-10 06:01:56 -07:00
|
|
|
static FastInterpolation mpx4250(0, 8, 5, 260);
|
|
|
|
|
2018-01-26 07:50:12 -08:00
|
|
|
static FastInterpolation mpx4250A(0.25, 20, 4.875, 250);
|
|
|
|
|
2021-09-30 18:53:31 -07:00
|
|
|
static FastInterpolation mpxh6400(1 /*volts*/, 90 /*kPa*/, 3 /*volts*/, 250 /*kPa*/);
|
2021-09-30 18:44:50 -07:00
|
|
|
|
2015-08-16 20:01:33 -07:00
|
|
|
static FastInterpolation mpx4100(0.3, 20, 4.9, 105);
|
|
|
|
|
2016-01-07 06:01:34 -08:00
|
|
|
/**
|
|
|
|
* http://easyautodiagnostics.com/chrysler/2.0L-2.4L/map-sensor-diagnostic-test-1
|
|
|
|
* or maybe
|
|
|
|
* https://books.google.com/books?id=3q85p56_PxIC page 132
|
|
|
|
* https://books.google.com/books?id=3q85p56_PxIC&q=chrysler+map#v=snippet&q=chrysler%20map&f=false
|
|
|
|
*/
|
2016-01-07 18:02:35 -08:00
|
|
|
//static FastInterpolation dodgeNeon2003(0.5 /* volts */, 0 /* kPa */, 4.5 /* volts */ , 100 /* kPa */);
|
|
|
|
static FastInterpolation dodgeNeon2003(0.4 /* volts */, 15.34 /* kPa */, 4.5 /* volts */ , 100 /* kPa */);
|
2015-07-10 06:01:56 -07:00
|
|
|
|
2017-09-21 18:15:13 -07:00
|
|
|
static FastInterpolation densoToyota(3.7 - 2 /* volts */, 33.322271 /* kPa */, 3.7 /* volts */ , 100 /* kPa */);
|
|
|
|
|
2020-05-17 22:39:41 -07:00
|
|
|
/**
|
|
|
|
* Open question how to get this Miata NB2 sensor read MAP
|
|
|
|
*/
|
2021-08-21 08:31:05 -07:00
|
|
|
static FastInterpolation mazda1bar(0 /* volts */, 2.5 /* kPa */, 5 /* volts */ , 117 /* kPa */);
|
2020-05-17 22:39:41 -07:00
|
|
|
|
2020-05-04 16:08:36 -07:00
|
|
|
/**
|
|
|
|
* Bosch 2.5 Bar TMap Map Sensor with IAT
|
|
|
|
*/
|
|
|
|
static FastInterpolation bosch2_5(0.4 /* volts */, 20 /* kPa */, 4.65 /* volts */ , 250 /* kPa */);
|
|
|
|
|
2017-09-21 20:31:46 -07:00
|
|
|
static FastInterpolation *getDecoder(air_pressure_sensor_type_e type);
|
|
|
|
|
2021-11-16 01:15:29 -08:00
|
|
|
float decodePressure(float voltage, air_pressure_sensor_config_s * mapConfig) {
|
2016-06-18 09:01:50 -07:00
|
|
|
switch (mapConfig->type) {
|
2015-07-10 06:01:56 -07:00
|
|
|
case MT_CUSTOM:
|
|
|
|
// todo: migrate to 'FastInterpolation customMap'
|
2018-06-12 02:45:11 -07:00
|
|
|
return interpolateMsg("map", engineConfiguration->mapLowValueVoltage, mapConfig->lowValue,
|
2016-06-26 11:01:41 -07:00
|
|
|
engineConfiguration->mapHighValueVoltage, mapConfig->highValue, voltage);
|
2015-07-10 06:01:56 -07:00
|
|
|
case MT_DENSO183:
|
|
|
|
case MT_MPX4250:
|
2018-01-26 07:50:12 -08:00
|
|
|
case MT_MPX4250A:
|
2015-07-10 06:01:56 -07:00
|
|
|
case MT_HONDA3BAR:
|
|
|
|
case MT_DODGE_NEON_2003:
|
|
|
|
case MT_SUBY_DENSO:
|
|
|
|
case MT_GM_3_BAR:
|
2021-02-02 06:15:28 -08:00
|
|
|
case MT_GM_2_BAR:
|
|
|
|
case MT_GM_1_BAR:
|
2016-06-12 08:03:43 -07:00
|
|
|
case MT_TOYOTA_89420_02010:
|
2015-08-16 20:01:33 -07:00
|
|
|
case MT_MPX4100:
|
2020-05-04 16:08:36 -07:00
|
|
|
case MT_BOSCH_2_5:
|
2020-05-17 22:39:41 -07:00
|
|
|
case MT_MAZDA_1_BAR:
|
2021-09-30 18:34:23 -07:00
|
|
|
case MT_MPXH6400:
|
2017-09-21 20:31:46 -07:00
|
|
|
return getDecoder(mapConfig->type)->getValue(voltage);
|
2015-07-10 06:01:56 -07:00
|
|
|
default:
|
2021-06-13 17:30:51 -07:00
|
|
|
firmwareError(CUSTOM_ERR_MAP_TYPE, "Unknown MAP type: pressure %d", mapConfig->type);
|
2015-07-10 06:01:56 -07:00
|
|
|
return NAN;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-01-03 04:47:44 -08:00
|
|
|
/**
|
|
|
|
* This function checks if Baro/MAP sensor value is inside of expected range
|
|
|
|
* @return unchanged mapKPa parameter or NaN
|
|
|
|
*/
|
2021-11-16 01:15:29 -08:00
|
|
|
static float validateBaroMap(float mapKPa) {
|
2018-01-03 04:47:44 -08:00
|
|
|
const float atmoPressure = 100.0f;
|
|
|
|
const float atmoPressureRange = 15.0f; // 85..115
|
2019-09-29 06:58:29 -07:00
|
|
|
if (cisnan(mapKPa) || absF(mapKPa - atmoPressure) > atmoPressureRange) {
|
|
|
|
warning(OBD_Barometric_Press_Circ, "Invalid start-up baro pressure = %.2fkPa", mapKPa);
|
2018-01-03 04:47:44 -08:00
|
|
|
return NAN;
|
2019-09-29 06:58:29 -07:00
|
|
|
}
|
2018-01-03 04:47:44 -08:00
|
|
|
return mapKPa;
|
|
|
|
}
|
|
|
|
|
2021-11-16 01:15:29 -08:00
|
|
|
float getBaroPressure() {
|
2018-01-03 04:47:44 -08:00
|
|
|
// Override the real Baro sensor with the stored initial MAP value, if the option is set.
|
2021-11-17 00:54:21 -08:00
|
|
|
if (engineConfiguration->useFixedBaroCorrFromMap)
|
2018-01-03 04:47:44 -08:00
|
|
|
return storedInitialBaroPressure;
|
2021-11-16 01:15:29 -08:00
|
|
|
float voltage = getVoltageDivided("baro", engineConfiguration->baroSensor.hwChannel);
|
|
|
|
return decodePressure(voltage, &engineConfiguration->baroSensor);
|
2015-07-10 06:01:56 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
static FastInterpolation *getDecoder(air_pressure_sensor_type_e type) {
|
|
|
|
switch (type) {
|
|
|
|
case MT_DENSO183:
|
|
|
|
return &denso183;
|
|
|
|
case MT_MPX4250:
|
|
|
|
return &mpx4250;
|
2021-06-13 17:30:51 -07:00
|
|
|
case MT_MPX4100:
|
|
|
|
return &mpx4100;
|
2018-01-26 07:50:12 -08:00
|
|
|
case MT_MPX4250A:
|
|
|
|
return &mpx4250A;
|
2021-09-30 18:34:23 -07:00
|
|
|
case MT_MPXH6400:
|
2021-09-30 18:44:50 -07:00
|
|
|
return &mpxh6400;
|
2015-07-10 06:01:56 -07:00
|
|
|
case MT_HONDA3BAR:
|
|
|
|
return &honda3bar;
|
|
|
|
case MT_DODGE_NEON_2003:
|
|
|
|
return &dodgeNeon2003;
|
|
|
|
case MT_SUBY_DENSO:
|
|
|
|
return &subyDenso;
|
|
|
|
case MT_GM_3_BAR:
|
|
|
|
return &gm3bar;
|
2021-02-02 06:15:28 -08:00
|
|
|
case MT_GM_2_BAR:
|
|
|
|
return &gm2bar;
|
|
|
|
case MT_GM_1_BAR:
|
|
|
|
return &gm1bar;
|
2017-09-21 20:31:46 -07:00
|
|
|
case MT_TOYOTA_89420_02010:
|
|
|
|
return &densoToyota;
|
2020-05-17 22:39:41 -07:00
|
|
|
case MT_MAZDA_1_BAR:
|
|
|
|
return &mazda1bar;
|
2020-05-04 16:08:36 -07:00
|
|
|
case MT_BOSCH_2_5:
|
|
|
|
return &bosch2_5;
|
2015-07-10 06:01:56 -07:00
|
|
|
default:
|
2021-06-13 17:30:51 -07:00
|
|
|
firmwareError(CUSTOM_ERR_MAP_TYPE, "Unknown MAP type: decoder %d", type);
|
2015-07-10 06:01:56 -07:00
|
|
|
return &customMap;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-11-16 01:15:29 -08:00
|
|
|
static void applyConfiguration() {
|
2015-07-10 06:01:56 -07:00
|
|
|
air_pressure_sensor_config_s * apConfig = &engineConfiguration->map.sensor;
|
2016-06-25 16:03:02 -07:00
|
|
|
customMap.init(0, apConfig->lowValue, 5, apConfig->highValue);
|
2015-07-10 06:01:56 -07:00
|
|
|
}
|
|
|
|
|
2019-04-12 19:07:03 -07:00
|
|
|
#if EFI_PROD_CODE
|
2017-08-06 13:29:14 -07:00
|
|
|
|
|
|
|
extern int mapMinBufferLength;
|
|
|
|
|
2021-11-15 04:02:34 -08:00
|
|
|
static void printMAPInfo() {
|
2019-04-12 19:07:03 -07:00
|
|
|
#if EFI_ANALOG_SENSORS
|
2021-10-05 16:59:07 -07:00
|
|
|
efiPrintf("instant value=%.2fkPa", Sensor::getOrZero(SensorType::Map));
|
2015-07-10 06:01:56 -07:00
|
|
|
|
2020-02-26 15:16:35 -08:00
|
|
|
#if EFI_MAP_AVERAGING
|
2021-09-29 21:20:21 -07:00
|
|
|
efiPrintf("map type=%d/%s MAP=%.2fkPa mapMinBufferLength=%d", engineConfiguration->map.sensor.type,
|
|
|
|
getAir_pressure_sensor_type_e(engineConfiguration->map.sensor.type),
|
2021-10-05 16:59:07 -07:00
|
|
|
Sensor::getOrZero(SensorType::Map),
|
2021-09-29 21:20:21 -07:00
|
|
|
mapMinBufferLength);
|
2020-02-26 15:16:35 -08:00
|
|
|
#endif // EFI_MAP_AVERAGING
|
2015-07-10 06:01:56 -07:00
|
|
|
|
2021-09-29 21:20:21 -07:00
|
|
|
adc_channel_e mapAdc = engineConfiguration->map.sensor.hwChannel;
|
|
|
|
char pinNameBuffer[16];
|
|
|
|
|
2021-11-16 01:15:29 -08:00
|
|
|
efiPrintf("MAP %.2fv @%s", getVoltage("mapinfo", mapAdc),
|
2021-09-29 21:20:21 -07:00
|
|
|
getPinNameByAdcChannel("map", mapAdc, pinNameBuffer));
|
|
|
|
if (engineConfiguration->map.sensor.type == MT_CUSTOM) {
|
|
|
|
efiPrintf("at %.2fv=%.2f at %.2fv=%.2f",
|
|
|
|
engineConfiguration->mapLowValueVoltage,
|
|
|
|
engineConfiguration->map.sensor.lowValue,
|
|
|
|
engineConfiguration->mapHighValueVoltage,
|
|
|
|
engineConfiguration->map.sensor.highValue);
|
2015-07-10 06:01:56 -07:00
|
|
|
}
|
|
|
|
|
2021-02-07 15:54:41 -08:00
|
|
|
if (Sensor::hasSensor(SensorType::BarometricPressure)) {
|
2021-04-20 11:09:41 -07:00
|
|
|
efiPrintf("baro type=%d value=%.2f", engineConfiguration->baroSensor.type, Sensor::get(SensorType::BarometricPressure).value_or(-1));
|
2015-08-30 14:01:21 -07:00
|
|
|
if (engineConfiguration->baroSensor.type == MT_CUSTOM) {
|
2021-04-20 11:09:41 -07:00
|
|
|
efiPrintf("min=%.2f@%.2f max=%.2f@%.2f",
|
2016-06-25 16:03:02 -07:00
|
|
|
engineConfiguration->baroSensor.lowValue,
|
|
|
|
engineConfiguration->mapLowValueVoltage,
|
|
|
|
engineConfiguration->baroSensor.highValue,
|
|
|
|
engineConfiguration->mapHighValueVoltage);
|
2015-08-30 14:01:21 -07:00
|
|
|
}
|
2015-07-10 06:01:56 -07:00
|
|
|
}
|
|
|
|
#endif /* EFI_ANALOG_SENSORS */
|
|
|
|
}
|
|
|
|
#endif /* EFI_PROD_CODE */
|
|
|
|
|
|
|
|
|
2021-11-16 01:15:29 -08:00
|
|
|
void initMapDecoder() {
|
|
|
|
applyConfiguration();
|
2015-07-10 06:01:56 -07:00
|
|
|
|
2021-11-17 00:54:21 -08:00
|
|
|
if (engineConfiguration->useFixedBaroCorrFromMap) {
|
2018-01-03 04:47:44 -08:00
|
|
|
// Read initial MAP sensor value and store it for Baro correction.
|
2021-10-04 15:33:10 -07:00
|
|
|
storedInitialBaroPressure = Sensor::get(SensorType::MapSlow).value_or(101.325);
|
2021-04-20 11:09:41 -07:00
|
|
|
efiPrintf("Get initial baro MAP pressure = %.2fkPa", storedInitialBaroPressure);
|
2018-01-03 04:47:44 -08:00
|
|
|
// validate if it's within a reasonable range (the engine should not be spinning etc.)
|
2021-11-16 01:15:29 -08:00
|
|
|
storedInitialBaroPressure = validateBaroMap(storedInitialBaroPressure);
|
2018-01-03 04:47:44 -08:00
|
|
|
if (!cisnan(storedInitialBaroPressure)) {
|
2021-04-20 11:09:41 -07:00
|
|
|
efiPrintf("Using this fixed MAP pressure to override the baro correction!");
|
2018-01-03 04:47:44 -08:00
|
|
|
} else {
|
2021-04-20 11:09:41 -07:00
|
|
|
efiPrintf("The baro pressure is invalid. The fixed baro correction will be disabled!");
|
2018-01-03 04:47:44 -08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-11-03 19:02:52 -08:00
|
|
|
#if EFI_PROD_CODE
|
2015-07-10 06:01:56 -07:00
|
|
|
addConsoleAction("mapinfo", printMAPInfo);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
#else /* EFI_ANALOG_SENSORS */
|
|
|
|
|
2021-11-16 01:15:29 -08:00
|
|
|
void initMapDecoder() {
|
2015-07-10 06:01:56 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif /* EFI_ANALOG_SENSORS */
|