Skip to content

Commit 01871e8

Browse files
committed
heater: always rely on localy measured heater voltage
if board able to measure it localy
1 parent b02e1c9 commit 01871e8

3 files changed

Lines changed: 15 additions & 17 deletions

File tree

firmware/heater_control.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -199,14 +199,14 @@ void HeaterControllerBase::Update(const ISampler& sampler, HeaterAllow heaterAll
199199
float sensorEsr = sampler.GetSensorInternalResistance();
200200
float sensorTemperature = sampler.GetSensorTemperature();
201201

202-
#ifdef BOARD_HAS_VOLTAGE_SENSE
202+
#if defined(HEATER_INPUT_DIVIDER)
203+
// if board has ability to measure heater supply localy - use it
204+
float heaterSupplyVoltage = sampler.GetInternalHeaterVoltage();
205+
#elif defined(BOARD_HAS_VOLTAGE_SENSE)
203206
float heaterSupplyVoltage = GetSupplyVoltage();
204207
#else // not BOARD_HAS_VOLTAGE_SENSE
205-
// If we haven't heard from the ECU, use the internally sensed
206-
// battery voltage instead of voltage over CAN.
207-
float heaterSupplyVoltage = heaterAllowState == HeaterAllow::Unknown
208-
? sampler.GetInternalHeaterVoltage()
209-
: GetRemoteBatteryVoltage();
208+
// this board rely on measured voltage from ECU
209+
float heaterSupplyVoltage = GetRemoteBatteryVoltage();
210210
#endif
211211

212212
// Run the state machine

firmware/sampling.cpp

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -38,21 +38,15 @@ float Sampler::GetPumpNominalCurrent() const
3838
return pumpCurrentSenseVoltage * ratio;
3939
}
4040

41+
#ifdef HEATER_INPUT_DIVIDER
42+
// Dual HW can measure heater voltage for each channel
43+
// by measuring voltage on Heater- while FET is off
4144
float Sampler::GetInternalHeaterVoltage() const
4245
{
43-
#ifdef HEATER_INPUT_DIVIDER
44-
// Dual HW can measure heater voltage for each channel
45-
// by measuring voltage on Heater- while FET is off
4646
return internalHeaterVoltage;
47-
#else
48-
// After 5 seconds, pretend that we get battery voltage.
49-
// This makes the controller usable without CAN control
50-
// enabling the heater - CAN message will be able to keep
51-
// it disabled, but if no message ever arrives, this will
52-
// start heating.
53-
return m_startupTimer.hasElapsedSec(5) ? 13 : 0;
54-
#endif
47+
5548
}
49+
#endif
5650

5751
float Sampler::GetSensorTemperature() const
5852
{

firmware/sampling.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@ struct ISampler
99
virtual float GetNernstDc() const = 0;
1010
virtual float GetNernstAc() const = 0;
1111
virtual float GetPumpNominalCurrent() const = 0;
12+
#ifdef HEATER_INPUT_DIVIDER
1213
virtual float GetInternalHeaterVoltage() const = 0;
14+
#endif
1315
virtual float GetSensorTemperature() const = 0;
1416
virtual float GetSensorInternalResistance() const = 0;
1517
};
@@ -25,7 +27,9 @@ class Sampler : public ISampler
2527
float GetNernstDc() const override;
2628
float GetNernstAc() const override;
2729
float GetPumpNominalCurrent() const override;
30+
#ifdef HEATER_INPUT_DIVIDER
2831
float GetInternalHeaterVoltage() const override;
32+
#endif
2933
float GetSensorTemperature() const override;
3034
float GetSensorInternalResistance() const override;
3135

0 commit comments

Comments
 (0)