Over 10 years we help companies reach their financial and branding goals. Engitech is a values-driven technology agency dedicated.

Gallery

Contacts

411 University St, Seattle, USA

engitech@oceanthemes.net

+1 -800-456-478-23

Current/Power Sensors Sensors and Modules TIMER Modules

HLW8012 AC Energy metering IC: Part 1

Table of Contents

So hello guys, welcome back to Gettobyte Once again. Todays blog is going to be on interfacing the Energy metering IC : HLW8012 which is manufactured by

HLW Technology.On previous blogs we have developed the application driver

 

for W25Q SPI based flash memory\’s,

is time we are going to develop the Application driver for HLW8012.

So first question that must come in your mind is that what is Energy Metering IC. Lets first Understand this term.

What are Energy Metering Integrated Chips ?

Before Understanding Energy metering IC\’s their is one term that i would like to get familiar my viewers that is ASIC\’s. ASIC\’s are Application Specific Integrated Chips i.e. chips which are designed, developed and fabricated for particular applications. 

Energy Metering IC\’s are one of the ASIC\’s. In this case the specific application is that of Electrical Energy Measurement. By the use and emergence of Energy Metering IC\’s we can calculate the Electrical Energy parameters like RMS/Instantaneous Voltage, RMS/Instantaneous Current, Reactive/Active/Apparent Power, Energy Consumed, Power loss/dissipation, Power factor, Frequency digitally.

Using this electrical Energy Measurements only our monthly electrical energy bill is calculated. These electrical energy parameters play very important role for monitoring and analyzing of Power consumption in our homes, offices, factories, city\’s and all such infrastructures where their is use of electricity. These Ic\’s are widely used in Energy Meters, Multifunction Meters, Smart Energy meters, Solar Energy control panels, Factory Automation Panels and etc.

Energy metering IC\’s are designed using the knowledge of ADC, Opamps, Low pass/High pass filters, use of Analog Electronics with Power Electronics, DSP(Digital Signal processing), Signal Conditioning circuits. All these circuits are designed inside the Energy Metering IC\’s using VLSI/VHDL. That is where the concept of Application Specific comes in. So when reading the datasheet of Energy Metering IC\’s some overview about these terms and terminologies would be beneficial for understanding the functioning of these IC\’s.

Voltage and current drive the world in every sense. Using these 2 parameters we can calculate all other electrical energy parameters be it reactive power, active power, energy, frequency, power factor and etc.

Energy Metering IC\’s primarily measures/senses only Voltage and Current by the use of Signal conditioning circuits, ADC, Opamps, Analog Electronics. Further these IC\’s calculates all other Electrical energy parameters using DSP, Low pass/High pass filters and etc.

All of these things are designed inside the Energy metering IC\’s. Input voltage and current to these IC\’s are fed depending upon the principal which we are using for sensing Voltage and current.

After feeding the Input to these IC\’s via one of the above principals, comes the role of above mentioned circuits/units which are designed inside the chips for their efficient functioning and digital accurate readings.

Energy metering IC\’s which are widely used are of

The above listed metering IC\’s and their development boards are very expensive, so for my use case i have found out some cheap/alternative Energy Metering IC\’s, but their manufacturer are Chinese companies:

Previous slide
Next slide

General Description of HLW8012 Energy Metering IC

HLW8012 is a single phase energy metering IC, which is based on shunt resistor based principal. The HLW8012 module has on board 1 milli-ohm copper-manganese shunt resistor, which acts as a shunt resistor and used to sense the voltage and current.

One of the biggest problem with IC, is its datasheet. The datasheet of this IC is in Chinese language, so likely it would be difficult to understand from it.

The IC can measure the RMS Voltage, RMS Current, Active power and Outputs these reading digitally in the form of PWM signals.

HLW8012 is a good choice for making small and hobbyist kind of projects which requires the measurement of AC electrical parameters. One such project/product that I found, is made on HLW8012. HLW8012 is inexpensive and good alternative to be used in comparison to  other expensive metering IC\’s.

The module of HLW8012 is very handy and easy to use. It has 4 input terminals: 2 terminals are connected with AC Load and other 2 terminals are connected with AC Power supply.

HLW8012 Outputs the Readings of Voltage, Current and power via PWM signals of 50 percent duty cycle, Their are two pins in HLW8012 CF and CF1 which outputs the voltage, current and power readings in a digital PWM square signal, which host MCU can capture using Timer Input Capture mode. The readings are directly proportional to the Frequency of the PWM signal. Every modern MCU has Timer peripheral, which we can configure in Timer Input capture mode. In this mode Host MCU can capture the PWM signals from external world (here our external world is HLW8012). That\’s how HLW8012 will communicate with the Host MCU.

Features of HLW8012 Energy Metering IC

Block Diagram of HLW8012 Metering IC

PINOUT of the HLW8012 Energy metering IC

Communication of HLW8012 with HOST MCU

HLW8012 doesn\’t communicate in SPI, I2C, or any serial communication protocol. It rather does work in a much simpler way kind of like a DHT11 sensor. HLW8012 is an intelligent IC that outputs the readings of RMS voltage, RMS current, and active power in PWM signal waveforms via CF and CF1 pin.\"\"

PWM signals are the series of pulses of High and low DC signals. PWM signals have characteristics like Frequency, Duty Cycle, Time Period, Pulse width and etc. Out of these characteristics in our case time period and frequency are the ones which will be of our concern.\"\"

Microcontrollers can output these PWM signals and can also measure these PWM signals. Microcontrollers do so with the help of TIMER peripherals. When MCU output the PWM signals, then Timer peripheral is configured in OUTPUT CAPTURE MODE, when MCU measures these PWM signals then Timer peripheral is configured in INPUT CAPTURE MODE.

So in our case, we are going to focus on TIMER INPUT CAPTURE MODE because we have to measure the PWM signals coming from the HLW8012. Now HLW8012 outputs the PWM signals at a fixed duty cycle, ie. 50 percent. But the Frequency of these PWM signals is directly proportional to the readings of Voltage, Current and Active Power.

So in nutshell, we just want to know the Frequency of these PWM signals, which are outputted by CF and CF1 from then we can compute the time period of PWM signals. Once we get that we can get to know about RMS Voltage, RMS Current, and Active power by feeding those values into the below formulas.

// Write formulas here

There is a concept of multipliers in HLW8012 that has to be understood, that part is covered in the Configuration of HLW8012 of the next blog.

In our code, we are going to configure the TIMER peripheral in Input Capture Mode using Interrupt. To know more about this and how is it done for host MCU( here STM32F103-blue-pill), you can refer to this blog. In the Application code here, I am directly going to use the API of TIMER INPUT CAPTURE MODE. For an in-depth analysis, of this configuration, you can refer to this blog.

Closing

So that\’s all about the HLW8012 Energy metering IC in this blog. Hope you have got the clear and better idea about this IC and its module.

Now in the next blog, i have developed the application driver for using this IC with STM32F103 MCU, using its TIMER INPUT CAPTURE MODE.

The driver would be pretty generic one, can be used with other Controllers also by just changing some core driver API\’s.

Author

Kunal

Leave a comment

Stay Updated With Us

Error: Contact form not found.

      Blog