mirror of https://github.com/FOME-Tech/fome-fw.git
implement temp sensor pulldown mode #116
This commit is contained in:
parent
c1cb45d15e
commit
ec8b054093
|
@ -30,6 +30,7 @@ Release template (copy/paste this for new release):
|
|||
|
||||
### Added
|
||||
- Log per-cylinder true ignition timing (includes trim, knock retard, etc) #76
|
||||
- Add mode for CLT/IAT sensors that are installed "high side" instead of typical "low side" #116
|
||||
|
||||
### Fixed
|
||||
- Improved bench test resolution (more usable for testing injectors, dwell, etc)
|
||||
|
|
|
@ -4,9 +4,10 @@
|
|||
|
||||
#include "resistance_func.h"
|
||||
|
||||
void ResistanceFunc::configure(float supplyVoltage, float pullupResistor) {
|
||||
void ResistanceFunc::configure(float supplyVoltage, float pullupResistor, bool isPulldown) {
|
||||
m_pullupResistor = pullupResistor;
|
||||
m_supplyVoltage = supplyVoltage;
|
||||
m_isPulldown = isPulldown;
|
||||
}
|
||||
|
||||
SensorResult ResistanceFunc::convert(float raw) const {
|
||||
|
@ -20,6 +21,12 @@ SensorResult ResistanceFunc::convert(float raw) const {
|
|||
return UnexpectedCode::High;
|
||||
}
|
||||
|
||||
if (m_isPulldown) {
|
||||
// If the sensor is on the high side (fixed resistor is pulldown),
|
||||
// invert the voltage so the math comes out correctly
|
||||
raw = m_supplyVoltage - raw;
|
||||
}
|
||||
|
||||
// Voltage is in a sensible range - convert
|
||||
float resistance = m_pullupResistor / (m_supplyVoltage / raw - 1);
|
||||
|
||||
|
|
|
@ -12,7 +12,7 @@
|
|||
|
||||
class ResistanceFunc final : public SensorConverter {
|
||||
public:
|
||||
void configure(float supplyVoltage, float pullupResistor);
|
||||
void configure(float supplyVoltage, float pullupResistor, bool isPulldown);
|
||||
|
||||
SensorResult convert(float inputValue) const override;
|
||||
|
||||
|
@ -21,4 +21,5 @@ public:
|
|||
private:
|
||||
float m_supplyVoltage = 5.0f;
|
||||
float m_pullupResistor = 1000.0f;
|
||||
bool m_isPulldown = false;
|
||||
};
|
||||
|
|
|
@ -35,7 +35,7 @@ static void validateThermistorConfig(const char *msg, thermistor_conf_s& cfg) {
|
|||
}
|
||||
|
||||
static SensorConverter& configureTempSensorFunction(const char *msg,
|
||||
thermistor_conf_s& cfg, FuncPair& p, bool isLinear) {
|
||||
thermistor_conf_s& cfg, FuncPair& p, bool isLinear, bool isPulldown) {
|
||||
if (isLinear) {
|
||||
p.linear.configure(cfg.resistance_1, cfg.tempC_1, cfg.resistance_2, cfg.tempC_2, -50, 250);
|
||||
|
||||
|
@ -43,7 +43,7 @@ static SensorConverter& configureTempSensorFunction(const char *msg,
|
|||
} else /* sensor is thermistor */ {
|
||||
validateThermistorConfig(msg, cfg);
|
||||
|
||||
p.thermistor.get<resist>().configure(5.0f, cfg.bias_resistor);
|
||||
p.thermistor.get<resist>().configure(5.0f, cfg.bias_resistor, isPulldown);
|
||||
p.thermistor.get<therm>().configure(cfg);
|
||||
|
||||
return p.thermistor;
|
||||
|
@ -54,21 +54,23 @@ static void configTherm(const char *msg,
|
|||
FunctionalSensor &sensor,
|
||||
FuncPair &p,
|
||||
ThermistorConf &config,
|
||||
bool isLinear) {
|
||||
bool isLinear,
|
||||
bool isPulldown) {
|
||||
// nothing to do if no channel
|
||||
if (!isAdcChannelValid(config.adcChannel)) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Configure the conversion function for this sensor
|
||||
sensor.setFunction(configureTempSensorFunction(msg, config.config, p, isLinear));
|
||||
sensor.setFunction(configureTempSensorFunction(msg, config.config, p, isLinear, isPulldown));
|
||||
}
|
||||
|
||||
static void configureTempSensor(const char *msg,
|
||||
FunctionalSensor &sensor,
|
||||
FuncPair &p,
|
||||
ThermistorConf &config,
|
||||
bool isLinear) {
|
||||
bool isLinear,
|
||||
bool isPulldown = false) {
|
||||
auto channel = config.adcChannel;
|
||||
|
||||
// Only register if we have a sensor
|
||||
|
@ -76,7 +78,7 @@ static void configureTempSensor(const char *msg,
|
|||
return;
|
||||
}
|
||||
|
||||
configTherm(msg, sensor, p, config, isLinear);
|
||||
configTherm(msg, sensor, p, config, isLinear, isPulldown);
|
||||
|
||||
// Register & subscribe
|
||||
AdcSubscription::SubscribeSensor(sensor, channel, 2);
|
||||
|
@ -88,13 +90,15 @@ void initThermistors() {
|
|||
clt,
|
||||
fclt,
|
||||
engineConfiguration->clt,
|
||||
engineConfiguration->useLinearCltSensor);
|
||||
engineConfiguration->useLinearCltSensor,
|
||||
engineConfiguration->cltSensorPulldown);
|
||||
|
||||
configureTempSensor("iat",
|
||||
iat,
|
||||
fiat,
|
||||
engineConfiguration->iat,
|
||||
engineConfiguration->useLinearIatSensor);
|
||||
engineConfiguration->useLinearIatSensor,
|
||||
engineConfiguration->iatSensorPulldown);
|
||||
|
||||
configureTempSensor("aux1",
|
||||
aux1,
|
||||
|
|
|
@ -428,7 +428,8 @@ bit usescriptTableForCanSniffingFiltering
|
|||
bit verboseCan,"Print all","Do not print";Print incoming and outgoing first bus CAN messages in rusEFI console
|
||||
bit artificialTestMisfire,"Danger Mode","No thank you";Experimental setting that will cause a misfire\nDO NOT ENABLE.
|
||||
bit useFordRedundantPps;On some Ford and Toyota vehicles one of the pedal sensors is not linear on the full range, i.e. in the specific range of the positions we effectively have only one sensor.
|
||||
|
||||
bit cltSensorPulldown
|
||||
bit iatSensorPulldown
|
||||
|
||||
int16_t tpsMin;Closed throttle, 1 volt = 200 units;"ADC", 1, 0, 0, 1023, 0
|
||||
int16_t tpsMax;Full throttle, 1 volt = 200 units;"ADC", 1, 0, 0, 1023, 0
|
||||
|
|
|
@ -4256,6 +4256,8 @@ dialog = tcuControls, "Transmission Settings"
|
|||
field = "Ford redundant PPS mode", useFordRedundantPps
|
||||
field = "Secondary PPS maximum", ppsSecondaryMaximum, {useFordRedundantPps}
|
||||
field = "ADC vRef voltage", adcVcc
|
||||
field = "CLT sensor is pulldown instead of pullup", cltSensorPulldown
|
||||
field = "IAT sensor is pulldown instead of pullup", iatSensorPulldown
|
||||
field = "Analog divider ratio", analogInputDividerCoefficient@@if_ts_show_analog_divider
|
||||
field = "Artificial Misfire", artificialTestMisfire
|
||||
field = "Instant Rpm Range", instantRpmRange
|
||||
|
|
|
@ -9,7 +9,7 @@
|
|||
TEST(resistance, OutOfRange)
|
||||
{
|
||||
ResistanceFunc f;
|
||||
f.configure(5, 10000);
|
||||
f.configure(5, 10000, false);
|
||||
|
||||
// Something in the middle should be valid
|
||||
{
|
||||
|
@ -45,7 +45,7 @@ TEST(resistance, OutOfRange)
|
|||
TEST(resistance, InRange)
|
||||
{
|
||||
ResistanceFunc f;
|
||||
f.configure(5, 10000);
|
||||
f.configure(5, 10000, false);
|
||||
|
||||
// 1 volt -> 2500 ohms low side
|
||||
{
|
||||
|
@ -76,3 +76,38 @@ TEST(resistance, InRange)
|
|||
EXPECT_FLOAT_EQ(r.Value, 40000);
|
||||
}
|
||||
}
|
||||
|
||||
TEST(resistance, PulldownMode)
|
||||
{
|
||||
ResistanceFunc f;
|
||||
f.configure(5, 10000, true);
|
||||
|
||||
// 4 volt -> 2500 ohms high side
|
||||
{
|
||||
auto r = f.convert(4.0f);
|
||||
EXPECT_TRUE(r.Valid);
|
||||
EXPECT_FLOAT_EQ(r.Value, 2500);
|
||||
}
|
||||
|
||||
// 3 volt -> 6666.667 ohm ohms high side
|
||||
// 20k/3 gives us an exact result
|
||||
{
|
||||
auto r = f.convert(3.0f);
|
||||
EXPECT_TRUE(r.Valid);
|
||||
EXPECT_FLOAT_EQ(r.Value, 20000.0f / 3);
|
||||
}
|
||||
|
||||
// 2 volt -> 15000 ohms high side
|
||||
{
|
||||
auto r = f.convert(2.0f);
|
||||
EXPECT_TRUE(r.Valid);
|
||||
EXPECT_FLOAT_EQ(r.Value, 15000);
|
||||
}
|
||||
|
||||
// 1 volt -> 40000 ohms high side
|
||||
{
|
||||
auto r = f.convert(1.0f);
|
||||
EXPECT_TRUE(r.Valid);
|
||||
EXPECT_FLOAT_EQ(r.Value, 40000);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue