Skip to content

Commit

Permalink
THDi
Browse files Browse the repository at this point in the history
  • Loading branch information
mathieucarbou committed Feb 24, 2024
1 parent cf052b2 commit 417bb5c
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/MycilaPZEM004Tv3.h
Original file line number Diff line number Diff line change
Expand Up @@ -96,11 +96,20 @@ namespace Mycila {
float getPowerFactor() const { return _powerFactor; }
float getApparentPower() const { return _powerFactor == 0 ? 0 : _power / _powerFactor; }
float getVoltage() const { return _voltage; }

float getResistance() const {
const float c = _current;
return c == 0 ? 0 : _voltage / c;
}

float getTHDi(float phi) const {
const float pf = _powerFactor;
if (pf == 0)
return 0;
// https://fr.electrical-installation.org/frwiki/Indicateur_de_distorsion_harmonique_:_facteur_de_puissance
return sqrt(pow(cos(phi), 2) / pow(pf, 2) - 1);
}

// get the uptime in milliseconds of the last successful read
uint32_t getTime() const { return _lastReadSuccess; }

Expand Down

0 comments on commit 417bb5c

Please sign in to comment.