Skip to content

Commit

Permalink
sensor checker knows about 5v sensor supply voltage
Browse files Browse the repository at this point in the history
  • Loading branch information
mck1117 committed Jan 4, 2025
1 parent aa7ceeb commit 04a6a2c
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 13 deletions.
4 changes: 2 additions & 2 deletions firmware/controllers/algo/obd_error_codes.h
Original file line number Diff line number Diff line change
Expand Up @@ -676,8 +676,8 @@ enum class ObdCode : uint16_t {
//P0639 Throttle Actuator Control Range/Performance (Bank 2)
//P0640 Intake Air Heater Control Circuit
//P0641 Sensor Reference Voltage “A” Circuit/Open
//P0642 Sensor Reference Voltage “A” Circuit Low
//P0643 Sensor Reference Voltage “A” Circuit High
Sensor5vSupplyLow = 642,
Sensor5vSupplyHigh = 643,
//P0644 Driver Display Serial Communication Circuit
//P0645 A/C Clutch Relay Control Circuit
//P0646 A/C Clutch Relay Control Circuit Low
Expand Down
35 changes: 24 additions & 11 deletions firmware/controllers/sensors/sensor_checker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -147,17 +147,30 @@ static ObdCode getCodeForIgnition(int idx, brain_pin_diag_e diag) {
#endif // BOARD_EXT_GPIOCHIPS > 0 && EFI_PROD_CODE

void SensorChecker::onSlowCallback() {
bool batteryVoltageSufficient = Sensor::getOrZero(SensorType::BatteryVoltage) > 7.0f;

// Don't check when:
// - battery voltage is too low for sensors to work
// - the ignition is off
// - ignition was just turned on (let things stabilize first)
// TODO: also inhibit checking if we just did a flash burn, since that blocks the ECU for a few seconds.
bool shouldCheck = batteryVoltageSufficient && m_ignitionIsOn && m_timeSinceIgnOff.hasElapsedSec(5);
m_analogSensorsShouldWork = shouldCheck;
if (!shouldCheck) {
return;
if (Sensor::hasSensor(SensorType::Sensor5vVoltage)) {
float sensorSupply = Sensor::getOrZero(SensorType::Sensor5vVoltage);

// Inhibit checking if the sensor supply isn't OK, but register a warning for that instead
if (sensorSupply > 5.25f) {
warning(ObdCode::Sensor5vSupplyHigh, "5V sensor supply high: %.2f", sensorSupply);
return;
} else if (sensorSupply < 4.75f) {
warning(ObdCode::Sensor5vSupplyLow, "5V sensor supply low: %.2f", sensorSupply);
return;
}
} else {
bool batteryVoltageSufficient = Sensor::getOrZero(SensorType::BatteryVoltage) > 7.0f;

// Don't check when:
// - battery voltage is too low for sensors to work
// - the ignition is off
// - ignition was just turned on (let things stabilize first)
// TODO: also inhibit checking if we just did a flash burn, since that blocks the ECU for a few seconds.
bool shouldCheck = batteryVoltageSufficient && m_ignitionIsOn && m_timeSinceIgnOff.hasElapsedSec(5);
m_analogSensorsShouldWork = shouldCheck;
if (!shouldCheck) {
return;
}
}

// Check sensors
Expand Down
1 change: 1 addition & 0 deletions firmware/controllers/sensors/sensor_type.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ enum class SensorType : unsigned char {

BatteryVoltage,
MainRelayVoltage,
Sensor5vVoltage,

BarometricPressure,

Expand Down

0 comments on commit 04a6a2c

Please sign in to comment.