mirror of https://github.com/rusefi/wideband.git
heater uses sampling class
This commit is contained in:
parent
2907a5378f
commit
b8f11741b5
|
@ -257,16 +257,18 @@ static void HeaterThread(void*)
|
||||||
auto heaterAllowState = GetHeaterAllowed();
|
auto heaterAllowState = GetHeaterAllowed();
|
||||||
|
|
||||||
for (i = 0; i < AFR_CHANNELS; i++) {
|
for (i = 0; i < AFR_CHANNELS; i++) {
|
||||||
|
const auto& sampler = GetSampler(i);
|
||||||
|
|
||||||
heater_state &s = state[i];
|
heater_state &s = state[i];
|
||||||
|
|
||||||
// Read sensor state
|
// Read sensor state
|
||||||
float heaterEsr = GetSensorInternalResistance(s.ch);
|
float heaterEsr = sampler.GetSensorInternalResistance();
|
||||||
float sensorTemperature = GetSensorTemperature(s.ch);
|
float sensorTemperature = sampler.GetSensorTemperature();
|
||||||
|
|
||||||
// If we haven't heard from rusEFI, use the internally sensed
|
// If we haven't heard from rusEFI, use the internally sensed
|
||||||
// battery voltage instead of voltage over CAN.
|
// battery voltage instead of voltage over CAN.
|
||||||
float batteryVoltage = heaterAllowState == HeaterAllow::Unknown
|
float batteryVoltage = heaterAllowState == HeaterAllow::Unknown
|
||||||
? GetInternalBatteryVoltage(s.ch)
|
? sampler.GetInternalBatteryVoltage()
|
||||||
: GetRemoteBatteryVoltage();
|
: GetRemoteBatteryVoltage();
|
||||||
|
|
||||||
// Run the state machine
|
// Run the state machine
|
||||||
|
|
|
@ -25,15 +25,18 @@ struct Sampler : public ISampler {
|
||||||
public:
|
public:
|
||||||
void ApplySample(AnalogChannelResult& result, float virtualGroundVoltageInt);
|
void ApplySample(AnalogChannelResult& result, float virtualGroundVoltageInt);
|
||||||
|
|
||||||
float GetNernstDc() const override {
|
float GetNernstDc() const override
|
||||||
|
{
|
||||||
return nernstDc;
|
return nernstDc;
|
||||||
}
|
}
|
||||||
|
|
||||||
float GetNernstAc() const override {
|
float GetNernstAc() const override
|
||||||
|
{
|
||||||
return nernstAc;
|
return nernstAc;
|
||||||
}
|
}
|
||||||
|
|
||||||
float GetPumpNominalCurrent() const override {
|
float GetPumpNominalCurrent() const override
|
||||||
|
{
|
||||||
// Gain is 10x, then a 61.9 ohm resistor
|
// Gain is 10x, then a 61.9 ohm resistor
|
||||||
// Effective resistance with the gain is 619 ohms
|
// Effective resistance with the gain is 619 ohms
|
||||||
// 1000 is to convert to milliamperes
|
// 1000 is to convert to milliamperes
|
||||||
|
@ -41,13 +44,45 @@ public:
|
||||||
return pumpCurrentSenseVoltage * ratio;
|
return pumpCurrentSenseVoltage * ratio;
|
||||||
}
|
}
|
||||||
|
|
||||||
float GetInternalBatteryVoltage() const override {
|
float GetInternalBatteryVoltage() const override
|
||||||
|
{
|
||||||
// Dual HW can measure heater voltage for each channel
|
// Dual HW can measure heater voltage for each channel
|
||||||
// by measuring voltage on Heater- while FET is off
|
// by measuring voltage on Heater- while FET is off
|
||||||
// TODO: rename function?
|
// TODO: rename function?
|
||||||
return internalBatteryVoltage;
|
return internalBatteryVoltage;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
float GetSensorTemperature() const override
|
||||||
|
{
|
||||||
|
float esr = GetSensorInternalResistance();
|
||||||
|
|
||||||
|
if (esr > 5000)
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
switch (GetSensorType()) {
|
||||||
|
case SensorType::LSU49:
|
||||||
|
return interpolate2d(esr, lsu49TempBins, lsu49TempValues);
|
||||||
|
case SensorType::LSU42:
|
||||||
|
return interpolate2d(esr, lsu42TempBins, lsu42TempValues);
|
||||||
|
case SensorType::LSUADV:
|
||||||
|
return interpolate2d(esr, lsuAdvTempBins, lsuAdvTempValues);
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
float GetSensorInternalResistance() const override
|
||||||
|
{
|
||||||
|
// Sensor is the lowside of a divider, top side is GetESRSupplyR(), and 3.3v AC pk-pk is injected
|
||||||
|
float totalEsr = GetESRSupplyR() / (VCC_VOLTS / GetNernstAc() - 1);
|
||||||
|
|
||||||
|
// There is a resistor between the opamp and Vm sensor pin. Remove the effect of that
|
||||||
|
// resistor so that the remainder is only the ESR of the sensor itself
|
||||||
|
return totalEsr - VM_RESISTOR_VALUE;
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
float r_2 = 0;
|
float r_2 = 0;
|
||||||
float r_3 = 0;
|
float r_3 = 0;
|
||||||
|
@ -60,6 +95,11 @@ private:
|
||||||
|
|
||||||
static Sampler samplers[AFR_CHANNELS];
|
static Sampler samplers[AFR_CHANNELS];
|
||||||
|
|
||||||
|
ISampler& GetSampler(int ch)
|
||||||
|
{
|
||||||
|
return samplers[ch];
|
||||||
|
}
|
||||||
|
|
||||||
constexpr float f_abs(float x)
|
constexpr float f_abs(float x)
|
||||||
{
|
{
|
||||||
return x > 0 ? x : -x;
|
return x > 0 ? x : -x;
|
||||||
|
@ -139,35 +179,15 @@ float GetNernstAc(int ch)
|
||||||
return samplers[ch].GetNernstAc();
|
return samplers[ch].GetNernstAc();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO: remove these helpers
|
||||||
float GetSensorInternalResistance(int ch)
|
float GetSensorInternalResistance(int ch)
|
||||||
{
|
{
|
||||||
// Sensor is the lowside of a divider, top side is GetESRSupplyR(), and 3.3v AC pk-pk is injected
|
return samplers[ch].GetSensorInternalResistance();
|
||||||
float totalEsr = GetESRSupplyR() / (VCC_VOLTS / GetNernstAc(ch) - 1);
|
|
||||||
|
|
||||||
// There is a resistor between the opamp and Vm sensor pin. Remove the effect of that
|
|
||||||
// resistor so that the remainder is only the ESR of the sensor itself
|
|
||||||
return totalEsr - VM_RESISTOR_VALUE;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
float GetSensorTemperature(int ch)
|
float GetSensorTemperature(int ch)
|
||||||
{
|
{
|
||||||
float esr = GetSensorInternalResistance(ch);
|
return samplers[ch].GetSensorTemperature();
|
||||||
|
|
||||||
if (esr > 5000)
|
|
||||||
{
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
switch (GetSensorType()) {
|
|
||||||
case SensorType::LSU49:
|
|
||||||
return interpolate2d(esr, lsu49TempBins, lsu49TempValues);
|
|
||||||
case SensorType::LSU42:
|
|
||||||
return interpolate2d(esr, lsu42TempBins, lsu42TempValues);
|
|
||||||
case SensorType::LSUADV:
|
|
||||||
return interpolate2d(esr, lsuAdvTempBins, lsuAdvTempValues);
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
float GetNernstDc(int ch)
|
float GetNernstDc(int ch)
|
||||||
|
|
|
@ -6,6 +6,8 @@ struct ISampler
|
||||||
virtual float GetNernstAc() const = 0;
|
virtual float GetNernstAc() const = 0;
|
||||||
virtual float GetPumpNominalCurrent() const = 0;
|
virtual float GetPumpNominalCurrent() const = 0;
|
||||||
virtual float GetInternalBatteryVoltage() const = 0;
|
virtual float GetInternalBatteryVoltage() const = 0;
|
||||||
|
virtual float GetSensorTemperature() const = 0;
|
||||||
|
virtual float GetSensorInternalResistance() const = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
// Get the sampler for a particular channel
|
// Get the sampler for a particular channel
|
||||||
|
|
Loading…
Reference in New Issue