From 55037b6c51e48ba36ab2b2fb2bce424942a71c6b Mon Sep 17 00:00:00 2001 From: migmaroto Date: Mon, 3 Oct 2022 16:05:18 -0500 Subject: [PATCH 1/2] feat: add methods SetOffsetNoLoad and GetCurrentWithoutOffset --- src/BslibEnergyMeter.h | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/BslibEnergyMeter.h b/src/BslibEnergyMeter.h index c5c06e9..5b94ef0 100644 --- a/src/BslibEnergyMeter.h +++ b/src/BslibEnergyMeter.h @@ -29,6 +29,7 @@ class BslibEnergyMeter { void SetCurrentReference(int _currentReference); void SetAnalogReference(float _analogReference); + void SetOffsetNoLoad(float _offsetWithoutLoad); void SetFilterSamples(unsigned int _numberOfSamples); int FilterValueADC(unsigned int pinADC); @@ -41,6 +42,7 @@ class BslibEnergyMeter { int GetCurrentADC(); float GetCurrentDAC(); float GetCurrent(); + float GetCurrentWithoutOffset(); void CalVoltage(); int GetVoltageADC(); @@ -63,6 +65,7 @@ class BslibEnergyMeter { float factorCurrent; float factorVoltage; float offsetVoltage; + float offsetWithoutLoad; }; #endif From 868675c26f1016a3fb2f9209ef49542588c9508e Mon Sep 17 00:00:00 2001 From: migmaroto Date: Mon, 3 Oct 2022 16:06:14 -0500 Subject: [PATCH 2/2] feat: add function SetOffsetNoLoad and GetCurrentWithoutOffset --- src/BslibEnergyMeter.cpp | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/src/BslibEnergyMeter.cpp b/src/BslibEnergyMeter.cpp index 1476f31..ab57d78 100644 --- a/src/BslibEnergyMeter.cpp +++ b/src/BslibEnergyMeter.cpp @@ -18,6 +18,7 @@ int currentADC; int currentRefADC; float currentDAC; float current; +float offsetWithoutLoad; int voltageADC; float voltageDAC; @@ -69,6 +70,15 @@ void BslibEnergyMeter::SetCurrentReference(int _currentReference) { currentReference = _currentReference; } +/** + * @brief Se usa para estabblecer la corriente de offset tiempo antes de la activacion de la carga + * + * @param _currentReference + */ +void BslibEnergyMeter::SetOffsetNoLoad(float _offsetWithoutLoad) { + offsetWithoutLoad = _offsetWithoutLoad; +} + /** * @brief Configura el valor de referencia analógica para el MCU * @@ -155,11 +165,22 @@ int BslibEnergyMeter::GetCurrentADC() { float BslibEnergyMeter::GetCurrentDAC() { return currentDAC; } + float BslibEnergyMeter::GetCurrent() { CalCurrent(); return current; } +float BslibEnergyMeter::GetCurrentWithoutOffset() { + CalCurrent(); + float currentWithoutOffset; + if ((current - offsetWithoutLoad) <= 0) { + currentWithoutOffset = 0; + } else { + currentWithoutOffset = current - offsetWithoutLoad; + } + return currentWithoutOffset; +} // ----------------------------------------------------------- void BslibEnergyMeter::CalVoltage() {