extract sampler class

This commit is contained in:
Matthew Kennedy 2023-08-09 12:31:49 -07:00
parent d549b42629
commit 58a09843eb
2 changed files with 74 additions and 63 deletions

View File

@ -21,21 +21,18 @@ 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
@ -44,7 +41,7 @@ public:
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
@ -52,7 +49,7 @@ public:
return internalBatteryVoltage; return internalBatteryVoltage;
} }
float GetSensorTemperature() const override float Sampler::GetSensorTemperature() const
{ {
float esr = GetSensorInternalResistance(); float esr = GetSensorInternalResistance();
@ -73,7 +70,7 @@ 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);
@ -83,16 +80,6 @@ public:
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];
const ISampler& GetSampler(int ch) const ISampler& GetSampler(int ch)

View File

@ -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);