mirror of
https://github.com/esphome/esphome.git
synced 2024-12-25 06:54:52 +01:00
fix negative result calculation
This commit is contained in:
parent
59cba62e20
commit
82c404c67b
1 changed files with 1 additions and 5 deletions
|
@ -101,17 +101,13 @@ float MCP3428Component::request_measurement(MCP3428Multiplexer multiplexer, MCP3
|
||||||
yield();
|
yield();
|
||||||
}
|
}
|
||||||
|
|
||||||
// got valid measurement, clean up unused bits from the anwser code and prepare tick size
|
// got valid measurement prepare tick size
|
||||||
float tick_voltage = 2.048f / 32768; // ref voltage 2.048V/non-sign bits, default 15 bits
|
float tick_voltage = 2.048f / 32768; // ref voltage 2.048V/non-sign bits, default 15 bits
|
||||||
switch (resolution) {
|
switch (resolution) {
|
||||||
case MCP3428Resolution::MCP3428_12_BITS:
|
case MCP3428Resolution::MCP3428_12_BITS:
|
||||||
// Structure [sign][sign][sign][sign][sign][value][value][value], only keep sign at MSB for int16_t
|
|
||||||
anwser[0] &= 0b10000111;
|
|
||||||
tick_voltage *= 16;
|
tick_voltage *= 16;
|
||||||
break;
|
break;
|
||||||
case MCP3428Resolution::MCP3428_14_BITS:
|
case MCP3428Resolution::MCP3428_14_BITS:
|
||||||
// Structure [sign][sign][sign][value][value][value][value][value]
|
|
||||||
anwser[0] &= 0b10011111;
|
|
||||||
tick_voltage *= 4;
|
tick_voltage *= 4;
|
||||||
break;
|
break;
|
||||||
default: // nothing to do for 16 bit
|
default: // nothing to do for 16 bit
|
||||||
|
|
Loading…
Reference in a new issue