Silicon ChipTouchscreen-Controlled Energy Meter, Pt.1 - August 2016 SILICON CHIP
  1. Outer Front Cover
  2. Contents
  3. Publisher's Letter: Digital technology is blanketing us with RF hash
  4. Feature: Personal Flight Vehicles by Dr David Maddison
  5. Project: Touchscreen-Controlled Energy Meter, Pt.1 by Jim Rowe & Nicholas Vinen
  6. Project: Compact 8-Digit Auto-Ranging Frequency Meter by John Clarke
  7. Serviceman's Log: The ISP help desk from hell by Dave Thompson
  8. Project: Micromite Plus & The Explore 64 Module by Geoff Graham
  9. PartShop
  10. Project: Add A 7-Inch Touchscreen To Your Raspberry Pi by Greg Swain
  11. Review: Tecsun’s S-2000 Multiband Radio by Ross Tester
  12. Product Showcase
  13. Vintage Radio: Astor Aladdin FG Dual-Band Receiver by Ian Batty
  14. Market Centre
  15. Notes & Errata: Wireless Rain Alarm / Combined Timer, Counter & Frequency Meter
  16. Advertising Index

This is only a preview of the August 2016 issue of Silicon Chip.

You can view 42 of the 104 pages in the full issue, including the advertisments.

For full access, purchase the issue for $10.00 or subscribe for access to the latest issues.

Items relevant to "Touchscreen-Controlled Energy Meter, Pt.1":
  • Touchscreen Appliance Energy Meter PCB [04116061 RevI] (AUD $15.00)
  • PIC32MX170F256B-50I/SP programmed for the Micromite-based Touchscreen Energy Meter v1.01 [0411606A.hex] (Programmed Microcontroller, AUD $15.00)
  • CP2102-based USB/TTL serial converter with microUSB socket and 6-pin right-angle header (Component, AUD $5.00)
  • CP2102-based USB/TTL serial converter with microUSB socket and 6-pin right-angle header (clone version) (Component, AUD $3.00)
  • DS3231-based Real Time Clock & Calendar module with mounting hardware (Component, AUD $6.00)
  • ACS718 20A isolated current monitor (Component, AUD $15.00)
  • Firmware (HEX) file and BASIC source code for the Micromite-based Touchscreen Appliance Energy Meter [v1.01] (Software, Free)
  • Touchscreen Appliance Energy Meter PCB pettern (PDF download) [04116061 RevG] (PCB Pattern, Free)
  • Touchscreen Appliance Energy Meter lid panel artwork (PDF download) (Free)
Articles in this series:
  • Touchscreen-Controlled Energy Meter, Pt.1 (August 2016)
  • Touchscreen-Controlled Energy Meter, Pt.1 (August 2016)
  • Touchscreen Appliance Energy Meter, Pt.2 (September 2016)
  • Touchscreen Appliance Energy Meter, Pt.2 (September 2016)
  • Touchscreen Appliance Energy Meter, Pt.3 (October 2016)
  • Touchscreen Appliance Energy Meter, Pt.3 (October 2016)
Items relevant to "Compact 8-Digit Auto-Ranging Frequency Meter":
  • Compact 8-Digit Frequency Meter PCB [04105161] (AUD $10.00)
  • PIC16F88-I/P programmed for the Compact 8-Digit Frequency Meter [0410516B.HEX] (Programmed Microcontroller, AUD $15.00)
  • Matte Black UB3 Lid for Compact 8-digit Frequency Meter (PCB, AUD $5.00)
  • Firmware (ASM and HEX) files for the Compact 8-Digit Frequency Meter [0410516B.HEX] (Software, Free)
  • Compact 8-Digit Frequency Meter PCB pattern (PDF download) [04105161] (Free)
  • Compact 8-Digit Frequency Meter lid panel artwork (PDF download) (Free)
Items relevant to "Micromite Plus & The Explore 64 Module":
  • Micromite Plus Explore 64 PCB [07108161] (AUD $5.00)
  • PIC32MX470F512H-120/PT programmed for the Micromite Plus (Programmed Microcontroller, AUD $20.00)
  • Micromite Plus Explore 64 kit (Component, AUD $37.50)
  • Firmware (HEX) file and documents for the Micromite Mk.2 and Micromite Plus (Software, Free)
  • Micromite Plus Explore 64 PCB pattern (PDF download) [07108161] (Free)
Articles in this series:
  • Micromite Plus & The Explore 64 Module (August 2016)
  • Micromite Plus & The Explore 64 Module (August 2016)

Purchase a printed copy of this issue for $10.00.

