xoseperez / hlw8012

HLW8012 library for Arduino and ESP8266 using the Arduino Core for ESP8266.
GNU General Public License v3.0
126 stars 48 forks source link

Voltage and current power formula #19

Open ForgetCSX opened 4 years ago

ForgetCSX commented 4 years ago

Hello, I don't understand where "1000000.0" in the calculation formula comes from, the value I calculated with the formula and the deviation I measured with the power meter。

_current_multiplier = (1000000.0 * 512 * V_REF / _current_resistor / 24.0 / F_OSC);
_voltage_multiplier = (2000000.0 * 512 * V_REF * _voltage_resistor / 2.0 / F_OSC);
_power_multiplier = (1000000.0 * 128 * V_REF * V_REF * _voltage_resistor / _current_resistor / 48.0 / F_OSC);
xoseperez commented 3 years ago

This is due to the library getting the period from the sensor in microseconds, so frequency is not in Hz (as per datasheet) but in 1/us. Hence the 10^6 in the multipliers (to avoid doing the calculation afterwards).

ForgetCSX commented 3 years ago

Thank you, I see!