Thursday, December 14, 2017

Sense Energy monitor teardown - sampling in MHz

Recently I obtained a Sense Energy monitor via US from Margaret of BitKnitting. She is doing a very interesting neighbourhood energy efficiency project. As usual I could not contain my curiosity and opened it up to have a look. I will start off with an analogy - the closest bit of open-source kit that I have to do half the amount of analog functions as the Sense is the PRUDAQ on the BeagleBone wifi as pictured below.
Beaglebone Wireless + PRUDAQ
The case is very well built from high density plastic, however it is clipped together neatly and easy to take off without permanent damage. The wifi antenna is screwed on with a neat water sealed connector. The power/voltage and current sampler connectors are Molex Microfit and Nanofit respectively. I rather liked the Molex Nanofit and adopted it for my own DIN Rail sampler board.
Enclosure and main boards
Inside this very nice exterior are a couple of very dense sandwiched PCB's. One is Green, almost a generic power supply board, but with additional function to sample the split phase AC in the North American grid. The other is a black board where the magic happens. It is essentially a beaglebone wireless with a custom energy monitor system put together using high-speed ADC's and a CPLD
Green Power board, Black Digital+Analog board

Main PMIC, same one is used on the BeagleBone Black
The image below shows the subsection that performs energy measurements, it is composed of x2 high sample rate ADC's (14bit 2MSPS) and an Altera Max V 64pin CPLD. I assume the cells inside the CPLD perform the reading from the ADC's and multiplication/accumulation to compute energy usage, then transmit computation results to the TI CPU.

Custom energy monitor with high-speed (2MSPS) ADC's and Altera CPLD

Wifi Module
Switcher IC's on power supply board

The main CPU is a Linux compatible AM3352 CPU from TI. It does not have a PRU co-processor like the one used on the BeagleBone, hence the need for a CPLD to perform some of the real-time computation required.
TI Arm CPU and RAM/Flash

Overall the Sense energy monitor hardware is a great design, though a bit specific to the USA market. I am looking forward to a release in the Australian market. The purchase to study one was certainly worth it. Now off to install my own linux build on it and send the data elsewhere.

Thursday, October 12, 2017

Simulating 3-phase AC for Energy Monitor testing

Finding 3-phase is difficult, convincing the owner of the said supply to test some home made hardware is even more so. After building a 3-phase energy monitor my testing options for it appeared very limited. So I set about making my own low-cost 3-phase energy monitor calibration system. Here are some build photos.
Initial testing with DSO scope
Arduino code and Sine-wave table
The main protagonists of this build are the Teensy 3.2 and MCP4728 4-channel I2C DAC. The Teensy pushes an integer valued sine-wave array into the DAC which is then RC-filtered and amplified via some opamps.

With target energy monitor
Eventually I worked up a budget to buy myself a 4-channel Rigol scope from Emona. This showed the nice equal amplitude and properly phased 50-Hz waveform the DAC was producing.


3-phase voltages on oscilloscope
There is more of a backstory and details about this project in the DIYODE Magazine article. I have tested this a fair bit now as well with ATM90E36 Energy Monitor IC and will look at adding power opamps and transferring to a PCB. Below is a video of a 3-phase energy monitor test rig using synthesized waveform vs 12V AC-AC transformer.

Sunday, August 13, 2017

PyconAu 2017 - Melbourne

I recently attended my first PyconAu - a cauldron of programming goodness. It was held in cloudy and grey Melbourne at the convention center. The exact same venue I attended the Nvidia conference a while ago. It was three days of information flow and meeting very interesting people. I jotted down some quick notes in my Keep and I will flesh them out here for my own reference.

These were the sessions where I had more detailed notes and some photos:

GnuRadio Python bindings and simulator. SoapySDR. HackRF simplex hardware including a freaky demo of using playback attack to unlock cars by copying car remotes.
An update on the state of MicroPython. A live demo with I2C read from gyroscope controlling a servo. New stuff like help('modules'), upip install, VFS , assembler, Zephyr RTOS etc. Really got into this one. The idea of having line by line firmware building convenience and a REPL on an embedded device is oh so appealing.
The Murchison Widefield Array(MWA) and sampling the universe at 655MSPS - Rocket IO to Xilinix. FPGA Fourier variants and finaly 24 of 256 spectral channels trickling back to Perth at 10Gbps. The processing electronics is double Faraday caged to prevent RF feeding back into the telescope.
The messaging of data from IoT devices while minimizing data usage and allowing convenience and transfer of state. Various contenders are JSON, Avro, Protobuf and MQTT over Websockets or simple HTTP, with advantages in HTTP v2 due to header compression via HPACK.

Presentation featuring GUI's for IoT devices and a glowing orb seen in a famous Trump photograph. With interesting details about Progressive Web Apps and Javascript based IoT controls.
Another very very impressive demo came from Russell showing Python running on 6 different platforms on a few minutes. After that I should really checkout our BeeWare. Will have to write a full length article on it as well with a proper usage tutorial to earn these great looking challenge coins.

During the breaks people were leaving notes seeking jobs, offering jobs or setting a topic for a lightning talk. The looking for employees board was slightly daunting but I put up a brave little ad featuring Aerometrex anyway. I also gave a brave little talk about my LSTM and energy monitoring time series adventures.
The last day had this fun little guy controlled via Python and a Jupyter Notebook. On my list of toys to get to play with my son.
I also enjoyed the end of the day talk from Xavier on scientific data cleaning using Pandas was great as well. I quickly put it to use to clean my Tindie buyers list to send out a MailChimp Promo, not very scientific, but useful when you are running a crowd funding campaign. After that it was a couple of days of sprints and getting ATM90E26 to play nice with ESP32 and Micropython, that is another blog post altogether.

Thursday, June 29, 2017

3G Energy Monitor - WattWatchers teardown

Tear-downs are always done in a spirit of learning and admiration. Having built some hobby electronics I really appreciate what goes into laying out a mixed signal PCB as well as one that has high and low-voltages on the same board and is subject to regulatory compliance both for electrical characteristics and RF emissions.

I was handed some detailed WattWatchers images by a client and I did some mark-up of what goes into them based on previous experience of how energy monitors are put together. It is a 2-board design with an SMD PCI connector joining the boards. The PCI connector passes the power and current-voltage signal up to a vertical board.

I shall call the bottom board power and sampling  board and the side-board metering, CPU and network board. The first image below shows one side of both boards. The power supply board features a hefty cap-drop supply with assortment of fuses and TVS, as well as the aforementioned PCI connector. The vertical board features a large 3G module and associated Telstra sim slot, I assume the SIM is linked to a custom M2M plan which costs a few dollars a month.

The other side of the vertical board features the most interesting goodies. On the left half it has a low-noise / high power voltage regulator from ST (presumably needed to feed the hungry 3G modules), as well as a low-power MSP430 MCU with a couple of large old-school tantalum caps. The right side of this board (separated by a row of what is most likely transient suppressors or isolation amplifiers) are a couple of Analog devices 3-phase energy monitor IC's. The isolation section indicates the presence of 9 analog channels which corresponds to 3-phases and 6-CT's. The 2 ADE7880's share a single clock crystal presumably buffered. There are also a bunch of passives to perform 50Hz filtering.

The other side of the bottom board also featured in this image contains the voltage divider to sample the AC-phases and some current-multiplier/burden resistors to convert the current measured by the CT's into a voltage value. There is also another LDO on this board to presumably power one side of the isolation amplifiers, nothing too high power. This LDO must be at the end of the cap-drop system so the neutral or phase on it is at high voltage and generous dob of insulating snot is providing extra protection. The insulating snot can also be seen at the top-left corner of this board where the phase and neutral(?) or 2 phases are too close together for comfort/compliance.

WattWatchers has done a great job packing a lot of features into an M2 DIN rail enclosure without resorting to many off the shelf modules and pre-built components except the 3G module. I am hoping to re-use some of the concepts here in my ATM90E36 based design.

Friday, May 19, 2017

ATM90E36 Dev-kit for 3-phase AC Metering

ATM90E3X Devkit PCB 5x5
After successfully building the single-phase energy monitor with the ATM90E26 there has been lots of interest in the 3-phase version. Being an open-hardware project, many people have created remixed and derived versions as well. After a while I started receiving requests to assist with the code for ATM90E36, the 3-phase version of the Energy Monitor chip. However I did not have the hardware to test the code, so I put together this basic devkit to access the SPI bus and easily inject voltage and CT signals to take the ATM90E36 through its paces. This is the first board I have designed based purely on user demand rather than to scratch my own itch, since I don't have 3-phase supply at home.

Design station for Energy Monitor PCB
I ended up making a 12V AC targeted design like my single-phase version with stereo jacks on board for directly connecting current transformers. The test PCB also has few LED's to show energy pulses and is basically a low voltage version of the 3-phase 4-wire Atmel/Microchip reference design. I restricted the size of the PCB to 5x5 for hackvana's specials category. These can also be obtained from PCBs.io if you want to send some credits my way. The final touches to the design were put in my shed drawing power from my solar panels and marine battery during a now notorious Adelaide blackout.

Logic analyzer SPI protocol analysis

This chip uses the 16-bit SPI mode while most Arduino compatible CPU's only implement an 8-bit SPI mode, so bit of SPI sequencing was necessary to get the results. A cheap Saleae compatible logic analyzer went a long way to pinning down the protocol and getting the right values. You can see the protocol analysis fot the ATM90E36 in the logic analyser screenshot.
Test rig with Teensy and logic analyzer
The ATM90E32 and ATM90E36 share the same footprint you can choose either chip when building the board. The ATM90E36 has slightly more functionality including data dumping over DMA with the chip in SPI-master mode.The unused pins on the ATM90E32 can be grounded when using the board. My library for the ATM90E36 should work for the ATM90E32 as well with meaningless results for the CRC check code. I am re-writing the library specifically for the ATM90E32 while I design some featherwing hardware around it as well.
I took the whole thing for a test to the Hackerspace in Tonsley who graciously provided me a set-up involving a 3-phase variac, an isolation transformer and a 3-phase load bank with wire wound resistors. The test set-up can be seen in the video below. I actually managed to blow up the load bank by pushing 12V AC through a 2ohm load rated for only couple of amps, maths failure there. Just excited to be able to play with the 3-phase at an isolated low voltage. While the load ran it gave nice readings on the monitor which I had previously calibrated using a single phase at a time.
For the next test to have a safer and more controlled conditions I am trying out several DAC's to simulate Voltage and Current waveforms with relevant phase shifts. That is another blog post and project altogether.

Monday, May 8, 2017

Pulsecounting and Deepsleep based IoT water meter

I admit to being a tiny bit obsessed with monitoring utility bills and gathering data on my usage patterns blow-by-blow. The energy monitoring has reduced my electricity bills, so I wanted to have a go at the water usage. Granted a lot of the water bill is fixed supply costs and sewerage charges which I can't do much about.
DS1682 Grove Breakout
A while ago I made some pulse counting breakouts with the DS1682+ RTC. I have finally got a chance to put them to good use interfacing with my mechanical water meter. The water meter has a spinning permanent magnet and in principle this can trigger a reed switch and generate pulses for accumulation by the RTC.
My collection of Sparkfun ESP8266 boards
As a processor board I am using the Sparkfun Blynk development board. It not only has an i2c port, but also sports a well placed pad to solder the deepsleep enabling resistor between GPIO16 and Reset pins. You can see this connection illustrated with a Nodemcu below. The deepsleep is super important in this battery operated set-up to conserve power. The DS1682+ RTC consumes uA's in standby mode and in deepsleep the ESP8266 power consumption comes down to similar levels. The duty cycle is pretty low. The ESP8266 wakes up for around 10s every 5minutes to do a registration onto my WiFi guest network, DHCP itself an IP, perform a DNS look-up of my custom Blynk server and send a custom message with RTC count. More details on the code here.
NodeMCU deepsleep hack
Since the unit will be operating outside without proximity to power for extended periods of time I wanted to make it solar powered. So I scavenged some solar cell + lipo packs I had acquired a while ago at the markets in Salmanca and did not quite live up to the task of powering a phone and had horrible soldering on the switches and USB connectors which had all but broken off. Surprisingly the lipo still had charge and the solar cell did an okay job keeping it topped up. It actually has a nice lipo charger circuit which deals with the variable output from the solar cell without too much fuss, and a boost converter to supply 5V for phone charging. I by-passed the boost for added effciency and soldered directly to the lipo, and the USB connector for the boost port was broken anyway.

El-cheapo solar

Battery charging and 5V boost

Solar panel as substrate

To count pulses I made up a probe with a simple reed switch from Jaycar encapsulated in a bit of heat shrink. Putting some hot-glue on it before heat shrinking makes a nice weather tight sealed probe which slots into the meter. Proper ones pre-sealed in weather proof ABS cost similar amount on eBay and I have ordered a couple on slow-boat from HongKong.
Hacked up magnetic pulse counter with reed-switch

Water meter pulse counter install
The host the data and visualise the water usage I wanted to try something new. So I decided to give setting up a custom Blynk server a go. I have plenty of experience with AWS, so I spun it up on a t2.nano instance for a trial and IP locked it to my home IP. The blynk app on Android can authenticate against this instance of Blynk server and push applications and fetch data. Since I have this tiny server all to myself I can choose very high frequency updates or very low in this case.
Blynk time series of water usage
Data shows up on the Blynk app as a time series without any hitch and I can clearly spot the 3 family showers and a dish washing session, with me being guilty of the longest shower. Oh well, at least we have a baseline to improve on. The only remaining concern is that the meter reader considers that I am tampering with the meter like this guy who hid a magnet in a wheelie bin, better contact SA Water proactively and plead my innocence. This might also have other uses such as leak detection in farms.

Saturday, March 18, 2017

Piezo Activated Drumlights - The PCB

I feel like once you have learnt one software tool in a particular domain to an intermediate level, you can pick up another in the same domain without much fuss. Only if you are too new or too entrenched with a tool do you feel the sunk-cost fallacy and have a higher barrier to switching to something new when circumstances change.

Nightly build I am currently using
I started my adventures in ECAD using Eagle and built up quite a bit of familiarity with it, I would like to say to an intermediate to advanced level. I also built up some assets i.e. libraries and projects. To unlock more features I spent a few hundred dollars on the maker edition. However as with all software, there were niggling bugs and gripes. One of them was lack of proper 3D support, another was lack of proper slots when exporting gerbers, well slots/mills that hackvana would accept. On the hackvana IRC channel KiCAD was mentioned often and I was encouraged to switch to it. The final straw was the acquisition of Eagle by Autodesk and subsequent switch to subscription based pricing.

Eeschema of Arduino Nano drumlights
So finally after much dithering, I decided to switch to KiCAD as my main ECAD tool in the beginning of February 2017. It has been a fun couple of month translating my Eagle knowledge to KiCAD and dealing with the vagaries of a rapidly evolving tool. So far I am loving it. The first PCB I designed using KiCAD was an Arduino Nano Shield using the template provided to work with my Drumlights project. I took the PCB design as an opportunity to add a battery charger and piezo charge amplifier using a TLV2771 opamp.

KiCost in action as a BOM tool
One of the Eagle features I miss is the forward-back annotation between the PCB and the schematic. In KiCAD the association between a schematic symbol and associated footprint and nets is done using a third tool. This way there is no need for duplicate footprints per device for commonly used pad patterns e.g. SOT-23 or TSSOP-16. All devices using this footprint can share a common PCB element and only differ in schematic element. However this also means that changes in the PCB and are not automatically propagated back to the schematic. The backward link will be coming soon according to a recent roadmap. So I am living nightly-to-nightly in anticipation.

PCBNew view of Arduino Nano Drumlights
The other feature I like about KiCAD is the seamless 3D support, especially in the recent builds.There is dual support for usual VRML for pretty rendering and associated STEP files for export to other CAD files particularly FreeCAD. I downloaded step files for parts not already in the library from Molex, JST of GrabCAD and populated them with some scaling and rotation onto the PCB. You can see the resulting internal KiCAD render below. Next came sending the boards to Fab, a lot of hackerfriendly fabs directly support Eagle .brd files, now there is increasing support for KiCAD as well.

KiCAD Ray trace render of Drumlights PCB
Oshpark can directly process KiCAD - kicad_pcb files to associated gerbers and board orders. This reduces the number of clicks to ordering a prototype and eliminates potential errors and filenaming issues when creating Gerbers, since KiCAD does not really have detailed DRC and CAM job settings like Eagle.
.kicad_pcb file directly imported in Oshpark
One of the valuable lessons I learnt which I have had issues with Eagle in the past as well (obviously I trusted community review of KiCAD libraries too much) was to always double check library footprints against the datasheet. The N-channel Mosfet schematic symbol was meant for a through hole part and when paired with a SOT-23 footprint things were not in the right place. So when testing I ended up with turned on mosfets being fed with 3.3V from the microcontroller from drain-to-source essentially shorting the output. Luckily no magic smoke escaped before I spotted it and pulled the power. You can see the picture here of my hack to salvage the erroneous PCB's using the SOT-23 at 45degrees. I have tested this board with LED strips and it works as expected.

Diagonal mosfets to correct for footprint mix-up
PCBs.io is another cheap option for getting good quality prototype PCB's if you are prepared to wait. However they do not support direct KiCAD upload. If you follow the Oshpark's Gerber generation guide to create gerbers and drill files they should work in PCBs.io as well. This is what I did when ordering my test boards, after a couple of revisions via Oshpark. Overall my experience with KiCAD has been very positive. The community is fun and responsive. There are some great ancillary tools like StepUp mentioned above and KiCost which I used to instantly generate BOM for my board and order all parts from Mouser in minutes.
KiCAD Gerbers rendered in PCBs.io

If you are interested in my KiCAD experience and general principle of piezo activated drumlights you can keep tabs of my hardware and software via github.

Saturday, February 25, 2017

Piezo activated Drumlights - The Prototype

One of my colleagues is member of the Adelaide Samba drumming club - SaSamba. I guess he was a bit jealous of the feathered samba dancers getting all the attention during a gig. So he brought up the idea of a sound/drumming activated light system for the band.

We aimed to get the set-up ready for the Adelaide Fringe parade. The parade takes place at night with plenty of opportunity to show off different sorts of lights.
Prototypes in assembly
For the first prototype I used an electret microphone with a pre-amplifier. With the right threshold tap and claps would activate the LED strips I had hooked up to it. It was only 5 RGB Led's on the test strip, but I was pushing my luck driving them directly from an Arduino Nano GPIO. An n-channel Mosfet is needed for safely sinking the current required for meter long strips.
The other trouble with this approach was the cross-talk between drums. Without fancy FIR filters identifying particular drums there was no reliable way of lighting only the drum being hit. In a band surrounded by screaming crowds an omni-directional electret microphone is definitely not the way to go.

After a conversation with Pix at the Adelaide Hackerspace I decided to switch to a contact-mic based approach, using a piezo as a knock sensor. Piezos can produce very large voltages in open circuit conditions, so I loaded this one with a 1MOhm resistor tacked directly onto the disk. Soldering on piezos is tricky, have to use flux, a hot iron and be quick. The disk acts as a heat sink and cools down pretty fast.

The piezo outputs only a few millivolts with this load (16-20 out of the 1024 max on the Arduino ADC range). This could be improved with pre-amp (opamp configured as a charge amplifier), however it is sufficient for thresholding and briefly flashing the LED's on drum hits.
Heatshrink as enclosures
My drummer colleague tested this with the whole band and it shows pretty good isolation as well. We went on to make 10 of these on protoboard and incorporated an overkill DPAK Mosfet (30V, 58A). These were covered in heatshrink and used with a lipo at the fringe parade in front of around 70,000 people. I wonder how many appreciated the fudging that went into making them.