TOUCHSCREEN • Full colour touchscreen for easy operation • Measures mains voltage, current, real power, VA, kilowatt-hours & running cost • Allows for time-of-day tariffs: peak/shoulder/off-peak • Displays graphs of power use over time • Logged data can be downloaded to a PC APPLIANCE ENERGY ENER GY METER Part 1 – By JIM ROWE & NICHOLAS VINEN How much do your appliances actually cost to run? Are you getting the most bang for your buck? This new Appliance Energy Meter will tell you exactly how much they’re using, how much they’re costing you and the total energy consumed. It can even log the results to your computer. T his completely new design measures the mains voltage and the appliance's load current, then multiplies the two (taking into account the power factor, including any phase difference) to work out the power being used. Then it integrates this over time to determine the total energy usage in kWh (kilowatt-hours). At the same time, it multiplies the power consumption by the energy tariff that is applicable at the time (ie, peak, shoulder or off-peak) and keeps a running total of the energy cost over time. 28  Silicon Chip It displays all this (and much more information) in an easy-to-understand form via its colour LCD screen. There are no switches or knobs to operate since all control is done via that colour LCD touchscreen, which works like the touchscreen on your smartphone. It is based on the Micromite Backpack module plus a matching 2.8-inch LCD touchscreen module (as described in the February 2016 issue of SILICON CHIP). One obvious use for this unit is to show refrigerator or air siliconchip.com.au conditioner running costs Then there are those devices over a set period of time, so that are powered via a plugpack that you can quickly detersupply: modems, some print, appliance current and time mine the effect of different • Measures mains voltage ers, portable CD players and .........................0.1V lay) disp thermostat settings. battery chargers (eg, for mobile for d nde (rou n lutio • Voltage reso Alternatively, it could be telephones) and so on. Most e) surg A (100 ent....................... 20A used to show the difference • Maximum measured curr continue to draw power even in energy consumption be- • Appliance current resolution ............................................ 0.01A though the device itself might tween the summer months be off. But how much power? 0VA ......................... 510 • Maximum volt-amps reading................ and the winter months. This Appliance Energy Meter If you have a solar power • Maximum wattage (real power) reading.................... 5100W will tell you. installation, the Appliance Many high-power appli................................................. 0.1W Energy Meter will quickly al- • Wattage resolution................ ances also continue to draw low you to determine which • Uncalibrated error.................................................. typically <3% current when they are not appliances are the most being used. <1% y call typi ..... ........ ........................ “power hungry”, so that you • Calibrated error.................. These could include your can adjust your energy us- • Sampling rate.......................................................................... ~5kHz microwave oven, wall oven, age patterns to suit the time dishwasher, washing ma............................................<10ppm of day when solar power is • Timing clock accuracy.......... chine and air-conditioners. nds seco 60 or 10 1, ........ ........ available. Typically, the standby ........ ........ • Logging interval.......... This will maximise the power usage for each of these ) rval tion.................. 7 days (60s inte benefit of your solar panels. • Maximum logging dura appliances is about 2W but For example, by running • Cost resolution............................................................ 0.001c/kWh some are significantly higher. your pool pump, dishwashThen there are those aper, washing machine or air pliances which must always be conditioner during the day from your solar panels, your on, otherwise there’s no point having them; for example, energy cost for running these appliances will essentially cordless telephones, digital alarm clocks, burglar alarms be zero. and garage door openers. That's a much better result than merely accepting the Do a quick audit of your house – you may be quite surnow derisory solar feed-in tariff of typically 6 cents per prised at how many appliances you have that are either kilowatt-hour. permanently powered or operating on standby power. By using the Appliance Energy Meter, you can quickly Standby power monitor these devices and find out which are the energy The cost of standby power is something that most people wasters and decide which can be updated or simply turned never think about. There are lots of appliances in your home off at the wall if they don't need to run continuously. that continuously consume power 24 hours a day, even What about those cheap when they are supposedly “switched off”, especially via power consumption meters? a remote control. These appliances include TV sets, DVD Of course, we are aware that there are plenty of power players, hifi equipment and cable and satellite TV receivers. Specifications +5V A 230VAC INPUT 230VAC TO 5V DC POWER CONVERTER E TO PC N 1 2 3 4 5 USB-TO-UART SERIAL MODULE DATA IN DATA OUT SERIAL INTERFACE LCD DISPLAY MODULE (320 x 240 PIXELS, TOUCH SCREEN) T1 SDA 230V 12V REAL-TIME CLOCK MODULE VOLTS BUFFER I2C INTERFACE IC3a 230VAC OUTLET E A CH1 CURRENT BUFFER IC3b CH4 8-INPUT ANALOG MULTIPLEXER HALL EFFECT ISOLATING CURRENT SENSOR (IC4) SCL SDI 12-BIT ADC (IC2) SD0 SCK CS/CONV SPI INTERFACE MOSI MISO SCK CS/SS MICROMITE MK2 BACKPACK N Fig.1: block diagram of the Energy Meter. T1 provides a voltage proportional to the mains while IC4’s output indicates the load current. The Micromite reads both via analog-to-digital converter IC2 and displays the readings on its LCD. siliconchip.com.au August 2016  29 Fig.2: complete circuit of the Energy Meter. At right is the LCD BackPack with new circuitry at left. The 2.5V output at IC2’s VREF (pin 10) is fed back to COM (pin 8) to allow bipolar (positive/negative) voltage readings at input pins 1 & 5. consumption meters available on-line for around $20 to $30 which can monitor appliances. But they’re not a patch on this one! Our experience is that their LCDs are often hard to read/decipher and they lack colour or any graphics capability. Nor do they have touchscreens. And we’ve seen two side-by-side reading quite differently on the same load! The more expensive “wireless” models (which have a transmitter in the fuse box and a display inside) are actually quite limited in what they can show you – for example, they cannot show individual appliance power, nor can they show true energy costs (they don’t know the difference between time of day tariffs so work on “worst case”). They can read current but assume a certain voltage so they can’t accurately calculate power. By contrast, the readings on our new Appliance Energy 30  Silicon Chip Meter are far more legible, with bright colours. It also offers immediate switching between screens to show energy usage or cost over time with time-of-day tariffs always taken into account. As well, all of this information can be displayed as graphs over time or as histograms (bargraphs) so you can quickly assess how power consumption varies as appliances cycle on and off. Or you can see how power consumption varies over the full cycle of a washing machine or dishwasher. Say you have a washing machine that heats its own water electrically (as many European models do). Do you really need to use that hot/hot setting or will a cooler (or even cold) setting save you money? This will tell you – and you might be in for a real surprise! siliconchip.com.au Using the Appliance Energy Meter As shown in the photos, the new SILICON CHIP Appliance Energy Meter is housed in a compact plastic box with the touchscreen on the top panel. It has two 250VAC 10A mains leads – one with a 3-pin plug, to supply power from the mains and the other with a 3-pin socket, to supply power to the appliance. The unit is easy to use; simply plug it into the mains socket and plug the appliance into the output lead. Turn the power on and it will immediately show the main screen with the following information: • mains voltage (eg, 237VAC) • mains current (eg, 2.25A) • mains frequency (eg, 50Hz) • real power (eg, 475W) siliconchip.com.au • VA (eg, 533VA) • power factor (eg, 0.89) • duration (elapsed time) • running total (in kWh) • current tariff (peak, shoulder or off-peak) • running total cost • current time & date Note that if you don’t have a smart meter in your home, you may only have a single tariff which applies all the time. In this case, you can leave the peak and shoulder periods blank and the unit will compute cost using just one tariff. PCB design Most of the circuitry for the Appliance Energy Meter is accommodated on a single, large double-sided PCB. The August 2016  31 Micromite BackPack and 2.8-inch touchscreen are attached to the lid and wired to the main PCB via a ribbon cable with IDC connectors. Components on the board include an EMI filter, a 230VAC to 6V+6V transformer (T1), a 230VAC to 5V DC switchmode converter, a precision real time clock and a USB-toUART serial converter, for both programming and logging. As well, there are special purpose ICs for an isolating current to voltage converter (IC4) and an analog-to-digital converter (ADC) – IC2. How it works As well as measuring mains voltage and appliance current, the Energy Meter does a lot of calculations and these are detailed in a separate panel. Let's now look at the block diagram of Fig.1 which shows the overall configuration of the new Energy Meter. The heart of the Meter is the already-mentioned Micromite Mk2 BackPack with its 320 x 240 pixel colour LCD touch screen, shown at the right-hand side. At upper left you can see the 230VAC mains input, used to provide power for the meter itself as well as for the appliance connected to the 230VAC outlet at lower left. The two parameters that the meter needs to measure in order to work out the energy consumption of an appliance are the mains voltage and the current being drawn by the appliance. To measure the mains voltage safely, we use a tiny stepdown transformer (T1) to provide isolation. This delivers a secondary AC voltage of 12V RMS (= 33.93V peak-to-peak) when the mains voltage is 230VAC. As this is too high for our measurement circuitry, we use a resistive voltage divider to reduce it further. Then the divided-down mains voltage signal is fed through a unity gain buffer amplifier, IC3a. The relationship between this voltage and the mains voltage is calibrated via the software. To measure the appliance current, we use an Allegro ACS718 isolating linear current sensor, IC4. This provides linear current sensing over a range ±20A, with an input-output isolation of better than 2.1kV RMS or 5.9kV peak-to-peak. The appliance current passes through a very low resistance “loop” on one side of the device, while on the other side, a linear Hall Effect circuit senses the magnetic field around the loop and provides an output voltage proportional to the instantaneous loop current. The output voltage is specified as 100mV/A, linear over a ±20A range. The output voltage from the current sensor passes through another unity gain buffer amplifier, IC3b. The outputs of the two buffer amplifiers are connected to two inputs of the input multiplexer (selector) inside a Linear Technology LTC1863 12-bit analog-to-digital converter, IC2. The ADC then takes samples of the voltage and current signals, under the control of the Micromite processor which communicates with the ADC via an SPI (serial peripheral interface) bus. So that describes the main measurement part of the new energy meter. There is also the real-time clock module (just above the ADC), which connects to the Micromite via an I2C interface and is used to provide the meter's accurate timing (important for time-of-day metering). A USB-to-UART serial module (just above the RTC module), which is connected to the Micromite via a serial interface, is used for down- Here’s the completed Energy Meter prototype (without BackPack) – it connects to the long IDC socket (CON9) at the bottom of the picture. 32  Silicon Chip siliconchip.com.au Parts List – Appliance Energy Meter The energy meter uses the Micromite BackPack with a 2.8-inch LCD touchscreen (you can read all about it in the February 2016 issue of SILICON CHIP). loading the meter's firmware program from your PC and off-loading logged data for analysis. The 230VAC to 5V DC Power Converter at the upper left corner of Fig.1 provides +5V DC power for all of the meter's circuitry, including the Micromite and its touchscreen display. Note that we did not want to use a conventional transformer, bridge rectifier and regulator circuitry to provide the 5V rail as it would have been more expensive and would have needed more space on the PCB. Circuit description Now have a look at the full circuit diagram of Fig.2. Although it is two pages wide, it is laid out in a very similar way to the block diagram of Fig.1. The internals of the Micromite and its LCD touchscreen are shown on the righthand page, while the rest of the Meter's circuitry is shown on the left-hand page. There are a few items in the pink shaded “live” area of the circuit at far left which were not shown in Fig.1 namely fuse F1, a MOV (metal oxide varistor) and the EMI filter module connected ahead of the 230VAC input to the VTX-214-002-105 power converter. There's also a four-way screw terminal strip (CON8) used to make the mains input and output connections, at left centre. Fuse F1 is there to prevent damage to the Meter circuitry (and components, especially current sensor IC4) in the event of a serious overload. The MOV prevents damage to the Meter circuitry in the event of a damaging over-voltage spike on the incoming mains lines. The EMI filter is included mainly to suppress any switching noise from the Vigortronix 230VAC/5V DC converter which would potentially create problems for the voltage and current measurement circuitry (and possibly affect 1 double-sided PCB, code 04116061#, 132 x 85mm 1 UB1 Jiffy box, 158 x 95 x 53mm 1 Micromite LCD BackPack kit with 2.8-inch TFT touchscreen* 1 real-time clock module, DS3231 based* 1 CR2016, CR2025, CR2032 or LIR2032 button cell 1 USB to UART serial converter module* 1 Block AVB 1.5/2/6 2 x 115V to 2 x 6V 1.5VA transformer (element14 1131474) 1 Vigortronix VTX-214-002-105 AC-DC switchmode power supply, 5V output at 400mA (element14 2517750) 1 Yunpen YF10T6 EMI filter, 250VAC/10A (Jaycar MS4000) 1 metal oxide varistor (MOV), 275VAC working/115J (Jaycar RN3400) 1 PCB-mounting 4-way terminal barrier, 300V/15A rating with 8.25mm spacing (CON8) (eg, Altronics P2103) 2 SIL pin headers, 6-pin vertical (CON10, CON11) 1 50-way DIL box header, PCB mounting (CON9) (Jaycar PP1116) 2 50-way IDC ribbon cable sockets (Jaycar PS0990) 1 100mm length of 50-way ribbon cable (Jaycar WM4508) 8 6mm-long M3 Nylon or polycarbonate screws 4 M3 tapped 6.3mm Nylon spacers 4 10mm-long M3 screws 4 12mm-long M3 tapped spacers 4 6mm-long M3 screws 12 M3 flat washers 1 panel-mounting 3AG fuseholder, “very safe” type (Jaycar SZ2025 or similar) 1 15A slow-blow 3AG fuse cartridge (element14 1171841) 1 230V/10A extension cord, 3m long 2 cable glands to suit 4-8mm diameter cable (Jaycar HP0724 or similar) Semiconductors 1 LTC1863CGN#PBF 8-channel 12-bit ADC (IC2; 16-pin SSOP SMD; element14 2294556) or 1 LTC1867CGN#PBF 8-channel 16-bit ADC (IC2; 16-pin SSOP SMD; element14 2115787; see text) 1 LMC6482AIM dual op amp (IC3; 8-pin SOIC; element14 1468888) 1 ACS718KMATR-20B-T Hall effect isolating current sensor (IC4: 16-pin SOIC; Digi-Key 620-1714-1-ND, SC4022)* 1 1N5819 40V 1A Schottky diode (D1) Capacitors 1 1000µF 10V low-ESR electrolytic 2 10µF 16V X5R SMD 3226/3216 (1210/1206 imperial) 1 2.2µF 16V X7R SMD 3216/2012 (1206/0805 imperial) 2 1µF 16V X7R SMD 3216/2012 (1206/0805 imperial) 8 100nF 16V X7R SMD 3216/2012 (1206/0805 imperial) 2 1nF 50V COG SMD 3216/2012 (1206/0805 imperial) Resistors (All 3216/2012 [imperial 1206/0805] SMD 1%) 2 56kΩ 1 22kΩ 1 2.2kΩ 2 47Ω The BackPack mounts flush on the Jiffy Box lid/panel, with a suitable cutout so you can read/touch it. Accurately machined acrylic panels are available from the SILICON CHIP Online Shop to save you the trouble of cutting the hole. siliconchip.com.au * available from SILICON CHIP Online Shop – www.siliconchip.com.au/shop # RevI (or RevG PCB with adaptor board, code 04116061, 71 x 16mm (supplied) plus 2 x 25 pin headers) August 2016  33 400 4 300 3 200 2 V 30 5 400 4 I 30 300 3 200 2 100 0 0 –100 –10 I –40 500 5 400 4 INSTANTANEOUS POWER V CURRENT (AMPS) AVERAGE POWER 20 I 100 0 0 50 –10 500 5 40 INSTANTANEOUS POWER –20 400 4 30 –30 300 3 20 –40 200 2 –100 POWER (kW) 180 10 100 0 0 –100 –10 I 50 VOLTAGE (VOLTS) 1 0 500 5 400 4 300 3 200 2 –300 V 30 –400 360 INSTANTANEOUS POWER –40 50 40 180 20 270 I 10 100 500 5 AVERAGE 400 4 –100 30 300 3 200 2 AVERAGE POWER 20 –30 10 100 –40 0 90 180 0 0 –100 –10 VOLTAGE (VOLTS) –20 I –400 34  Silicon Chip 50 40 270 360 500 5 400 4 300 3 V 360 1 0 0 –100 POWER (kW) 1 0 –200 –300 V –400 –40 0 90 180 360 270 50 500 5 40 400 4 300 3 200 2 INSTANTANEOUS POWER 20 I 10 100 AVERAGE POWER 0 0 –100 1 0 –200 –20 –30 –300 V –40 –400 90 180 270 360 siliconchip.com.au R (kW) 180 –300 –400 270 0 –300 V –40 –200 V –200 –30 I 1 I –20 90 0 0 INSTANTANEOUS –10POWER V POWER POWER (kW) CURRENT (AMPS) 90 0 POWER (kW) V –30 CURRENT (AMPS) 0 –400 40 0 0 1 –200 –20 100 I 360 270 VOLTAGE (VOLTS) CURRENT (AMPS) 90 2 I –10 –300 V 200 AVERAGE POWER 20 10 V –200 AVERAGE POWER 3 30 I V 0 2 200 10 I 3 300 30 30 1 40 300 INSTANTANEOUS POWER –30 0 50 4 I 360 270 180 5 400 –20 POWER (kW) 90 500 40 –10 –400 0 360 270 50 V –300 V 180 30 CURRENT (AMPS) –30 –400 90 0 –200 –20 0 VOLTAGE (VOLTS) I 10 VOLTAGE (VOLTS) CURRENT (AMPS) AVERAGE POWER 20 –300 V –40 POWER (kW) V 0 –200 –20 –30 INSTANTANEOUS POWER 40 1 POWER (kW) 500 –100 –10 VOLTAGE (VOLTS) 50 0 0 Fig. B shows what happens when a partially inductive load causes the current to lag behind the voltage by 45°. This results in the instantaneous power curve (solid green) passing through zero and reversing in direction for part of each cycle (shaded areas). Can you guess what this means? It shows that power is actually PHASE ANGLE IN DEGREES being returned to the power company during these brief pulses. A CURRENT IN PHASE WITH VOLTAGE As a result, the real power being consumed by the load falls, as shown again by the dashed green line. To work out the real power being dissipated by this kind of load, we need to multiply the RMS values of V and I together as before but then multiply this result with a variable known as the “power factor”. This takes into account the phase difference between V and I, ie, the degree to which the current lags or leads the voltage. In fact it turns out that the power factor corresponds to the cosine of the phase angle . In other words, real power = V x I x cos . Note that with a resistive load and no phase difference between V and I, the phase angle will be zero and the power factor equal to cos(0) = 1. That’s why the real power is equal to V x I. PHASE ANGLE IN DEGREES In closing, consider BtheCURRENT situation shown(LAGGING) in Fig. VOLTAGE C , where the 45° BEHIND current is lagging behind the voltage by 90° – a full quarter cycle. As you can see the instantaneous power curve swings above the zero axis for exactly half the time, and below the zero axis for the same amount of time (shaded areas). So the PHASE ANGLE IN DEGREES “forward” and C CURRENT 90° BEHIND VOLTAGE “reverse” power flows effectively cancel out, and the average power drawn by the load is zero. Needless to say the power companies are not happy with this type of load, because there is no billable power being consumed (cos(90°) = 0) – yet there is plenty of current flowing in their distribution system, so there will be energy lost in it. Is that it? Well, except for simple heating appliances like incandescent lamps, radiators and ovens, real-life loads are not purely resistive, or inductive or capacitive and they do not draw sinusoidal currents. So we need to take into account the widely varying current waveform shapes from all power supplies whether linear or switchmode, all lighting such as LEDs, fluorescent, CFLs and so on. And nor is the mains voltage waveform purely sinusoidal – it usually has the peaks clipped off due to the heavy peak currents drawn by capacitive-input power supplies and fluorescent lights. To get over that problem and to accurately measure the RMS values of the voltage and current, the ADC needs to make samples of these parameters at a minimum of 2kHz and integrate the results. This means that the accuracy of the Appliance Energy Meter will not be affected by the shape of the voltage and current waveforms, provided that the harmonics do not exceed about 1kHz. Mind you, the fact that voltage and current sampling needs to be made virtually continuously for reasonable reading accuracy greatly increases the workload of the Micromite because while it is sampling it still needs to update the displayed readings, respond to the touchscreen commands and so on. CURRENT (AMPS) In a DC (direct current) system, the power being used by a load can be worked out quite easily by measuring the voltage (V) across the load and the current (I) passing through it, and then multiplying the two figures together to get the power P in watts (W) or kilowatts (1kW = 1000W), ie, P = V x I. Then if the load uses power of say 2kW for one hour of time, we say it has used 2kWh (kilowatt-hours) of energy, which is equivalent to 7.2MJ. In other words, the energy used is found by simply multiplying the power in Watts by the time in hours. But in an AC (alternating current) system, things are more complicated. In an AC system both the voltage and the current are reversing in direction 50 (or 60) times per second. The graphs shown here are for a resistive load where the voltage and current are both sinusoidal but this is not necessarily the case in reality. Now, when the load connected to the AC power is purely resistive (such as a heating element), the current that flows through it will reverse in direction at exactly the same PHASE ANGLE IN DEGREES instants as A CURRENT IN PHASE WITH VOLTAGE does the voltage. This is usually described as the current being “in phase” with the voltage, and you can see it in Fig. A . Since the power being consumed is again found by multiplying the voltage V and the current I together, this means that the power varies instantaneously with V and I. In fact, it varies in “sine-squared” fashion, at a frequency of twice that of V and I, as shown by the solid green curve in Fig. A . Note that this varying power is always positive. The average heating effect of this rapidly pulsing power corresponds to a steady power level very close to the midway level of the power curve, as shown by thePHASE dashed horizontal line in Fig. A . ANGLE IN DEGREES The usual way of working out this “real (LAGGING) power” level when V B CURRENT 45° BEHIND VOLTAGE and I are in phase is by measuring the RMS (root mean square) voltage and current, and then multiplying them together. So a heater element that draws 10A RMS from a 230V RMS mains supply would be consuming 10A x 230V = 2300W or 2.3kW. It gets even more complicated in an AC system if the load is not purely resistive but has a significant amount of inductance or PHASE ANGLE IN DEGREES capacitance. Examples of inductive loads include motors and fluoA CURRENT IN PHASE WITH VOLTAGE rescent lamps. The effect of load inductance is to make the current “lag” bePHASE ANGLE IN DEGREES hind the voltC CURRENT 90° BEHIND VOLTAGE age, while the effect of load capacitance is to make the current “lead” PHASE ANGLE IN DEGREES B CURRENT 45° BEHIND (LAGGING) VOLTAGE the voltage. 100 VOLTAGE (VOLTS) Volts, Amps, Kilowatts & Energy I 10 VOLTAGE (VOLTS) CURRENT (AMPS) AVERAGE POWER 20 POWER (kW) INSTANTANEOUS POWER 40 radio or TV reception). Transformer T1 (at left centre) has its secondary voltage (nominally 12V) divided down to a measurable level by the voltage divider formed by the 22kΩ and 2.2kΩ resistors. Then the divider's AC output voltage (around 3.25V peak-to-peak) is coupled to the input of buffer IC3a via a 1µF capacitor, while pin 3 of IC3a is DC biased at +2.5V so the signal fed to the ADC (IC2) swings around this voltage level (which suits the ADC). The 1nF capacitor from pin 3 of IC3a to ground and the 100nF capacitor from pin 1 of IC2 to ground provide filtering of any HF noise which may be present on the signal from T1, so that it does not affect the voltage reading accuracy. Hall Effect current sensor IC4 has an output signal centred at +2.5V (half its supply voltage) which varies either above or below this level, by 100mV/A, depending on the direction of current flow through the sensor. The circuitry around the LTC1863 ADC (IC2) is also quite straightforward. It contains its own high-precision voltage reference, with its output available at pin 10. We take this reference around to pin 8 of the device, which is being used as the common input for the other inputs to the device, so that the conversion result is close to zero for voltages around 2.5V. The 2.2µF and 100nF capacitors from pin 8 to ground ensure that this reference voltage is noise free. The signal from the current sensor is buffered by rail-torail CMOS op amp IC3b and passes through a 47Ω/100nF low-pass filter to remove any RF signals which may have been picked up. IC4 also has a 100nF capacitor from its FILTER pin (pin 6) to ground which works with an internal 1.7kΩ resistance to reduce the output noise from the Hall effect sensor and also reduce its bandwidth to around 3kHz, to suit the sampling rate (about 5kHz) that we are using to measure the mains current. Note that a 16-bit version of the ADC, part code LTC1867, is also available. In theory, this might provide slightly improved current resolution if substituted for the LTC1863. The software is designed to work with either part although we haven’t tested the LTC1867. We expect the difference in performance to be small in this application. As noted above, ADC IC2 is controlled by the Micromite via its SPI interface, with the lines connected to pin 14 (SDI), pin 13 (SDO), pin 12 (SCK) and pin 11 (CONV/CS-bar). Basically, the Micromite sends sampling command words The real-time-clock module is soldered onto the PCB once the pins are bent down 90°. It is fitted with a button cell to maintain power and time in the event of disconnection. siliconchip.com.au to IC2 via the SDI line, and receives the sampled data back via the SDO line. The SCK line provides the serial clock pulses for all transactions, while the CONV/CS-bar line is used to select the ADC and direct it to take each sample. Note that we haven’t used the Micromite’s hardware SPI pins for communications (pins 3, 14 & 25) but rather general purpose I/O pins 9, 10 & 24. The reason for this is that the hardware SPI pins are used to drive the TFT display and touch sensor and we need to have a dedicated SPI bus to allow continuous sampling, even while the display is in use. The two remaining circuit sections to discuss are the RTC (real-time clock) module and the USB-serial converter module (both on the left-hand page). The RTC module is based on a Maxim DS3231 “extremely accurate” RTC chip, which includes its own 32kHz crystal and a built-in I2C interface. The module we’ve used (shown in the photos) has provision for a 3V button cell to keep time when power is removed from the meter. It also includes pull-up resistors on the I2C SDA and SCL lines, so these are not needed on our main PCB. The RTC module also hosts an AT24C32 4KB EEPROM (the smaller IC next to the DS3231 chip, visible in the photo at lower-left). This shares the same I2C bus as the real-time clock. We use this chip to store logging duration, accumulated power usage and cost information, so that if there’s a blackout or brownout and the unit resets, you don’t lose all the data. However, note that logged data is stored in RAM as the EEPROM is too small. The USB-serial converter module is based on a Silicon Labs CP2102 which is a complete USB-to-serial interface. The module is about the size of a postage stamp and has a micro-USB socket on one end and a set of connections for its TTL serial port on the other. In our Meter, the module connects to the Micromite serial port via the RXI and TXO lines, to allow the Micromite to communicate with your PC to download logged data. The same interface is used initially to program the Meter's firmware, via your PC. Measuring power Since the Micromite used here only has support for one hardware SPI bus, we’ve had to implement the second SPI bus in software, ie, by “bit banging”. As there are several thousand ADC measurements per second, this is written in “C” and embedded in the Micromite BASIC code using the “CFUNCTION” statement. This is also necessary to allow the sampling to occur even while the BASIC interpreter is busy updating the display or performing other tasks. We’ll have more details on how the software works in part 2, next month. But let’s now go over how the unit measures RMS voltage, current and power. First, the CFUNCTION sets up the PIC32’s internal TIMER1 at boot to call an interrupt routine (also written in C) at approximately 10kHz. This alternately samples inputs 1 & 5 of IC2, resulting in a pair of instantaneous (and more-or-less simultaneous) voltage/ current readings at 5kHz. Each time a pair of readings is completed, they are squared and accumulated into two separate 64-bit memory locations. They are also multiplied together and accumulated into a third location (for VA) and finally, if they are of the same polarity, also accumulated into a fourth locaAugust 2016  35 The User Interface Because the Energy Meter has a colour LCD touchscreen, we have put significant effort into the user interface, to maximise the unit’s utility. Samples of most (but not all) available screens are shown at right. Note that these are from the prototype and some improvements and additions have been made since they were taken. On the main screen, shown at upper-left, pressing on any element in the display takes you to a screen with more information relevant to that particular area. So for example, if you touch on the power figure, you will see a graph of power vs time and pressing on this again takes you to a power histogram. Similarly, if you touch the time or date, you are taken to a screen where you can set the current time or date and if you touch the logging duration, you can access the logging screen which provides more information and allows you to start, stop or pause logging (and other functions, too). In fact, the Appliance Energy Meter is so feature-packed that we have exhausted both the RAM and flash memory available in the Micromite Mk2! We had to spend significant amounts of time optimising both types of memory usage before we could fit in all the features that we felt were necessary to make the Appliance Energy Meter as useful as possible. You may notice a trimpot in one of the photos of the assembled prototype PCB. This has been removed from the final design in favour of software calibration, which can be done via the touchscreen, with the unit completely sealed. This is much safer as it doesn’t require you to insert a screwdriver into the case while mains power is applied. In fact, part of the calibration (to account for DC offset in both voltage and current, and noise from the current sensor) is totally automatic. The only manual calibration required is to set the voltage reading so that it matches the actual mains voltage, as determined using a multimeter (more on that next month). You can also calibrate the current readings however this is optional and can be done using a DC supply and a DMM. 36  Silicon Chip The main screen, displayed at powerup, shows all the most important information at a glance: mains voltage current, real power, VA, frequency, power factor, tariff, accumulated energy and cost, current time and date and logging duration. Touch the logging duration to access this screen with more information including the logging interval, current and maximum duration and memory usage. It also has buttons to start, stop or pause logging, export the data via USB or access calibration/diagnostics. Touch the accumulated energy figure (in kWh) to view estimates of how much energy the load will use in one hour, one day, one week and one year. The longer you leave the unit running, the more accurate these become. Touch the accumulated cost figure to view estimates of how much the load will cost to run for one hour, one day, one week and one year. The longer you leave the unit running, the more accurate these become. This screen allows you to view and set the three different tariffs and when they apply. Each tariff can have two different start/end times for weekdays or weekends and public holidays can be programmed in, so that the weekend rate is used on those dates. Touch the public holidays on the screen to the left and you can enter in up to 22 different dates to indicate weekdays that should be treated as weekends for calculating the current tariff. Most Australian energy suppliers use this billing scheme. While logging is active, data is stored in memory at one, 10 or 60 second intervals and can be plotted by touching on the parameter. Here’s a sample graph of mains voltage over time. Touching the voltage/time graph takes you to histogram mode. The selectable durations are the same as before but now you can see what proportion of the time the mains voltage spends at various different voltage levels. siliconchip.com.au The power vs time graph is accessed by touching the power figure. All time-based graphs can be changed between one hour, one day and one week periods. If insufficient data is available, it shows that which it has accumulated so far. All values that are logged can be displayed as either graphs or histograms. Minimum, maximum and average readings are shown at the top of each graph or histogram and indicate the range of values measured during the displayed period. tion (for true power). The software detects voltage zerocrossing events and when this occurs, the accumulated registers are divided by the number of readings made since the last zero crossing and the square root taken. This yields RMS voltage, current, VA and power for the half-cycle. Multiple half-cycle readings are averaged for display and the power factor computed by dividing the real power by the apparent power. The average power reading is multiplied by the number of mains cycles it occurs over and then divided by the detected mains frequency to compute an energy figure, which is accumulated to give total energy consumption. Cost is computed similarly, after applying the current tariff, with the real-time clock used to determine the one to use. The hardware: a quick preview Similarly, VA (apparent power) can be graphed. While the duration can be changed, the right-most point is always the current reading. If you leave a graph on screen, once sufficient data is available, it “scrolls” right-to-left. Histograms (such as this one for apparent power) also update automatically when they are left on the display and like the graphs, represent data for the selected duration to the present. While minimum and maximum values are shown, note that data is averaged over the logging interval (between one second and one minute) so brief excursions to one extreme or the other may not always be reflected in these readings. In histogram mode, 10-12 bars are normally shown and the horizontal scale is automatically determined by the lowest and highest readings over the logging period. In this case, the power factor is always low (with the load off) or high, never in between. The vertical axis for graphs is also chosen automatically to show the whole range of values logged, hence for loads which draw more current than this, the Amps scale will be more compressed. Finally, a histogram of load current for the last hour, which shows how the current is spread over a range from 250-400mA when the load is on and is close to zero for those times it switches off. siliconchip.com.au The Touchscreen Appliance Energy Meter is built into a UB1 jiffy box measuring 158 x 95 x 53mm. Apart from the mains fuseholder and the two cable glands used for entry of the mains input and output cables, everything else is mounted on three small PCBs – the two used by the Micromite Backpack and its LCD touchscreen, and the main PCB we have designed for the rest of the Meter’s circuitry. (The real-time clock and USB/serial converter modules are pre-assembled). The main board is coded 04116061, and measures 132 x 85mm. All components except for those used in the Micromite LCD BackPack are mounted on its top-side. The sole fine-pitch SMD IC is the analog-to-digital converter, IC2, as this is not available in any other package. Most of the other individual components are relatively large and easy to solder. That’s all we have space for this month. In the second article we’ll tell you how to build it, give more details on the Micromite software, explain how to calibrate it and also describe SC how it’s used. Thanks to Geoff Graham Our thanks to Geoff Graham, the designer of the Micromite BackPack for his assistance during the development of this project. August 2016  37