fix shunt voltage / current / power reading in INA3221 (#1101)

* fix shunt voltage / current / power reading in INA3221

* support nagetive shunt voltage reading

* fix loss of precision
This commit is contained in:
vxider 2020-06-29 05:50:20 +08:00 committed by GitHub
parent 83a12d980e
commit c041cc483c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -100,7 +100,7 @@ void INA3221Component::update() {
this->status_set_warning();
return;
}
const float shunt_voltage_v = int16_t(raw) * 40.0f / 1000000.0f;
const float shunt_voltage_v = int16_t(raw) * 40.0f / 8.0f / 1000000.0f;
if (channel.shunt_voltage_sensor_ != nullptr)
channel.shunt_voltage_sensor_->publish_state(shunt_voltage_v);
current_a = shunt_voltage_v / channel.shunt_resistance_;