rusEFI
The most advanced open source ECU
Loading...
Searching...
No Matches
Public Member Functions | Private Attributes
ResistanceFunc Class Referencefinal

#include <resistance_func.h>

Inheritance diagram for ResistanceFunc:
Inheritance graph
[legend]
Collaboration diagram for ResistanceFunc:
Collaboration graph
[legend]

Public Member Functions

void configure (float supplyVoltage, float pullupResistor, bool isPulldown)
 
SensorResult convert (float inputValue) const override
 
void showInfo (float testInputValue) const override
 
- Public Member Functions inherited from SensorConverter
 SensorConverter (const SensorConverter &)=delete
 
 SensorConverter ()=default
 

Private Attributes

float m_supplyVoltage = 5.0f
 
float m_pullupResistor = 1000.0f
 
bool m_isPulldown = false
 

Detailed Description

Author
Matthew Kennedy, (c) 2019

A function to convert input voltage to resistance in a voltage divider. Configured with the value of the pullup resistor, and the voltage to which it's connected.

Definition at line 13 of file resistance_func.h.

Member Function Documentation

◆ configure()

void ResistanceFunc::configure ( float  supplyVoltage,
float  pullupResistor,
bool  isPulldown 
)
Author
Matthew Kennedy, (c) 2019

Definition at line 7 of file resistance_func.cpp.

7 {
8 m_pullupResistor = pullupResistor;
9 m_supplyVoltage = supplyVoltage;
10 m_isPulldown = isPulldown;
11}

Referenced by initRangeSensors().

Here is the caller graph for this function:

◆ convert()

SensorResult ResistanceFunc::convert ( float  inputValue) const
overridevirtual

Implements SensorConverter.

Definition at line 13 of file resistance_func.cpp.

13 {
14 // If the voltage is very low, the sensor is a dead short.
15 if (raw < 0.05f) {
16 return UnexpectedCode::Low;
17 }
18
19 // If the voltage is very high (98% VCC), the sensor is open circuit.
20 if (raw > (m_supplyVoltage * 0.98f)) {
21 return UnexpectedCode::High;
22 }
23
24 if (m_isPulldown) {
25 // If the sensor is on the high side (fixed resistor is pulldown),
26 // invert the voltage so the math comes out correctly
27 raw = m_supplyVoltage - raw;
28 }
29
30 // Voltage is in a sensible range - convert
31 float resistance = m_pullupResistor / (m_supplyVoltage / raw - 1);
32
33 return resistance;
34}

Referenced by showInfo().

Here is the caller graph for this function:

◆ showInfo()

void ResistanceFunc::showInfo ( float  testInputValue) const
overridevirtual

Reimplemented from SensorConverter.

Definition at line 93 of file sensor_info_printing.cpp.

93 {
94 const auto result = convert(testInputValue);
95 efiPrintf(" %.2f volts -> %.1f ohms with supply voltage %.2f and pullup %.1f.", testInputValue, result.Value, m_supplyVoltage, m_pullupResistor);
96}
SensorResult convert(float inputValue) const override
Here is the call graph for this function:

Field Documentation

◆ m_isPulldown

bool ResistanceFunc::m_isPulldown = false
private

Definition at line 24 of file resistance_func.h.

Referenced by configure(), and convert().

◆ m_pullupResistor

float ResistanceFunc::m_pullupResistor = 1000.0f
private

Definition at line 23 of file resistance_func.h.

Referenced by configure(), convert(), and showInfo().

◆ m_supplyVoltage

float ResistanceFunc::m_supplyVoltage = 5.0f
private

Definition at line 22 of file resistance_func.h.

Referenced by configure(), convert(), and showInfo().


The documentation for this class was generated from the following files: