implement temp sensor pulldown mode
This commit is contained in:
parent
96bad7a392
commit
b150b8702d
|
@ -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);
|
||||
|
@ -89,13 +91,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",
|
||||
|
|
|
@ -447,7 +447,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.\nSee also tps1_1AdcChannel\nset tps_min X;"ADC", 1, 0, 0, 1023, 0
|
||||
int16_t tpsMax;Full throttle.\nSee also tps1_1AdcChannel\nset tps_max X;"ADC", 1, 0, 0, 1023, 0
|
||||
|
|
|
@ -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