mirror of https://github.com/rusefi/wideband.git
extract sampler class
This commit is contained in:
parent
d549b42629
commit
58a09843eb
|
@ -21,39 +21,36 @@ static const float lsu42TempValues[] = { 1199, 961, 857, 806, 775, 750, 730, 715
|
||||||
static const float lsuAdvTempBins[] = { 53, 96, 130, 162, 184, 206, 239, 278, 300, 330, 390, 462, 573, 730, 950, 1200, 1500, 1900, 2500, 3500, 5000, 6000 };
|
static const float lsuAdvTempBins[] = { 53, 96, 130, 162, 184, 206, 239, 278, 300, 330, 390, 462, 573, 730, 950, 1200, 1500, 1900, 2500, 3500, 5000, 6000 };
|
||||||
static const float lsuAdvTempValues[] = { 1198, 982, 914, 875, 855, 838, 816, 794, 785, 771, 751, 732, 711, 691, 671, 653, 635, 614, 588, 562, 537, 528 };
|
static const float lsuAdvTempValues[] = { 1198, 982, 914, 875, 855, 838, 816, 794, 785, 771, 751, 732, 711, 691, 671, 653, 635, 614, 588, 562, 537, 528 };
|
||||||
|
|
||||||
struct Sampler : public ISampler {
|
|
||||||
public:
|
|
||||||
void ApplySample(AnalogChannelResult& result, float virtualGroundVoltageInt);
|
|
||||||
|
|
||||||
float GetNernstDc() const override
|
float Sampler::GetNernstDc() const
|
||||||
{
|
{
|
||||||
return nernstDc;
|
return nernstDc;
|
||||||
}
|
}
|
||||||
|
|
||||||
float GetNernstAc() const override
|
float Sampler::GetNernstAc() const
|
||||||
{
|
{
|
||||||
return nernstAc;
|
return nernstAc;
|
||||||
}
|
}
|
||||||
|
|
||||||
float GetPumpNominalCurrent() const override
|
float Sampler::GetPumpNominalCurrent() const
|
||||||
{
|
{
|
||||||
// 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
|
||||||
constexpr float ratio = -1000 / (PUMP_CURRENT_SENSE_GAIN * LSU_SENSE_R);
|
constexpr float ratio = -1000 / (PUMP_CURRENT_SENSE_GAIN * LSU_SENSE_R);
|
||||||
return pumpCurrentSenseVoltage * ratio;
|
return pumpCurrentSenseVoltage * ratio;
|
||||||
}
|
}
|
||||||
|
|
||||||
float GetInternalBatteryVoltage() const override
|
float Sampler::GetInternalBatteryVoltage() const
|
||||||
{
|
{
|
||||||
// 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 Sampler::GetSensorTemperature() const
|
||||||
{
|
{
|
||||||
float esr = GetSensorInternalResistance();
|
float esr = GetSensorInternalResistance();
|
||||||
|
|
||||||
if (esr > 5000)
|
if (esr > 5000)
|
||||||
|
@ -71,27 +68,17 @@ public:
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
float GetSensorInternalResistance() const override
|
float Sampler::GetSensorInternalResistance() const
|
||||||
{
|
{
|
||||||
// Sensor is the lowside of a divider, top side is GetESRSupplyR(), and 3.3v AC pk-pk is injected
|
// 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);
|
float totalEsr = GetESRSupplyR() / (VCC_VOLTS / GetNernstAc() - 1);
|
||||||
|
|
||||||
// There is a resistor between the opamp and Vm sensor pin. Remove the effect of that
|
// 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
|
// resistor so that the remainder is only the ESR of the sensor itself
|
||||||
return totalEsr - VM_RESISTOR_VALUE;
|
return totalEsr - VM_RESISTOR_VALUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
|
||||||
float r_2 = 0;
|
|
||||||
float r_3 = 0;
|
|
||||||
|
|
||||||
float nernstAc;
|
|
||||||
float nernstDc;
|
|
||||||
float pumpCurrentSenseVoltage;
|
|
||||||
float internalBatteryVoltage;
|
|
||||||
};
|
|
||||||
|
|
||||||
static Sampler samplers[AFR_CHANNELS];
|
static Sampler samplers[AFR_CHANNELS];
|
||||||
|
|
||||||
|
|
|
@ -10,6 +10,30 @@ struct ISampler
|
||||||
virtual float GetSensorInternalResistance() const = 0;
|
virtual float GetSensorInternalResistance() const = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct AnalogChannelResult;
|
||||||
|
|
||||||
|
class Sampler : public ISampler
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
void ApplySample(AnalogChannelResult& result, float virtualGroundVoltageInt);
|
||||||
|
|
||||||
|
float GetNernstDc() const override;
|
||||||
|
float GetNernstAc() const override;
|
||||||
|
float GetPumpNominalCurrent() const override;
|
||||||
|
float GetInternalBatteryVoltage() const override;
|
||||||
|
float GetSensorTemperature() const override;
|
||||||
|
float GetSensorInternalResistance() const override;
|
||||||
|
|
||||||
|
private:
|
||||||
|
float r_2 = 0;
|
||||||
|
float r_3 = 0;
|
||||||
|
|
||||||
|
float nernstAc = 0;
|
||||||
|
float nernstDc = 0;
|
||||||
|
float pumpCurrentSenseVoltage = 0;
|
||||||
|
float internalBatteryVoltage = 0;
|
||||||
|
};
|
||||||
|
|
||||||
// Get the sampler for a particular channel
|
// Get the sampler for a particular channel
|
||||||
const ISampler& GetSampler(int ch);
|
const ISampler& GetSampler(int ch);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue