mirror of https://github.com/rusefi/wideband.git
suggestion to improve naming (#294)
* Rename GetInternalBatteryVoltage() to GetInternalHeaterVoltage() * sampling, heater: fix Battery vs Heater naming mess --------- Co-authored-by: Andrey Gusakov <dron0gus@gmail.com>
This commit is contained in:
parent
867082f276
commit
d8e65a2c24
|
@ -47,7 +47,7 @@ AnalogResult AnalogSample()
|
||||||
{
|
{
|
||||||
.NernstVoltage = AverageSamples(adcBuffer, 0) * (1.0 / NERNST_INPUT_GAIN),
|
.NernstVoltage = AverageSamples(adcBuffer, 0) * (1.0 / NERNST_INPUT_GAIN),
|
||||||
.PumpCurrentVoltage = AverageSamples(adcBuffer, 1),
|
.PumpCurrentVoltage = AverageSamples(adcBuffer, 1),
|
||||||
.BatteryVoltage = 0,
|
.HeaterSupplyVoltage = 0,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
.VirtualGroundVoltageInt = AverageSamples(adcBuffer, 2),
|
.VirtualGroundVoltageInt = AverageSamples(adcBuffer, 2),
|
||||||
|
|
|
@ -111,13 +111,13 @@ AnalogResult AnalogSample()
|
||||||
/* left */
|
/* left */
|
||||||
.NernstVoltage = AverageSamples(adcBuffer, 3) * (1.0 / NERNST_INPUT_GAIN),
|
.NernstVoltage = AverageSamples(adcBuffer, 3) * (1.0 / NERNST_INPUT_GAIN),
|
||||||
.PumpCurrentVoltage = AverageSamples(adcBuffer, 2),
|
.PumpCurrentVoltage = AverageSamples(adcBuffer, 2),
|
||||||
.BatteryVoltage = l_heater_voltage,
|
.HeaterSupplyVoltage = l_heater_voltage,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
/* right */
|
/* right */
|
||||||
.NernstVoltage = AverageSamples(adcBuffer, 1) * (1.0 / NERNST_INPUT_GAIN),
|
.NernstVoltage = AverageSamples(adcBuffer, 1) * (1.0 / NERNST_INPUT_GAIN),
|
||||||
.PumpCurrentVoltage = AverageSamples(adcBuffer, 0),
|
.PumpCurrentVoltage = AverageSamples(adcBuffer, 0),
|
||||||
.BatteryVoltage = r_heater_voltage,
|
.HeaterSupplyVoltage = r_heater_voltage,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
/* Dual board has separate internal virtual ground = 3.3V / 2
|
/* Dual board has separate internal virtual ground = 3.3V / 2
|
||||||
|
|
|
@ -135,10 +135,10 @@ AnalogResult AnalogSample()
|
||||||
}
|
}
|
||||||
/* left */
|
/* left */
|
||||||
res.ch[0].PumpCurrentVoltage = AverageSamples(adcBuffer, 2);
|
res.ch[0].PumpCurrentVoltage = AverageSamples(adcBuffer, 2);
|
||||||
res.ch[0].BatteryVoltage = l_heater_voltage;
|
res.ch[0].HeaterSupplyVoltage = l_heater_voltage;
|
||||||
/* right */
|
/* right */
|
||||||
res.ch[1].PumpCurrentVoltage = AverageSamples(adcBuffer, 0);
|
res.ch[1].PumpCurrentVoltage = AverageSamples(adcBuffer, 0);
|
||||||
res.ch[1].BatteryVoltage = r_heater_voltage;
|
res.ch[1].HeaterSupplyVoltage = r_heater_voltage;
|
||||||
|
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
|
@ -66,8 +66,11 @@ AnalogResult AnalogSample()
|
||||||
.PumpCurrentVoltage = AverageSamples(adcBuffer, 1),
|
.PumpCurrentVoltage = AverageSamples(adcBuffer, 1),
|
||||||
/* We also can measure output virtual ground voltage for diagnostic purposes */
|
/* We also can measure output virtual ground voltage for diagnostic purposes */
|
||||||
//.VirtualGroundVoltageExt = AverageSamples(adcBuffer, 0) / VM_INPUT_DIVIDER,
|
//.VirtualGroundVoltageExt = AverageSamples(adcBuffer, 0) / VM_INPUT_DIVIDER,
|
||||||
.BatteryVoltage = AverageSamples(adcBuffer, 3) / BATTERY_INPUT_DIVIDER,
|
/* Heater measurement circuit has incorrect RC filter making inposible accurate
|
||||||
/* .HeaterVoltage = AverageSamples(adcBuffer, 4) / HEATER_INPUT_DIVIDER, */
|
* measurement when heater pwm has high duty
|
||||||
|
* Assume WBO supply voltage == heater supply voltage */
|
||||||
|
.HeaterSupplyVoltage = AverageSamples(adcBuffer, 3) / BATTERY_INPUT_DIVIDER,
|
||||||
|
/* .HeaterSupplyVoltage = AverageSamples(adcBuffer, 4) / HEATER_INPUT_DIVIDER, */
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
/* Rev 2 board has separate internal virtual ground = 3.3V / 2
|
/* Rev 2 board has separate internal virtual ground = 3.3V / 2
|
||||||
|
|
|
@ -63,8 +63,11 @@ AnalogResult AnalogSample()
|
||||||
.PumpCurrentVoltage = AverageSamples(adcBuffer, 1),
|
.PumpCurrentVoltage = AverageSamples(adcBuffer, 1),
|
||||||
/* We also can measure output virtual ground voltage for diagnostic purposes */
|
/* We also can measure output virtual ground voltage for diagnostic purposes */
|
||||||
//.VirtualGroundVoltageExt = AverageSamples(adcBuffer, 0) / VM_INPUT_DIVIDER,
|
//.VirtualGroundVoltageExt = AverageSamples(adcBuffer, 0) / VM_INPUT_DIVIDER,
|
||||||
.BatteryVoltage = AverageSamples(adcBuffer, 3) / BATTERY_INPUT_DIVIDER,
|
/* Heater measurement circuit has incorrect RC filter making inposible accurate
|
||||||
/* .HeaterVoltage = AverageSamples(adcBuffer, 4) / HEATER_INPUT_DIVIDER, */
|
* measurement when heater pwm has high duty
|
||||||
|
* Assume WBO supply voltage == heater supply voltage */
|
||||||
|
.HeaterSupplyVoltage = AverageSamples(adcBuffer, 3) / BATTERY_INPUT_DIVIDER,
|
||||||
|
/* .HeaterSupplyVoltage = AverageSamples(adcBuffer, 4) / HEATER_INPUT_DIVIDER, */
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
/* Rev 2 board has separate internal virtual ground = 3.3V / 2
|
/* Rev 2 board has separate internal virtual ground = 3.3V / 2
|
||||||
|
|
|
@ -12,13 +12,14 @@ struct AnalogChannelResult
|
||||||
float PumpCurrentVoltage;
|
float PumpCurrentVoltage;
|
||||||
/* for dual version - this is voltage on Heater-, switches between zero and Vbatt with heater PWM,
|
/* for dual version - this is voltage on Heater-, switches between zero and Vbatt with heater PWM,
|
||||||
* used for both Vbatt measurement and Heater diagnostic */
|
* used for both Vbatt measurement and Heater diagnostic */
|
||||||
float BatteryVoltage;
|
float HeaterSupplyVoltage;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct AnalogResult
|
struct AnalogResult
|
||||||
{
|
{
|
||||||
AnalogChannelResult ch[AFR_CHANNELS];
|
AnalogChannelResult ch[AFR_CHANNELS];
|
||||||
float VirtualGroundVoltageInt;
|
float VirtualGroundVoltageInt;
|
||||||
|
/* TODO: add SupplyVoltage - some boards can measure supply voltage */
|
||||||
};
|
};
|
||||||
|
|
||||||
AnalogResult AnalogSample();
|
AnalogResult AnalogSample();
|
||||||
|
|
|
@ -42,7 +42,7 @@ HeaterState HeaterControllerBase::GetHeaterState() const
|
||||||
return heaterState;
|
return heaterState;
|
||||||
}
|
}
|
||||||
|
|
||||||
HeaterState HeaterControllerBase::GetNextState(HeaterState currentState, HeaterAllow heaterAllowState, float batteryVoltage, float sensorTemp)
|
HeaterState HeaterControllerBase::GetNextState(HeaterState currentState, HeaterAllow heaterAllowState, float heaterSupplyVoltage, float sensorTemp)
|
||||||
{
|
{
|
||||||
bool heaterAllowed = heaterAllowState == HeaterAllow::Allowed;
|
bool heaterAllowed = heaterAllowState == HeaterAllow::Allowed;
|
||||||
|
|
||||||
|
@ -50,14 +50,14 @@ HeaterState HeaterControllerBase::GetNextState(HeaterState currentState, HeaterA
|
||||||
if (heaterAllowState == HeaterAllow::Unknown)
|
if (heaterAllowState == HeaterAllow::Unknown)
|
||||||
{
|
{
|
||||||
// measured voltage too low to auto-start heating
|
// measured voltage too low to auto-start heating
|
||||||
if (batteryVoltage < HEATER_BATTETY_OFF_VOLTAGE)
|
if (heaterSupplyVoltage < HEATER_BATTETY_OFF_VOLTAGE)
|
||||||
{
|
{
|
||||||
m_batteryStableTimer.reset();
|
m_batteryStableTimer.reset();
|
||||||
return HeaterState::NoHeaterSupply;
|
return HeaterState::NoHeaterSupply;
|
||||||
}
|
}
|
||||||
else if (batteryVoltage > HEATER_BATTERY_ON_VOLTAGE)
|
else if (heaterSupplyVoltage > HEATER_BATTERY_ON_VOLTAGE)
|
||||||
{
|
{
|
||||||
// measured voltage is high enougth to auto-start heating, wait some time to stabilize
|
// measured voltage is high enough to auto-start heating, wait some time to stabilize
|
||||||
heaterAllowed = m_batteryStableTimer.hasElapsedSec(HEATER_BATTERY_STAB_TIME);
|
heaterAllowed = m_batteryStableTimer.hasElapsedSec(HEATER_BATTERY_STAB_TIME);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -181,12 +181,12 @@ void HeaterControllerBase::Update(const ISampler& sampler, HeaterAllow heaterAll
|
||||||
|
|
||||||
// If we haven't heard from the ECU, use the internally sensed
|
// If we haven't heard from the ECU, use the internally sensed
|
||||||
// battery voltage instead of voltage over CAN.
|
// battery voltage instead of voltage over CAN.
|
||||||
float batteryVoltage = heaterAllowState == HeaterAllow::Unknown
|
float heaterSupplyVoltage = heaterAllowState == HeaterAllow::Unknown
|
||||||
? sampler.GetInternalBatteryVoltage()
|
? sampler.GetInternalHeaterVoltage()
|
||||||
: GetRemoteBatteryVoltage();
|
: GetRemoteBatteryVoltage();
|
||||||
|
|
||||||
// Run the state machine
|
// Run the state machine
|
||||||
heaterState = GetNextState(heaterState, heaterAllowState, batteryVoltage, sensorTemperature);
|
heaterState = GetNextState(heaterState, heaterAllowState, heaterSupplyVoltage, sensorTemperature);
|
||||||
float heaterVoltage = GetVoltageForState(heaterState, sensorEsr);
|
float heaterVoltage = GetVoltageForState(heaterState, sensorEsr);
|
||||||
|
|
||||||
// Limit to 12 volts
|
// Limit to 12 volts
|
||||||
|
@ -195,7 +195,7 @@ void HeaterControllerBase::Update(const ISampler& sampler, HeaterAllow heaterAll
|
||||||
}
|
}
|
||||||
|
|
||||||
// duty = (V_eff / V_batt) ^ 2
|
// duty = (V_eff / V_batt) ^ 2
|
||||||
float voltageRatio = (batteryVoltage < 1.0f) ? 0 : heaterVoltage / batteryVoltage;
|
float voltageRatio = (heaterSupplyVoltage < 1.0f) ? 0 : heaterVoltage / heaterSupplyVoltage;
|
||||||
float duty = voltageRatio * voltageRatio;
|
float duty = voltageRatio * voltageRatio;
|
||||||
|
|
||||||
#ifdef HEATER_MAX_DUTY
|
#ifdef HEATER_MAX_DUTY
|
||||||
|
@ -208,7 +208,7 @@ void HeaterControllerBase::Update(const ISampler& sampler, HeaterAllow heaterAll
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (batteryVoltage >= 23)
|
if (heaterSupplyVoltage >= 23)
|
||||||
{
|
{
|
||||||
duty = 0;
|
duty = 0;
|
||||||
heaterVoltage = 0;
|
heaterVoltage = 0;
|
||||||
|
|
|
@ -36,7 +36,7 @@ void SamplingUpdateLiveData()
|
||||||
data->heaterState = (uint8_t)GetHeaterState(ch);
|
data->heaterState = (uint8_t)GetHeaterState(ch);
|
||||||
}
|
}
|
||||||
|
|
||||||
livedata_common.vbatt = GetSampler(0).GetInternalBatteryVoltage();
|
livedata_common.vbatt = GetSampler(0).GetInternalHeaterVoltage();
|
||||||
}
|
}
|
||||||
|
|
||||||
template<>
|
template<>
|
||||||
|
|
|
@ -38,13 +38,12 @@ float Sampler::GetPumpNominalCurrent() const
|
||||||
return pumpCurrentSenseVoltage * ratio;
|
return pumpCurrentSenseVoltage * ratio;
|
||||||
}
|
}
|
||||||
|
|
||||||
float Sampler::GetInternalBatteryVoltage() const
|
float Sampler::GetInternalHeaterVoltage() const
|
||||||
{
|
{
|
||||||
#ifdef BATTERY_INPUT_DIVIDER
|
#ifdef BATTERY_INPUT_DIVIDER
|
||||||
// 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?
|
return internalHeaterVoltage;
|
||||||
return internalBatteryVoltage;
|
|
||||||
#else
|
#else
|
||||||
// After 5 seconds, pretend that we get battery voltage.
|
// After 5 seconds, pretend that we get battery voltage.
|
||||||
// This makes the controller usable without CAN control
|
// This makes the controller usable without CAN control
|
||||||
|
@ -116,7 +115,7 @@ void Sampler::ApplySample(AnalogChannelResult& result, float virtualGroundVoltag
|
||||||
PUMP_FILTER_ALPHA * (result.PumpCurrentVoltage - virtualGroundVoltageInt);
|
PUMP_FILTER_ALPHA * (result.PumpCurrentVoltage - virtualGroundVoltageInt);
|
||||||
|
|
||||||
#ifdef BATTERY_INPUT_DIVIDER
|
#ifdef BATTERY_INPUT_DIVIDER
|
||||||
internalBatteryVoltage = result.BatteryVoltage;
|
internalHeaterVoltage = result.HeaterSupplyVoltage;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Shift history over by one
|
// Shift history over by one
|
||||||
|
|
|
@ -9,7 +9,7 @@ struct ISampler
|
||||||
virtual float GetNernstDc() const = 0;
|
virtual float GetNernstDc() const = 0;
|
||||||
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 GetInternalHeaterVoltage() const = 0;
|
||||||
virtual float GetSensorTemperature() const = 0;
|
virtual float GetSensorTemperature() const = 0;
|
||||||
virtual float GetSensorInternalResistance() const = 0;
|
virtual float GetSensorInternalResistance() const = 0;
|
||||||
};
|
};
|
||||||
|
@ -25,7 +25,7 @@ public:
|
||||||
float GetNernstDc() const override;
|
float GetNernstDc() const override;
|
||||||
float GetNernstAc() const override;
|
float GetNernstAc() const override;
|
||||||
float GetPumpNominalCurrent() const override;
|
float GetPumpNominalCurrent() const override;
|
||||||
float GetInternalBatteryVoltage() const override;
|
float GetInternalHeaterVoltage() const override;
|
||||||
float GetSensorTemperature() const override;
|
float GetSensorTemperature() const override;
|
||||||
float GetSensorInternalResistance() const override;
|
float GetSensorInternalResistance() const override;
|
||||||
|
|
||||||
|
@ -38,7 +38,7 @@ private:
|
||||||
float pumpCurrentSenseVoltage = 0;
|
float pumpCurrentSenseVoltage = 0;
|
||||||
|
|
||||||
#ifdef BATTERY_INPUT_DIVIDER
|
#ifdef BATTERY_INPUT_DIVIDER
|
||||||
float internalBatteryVoltage = 0;
|
float internalHeaterVoltage = 0;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
Timer m_startupTimer;
|
Timer m_startupTimer;
|
||||||
|
|
|
@ -39,7 +39,7 @@ static void UartThread(void*)
|
||||||
float lambda = GetLambda(ch);
|
float lambda = GetLambda(ch);
|
||||||
int lambdaIntPart = lambda;
|
int lambdaIntPart = lambda;
|
||||||
int lambdaThousandths = (lambda - lambdaIntPart) * 1000;
|
int lambdaThousandths = (lambda - lambdaIntPart) * 1000;
|
||||||
int batteryVoltageMv = GetSampler(ch).GetInternalBatteryVoltage() * 1000;
|
int batteryVoltageMv = GetSampler(ch).GetInternalHeaterVoltage() * 1000;
|
||||||
int duty = GetHeaterDuty(ch) * 100;
|
int duty = GetHeaterDuty(ch) * 100;
|
||||||
|
|
||||||
size_t writeCount = chsnprintf(printBuffer, 200,
|
size_t writeCount = chsnprintf(printBuffer, 200,
|
||||||
|
|
Loading…
Reference in New Issue