Multichannel Home Electricity Monitoring System

Hi to All,

I come to the emonLibCM and this forum while investigating how to start implementation of my idea for Multichannel Home Electricity Monitoring System (https://www.radevs.net/chradev/projects/Multichannel_Home_Electricity_Monitoring_System.pdf). The idea in the beginning was to use Atmega32u4 and its feature for differential inputs and built-in OP with configurable gain which can be used to connect directly (without voltage offset) up to 9 CTs. The main advantages are no necessity of DC compensation, possibility to amplify the signal for measuring of low currents more precisely and possibility to use emonLibCM and related staff with small or no changes. In such a case it will be feasible to scan single voltage and up to 9 even more (if single ended inputs are also used) current sources. Of course the report period will be seconds but enough for home monitoring system.

While reading the forum I realize that the precision is mainly limited by the value-dependent phase errors and lower computational resources of the MCU used.

That is why I started to think about possibility to move to powerful MCU like Cortex-M4 based once. My experience in using STM32 MCUs took me away to look at STM32F405 and STM32L412 MCUs well supported by STM32Cube, ChibiOS, Arduino core support for STM32 based boards (GitHub - stm32duino/Arduino_Core_STM32: STM32 core support for Arduino) etc. STM32F405 is most standard and has 3x 12-bits ADCs with DMA and work in many different modes including simultaneous scanning of sequences of external inputs. STM32L412 low power MCU and has 2x 12-bits (up to 16-bits with oversampling) ADCs with DMA also having the same simultaneous scanning modes. Both they have FPU, DSP instruction, 5+ Msps maximum conversion rate with full resolution, fast / slow channels and many other excellent features.

Other advantages are bigger RAM, FLASH and wide communication options including USB even high speed (up to 480 Mbps) if ULPY PHY is used with STM32F405. Availability of Arduino port for these devices will make it easier to port emonLibCM for them.

Of course, the other big advantage could possibility to divide ADC sampling and RMS calculations and process them in parallel. Calculation of RMS values can be done in parallel with ADC sampling combined with DMA to a dual value ring buffer together with sequential simultaneous scanning of voltage and current source sequences. Ring buffer calculations can be combined with dynamic phase correction simply multiplying voltage and current values with value correlated offset. And the cherry of the cake will be if DSP instructions are used for the calculation. From the communication point of view the high speed U(S)ARTs and USB both working with DMA can be used to unload CPU for calculations and other activities. Other option is to use multi-threaded RTOS with good synchronization between calculations and transfer functionality.

One disadvantage of using STM32F4 MCUs is that no internal gain control to differential input option.

My question: What is more important: to use Atmega32u4 adding differential and gain control or to move to STM32F4 alternative for solving phase error issue where differential option is possible without gain control.

Best regards
Chris

Welcome, Chris, to the OEM forum.

Have you read the many threads here about the work that was done here on the STM32? It was looking very promising - but availability became a serious problem that forced us - hopefully only as a short-term solution - to the AVR-DB. I wasn’t directly involved, so I can’t offer any more details.

Hi Robert,

Thanks for your prompt replay.

I think that availability is not a problem. You can take a look on Olimex site:

where STM32F3/F4 have long term availability. My preference is STM32-H405 because of its simplicity and all resources availability.

On the other hand ST boards for example NUCLEO-L412KB and NUCLEO-L412RB-P are available on Digi-Key for 11.15 € and 16.19 € respectively. 48 and 64 pins STM32L412 chips are also available at 5-7 € for small quantities. In may opinion development and production of a new board for 8+ CTs with MCU on it is not more complex than the board without MCU.

About the other forum posts about using STM32 alternative it lies ahead of me.

Dear All,

Following Robert’s advice to read forum publications about stm32 alternative I realize that adopted solution based on stm32f303 MCU and emonPI is quite different from my expectations. That is why I decided first to test the idea to use Arduino Leonardo compatible board from Olimex like OLIMEXINO-32U4, OLIMEXINO-NANO or AVR-T32U4 (AVR - Open Source Hardware Boards). I will experiment with the differential ADC inputs, working with 8/12 small CTs like once offered by Olimex (Current) SNS-CURRENT-HWCT-5A-5MA, single SNS-CURRENT-CT013-100A to measure total consumption and AC-AC adapter for measuring the voltage. My experiments will be based on emonLibCM and Lluis Pamies-Juarez (llpamies) experience.

Next important for me experiment is to assess possibility to use native USB of ATMEGA32U4 MCU to transfer data to the nearby host based on Olimex A20-OLINUXINO-LIME2 board like LIME2-SERVER with SSD and battery backup connected to the home network. Currently I am not sure to use EmonCMS or not.

One basic question I would like to discuss is about ADC sequences. Is it better to scan V, CT0, CT1, …, CTn (where n = 4/8/12 and CT0 is sensor to measure total consumption) or V, CT0, CT1, …, CT4, V, CT5, …, CT8, V, CT9, …, CT12?

Here CT0-8 will be connected to differential ADC inputs and CT9-12 will be optional via additional board and could be CT013 or HWCT current sensors connected like in EmonTx Shield. Most likely the HW design will be stack with boards (Olimexino + 2 shields in a box attached to LIME2-SERVER and connected via native USB).

Other important questions are:

  • is it good idea to use shielded cable with twisted wires to connect HWCT CTs?
  • to use RC high frequency filtering for the voltage and current sensors or not?
  • how to deal with distortion of sinusoidal form in some CTs and VTs?

Any recommendations and help to find the above answers will be highly appreciated.

Regards
Chris

I’m afraid I simply don’t have the time that I feel your questions demand in order to respond in depth. Some of the points relate to fundamental questions that could be answered in good electrical and electronic engineering textbooks, I hope other contributors can help with the remaining points.

Thanks Robert, I hope so.

There are some steps doing after my last posts. Simple alternative of MEM (Multichannel Electricity Monitoring) system was successfully prototyped and tested with modified version of emonLibCM on Leonardo compatible board (AVR-T32U4 by Olimex).

It works fine with all 12 ADC single ended inputs. The test were made with simulation of currents up to 20A and scan period of 1 sec. Typical output in JSON format looks like:

{ Va: 227.90, Hz: 50.016, Sp: 1,
  Ia: [ 16.098, 16.080, 16.074, 16.075, 16.077, 16.076, 16.075, 16.077, 16.077, 16.075, 16.074 ],
  PF: [ 0.9997, 0.9998, 0.9999, 0.9999, 0.9999, 0.9999, 0.9999, 0.9998, 0.9998, 0.9997, 0.9997 ],
  Wr: [   3668,   3664,   3663,   3663,   3664,   3663,   3663,   3663,   3663,   3662,   3662 ],
  Wa: [   3669,   3665,   3663,   3664,   3664,   3664,   3664,   3664,   3664,   3663,   3663 ],
  Wh: [     47,     46,     46,     46,     46,     46,     46,     46,     46,     46,     46 ],
}

More details can be seen in updated version of Multichannel Home Electricity Monitoring System.

The functionality of emonLibCM was achieved by very simple changes in the library tied mainly with ability to access more ADC features of ATMEGA32U4 MCU.

This is the first step to use all ADC features especially differential inputs and the gain control of the internal opp amp.

Regards
Chris