fabianoriccardi / dimmable-light

Arduino library to manage dimmers compatible with AVR, ESP8266, ESP32, SAMD, and RP2040 platforms.
GNU Lesser General Public License v2.1
97 stars 29 forks source link

THDi calculation #52

Closed mathieucarbou closed 9 months ago

mathieucarbou commented 10 months ago

THDi can be calculated based on the power factor and phase angle (deplacement factor).

Since we know in the dimmer library the time when the dimmer is activated, is there a way to derive the angle to get the cosPhi ?

      // https://fr.electrical-installation.org/frwiki/Indicateur_de_distorsion_harmonique_:_facteur_de_puissance
      const float phi = 0; // TODO: find angle
      const float pf = getTotalPowerFactor();
      return sqrt(pow(cos(phi), 2) / pow(pf, 2) - 1);
mathieucarbou commented 10 months ago

Actually, thinking about it... This is a resistive load so as looking at the oscilloscope graphs (https://yasolr.carbou.me/overview), there is no phase shift between U and I so phi should be 0 and cos phi 1.