Khaalidi / HLW8032

A lightweight library for the HLW8032 SOP8 high precision energy metering IC
MIT License
50 stars 15 forks source link

current value note coming #4

Open faezehFrj opened 3 years ago

faezehFrj commented 3 years ago

hello. tanks for your library. actually I use Arduino mega in this project. The voltage is received quite correctly but current not. I design this project like below picture: Schematic

I hope you can help me ;(

Mbilal337 commented 3 years ago

@faezehFrj hello I'm also facing the same issue.. did you find any solution for this ?

ArashGolsaz commented 3 years ago

Hi I had your problem too... You must make changes to this library : 1- At this address : Arduino\libraries\HLW8032-master\HLW8032.ccp you must change the variable type "CF" to float 2- At this address : Arduino\libraries\HLW8032-master\HLW8032.h you must change the value of variable "CurrentRF" to the value of the shunt current resistance used. I came to the conclusion by applying these changes. good luck. 👍

Mbilal337 commented 3 years ago

hi @ArashGolsaz Thanks for you reply . I already made the changes that you mentioned as I was thinking this is problem with datatype casting and I started getting the current values but those values are not accurate because when I calculate power using those (with know load attached ) then it's way of the required values plus negative sign kept appearing repeatedly.
So any fix for that ? Do I need to take RMS ?

Also in GetKwh() function in HLW8032.cpp file, I changed these lines :

*uint32_t PFcnt = (1 / PowerPar) (1 / InspectingPower) 1000000000 3600;**

to :

float PFcnt = (1 / PowerPar) (1 / (CF VF) ) 1000000000 3600;

and

*float KWh = (PFData PF) / PFcnt;**

to: *float KWh = ((PFData 65536) + PF) / PFcnt;**

as per mentioned in Datasheet page#17 . then I was able to get the correct kwh

millerboy-k commented 2 years ago

@faezehFrj hello I'm also facing the same issue.. did you find any solution for this ?

file HLW8032.cpp, replace GetCurrent() and GetCurrentAnalog() ///

*float HLW8032::GetCurrent() { float Current = GetCurrentAnalog() CF;;
return Current; } float HLW8032::GetCurrentAnalog() { float FCurrentPar = CurrentPar; float Current = FCurrentPar / (float)CurrentData; return Current;**

/// this code i get from https://github.com/ocrobot/HLW8032