Silicon ChipUSB Power Monitor - December 2012 SILICON CHIP
  1. Outer Front Cover
  2. Contents
  3. Publisher's Letter: Smart power meters ain't smart
  4. Feature: RapMan: A 3D Printer That You Build From A Kit by Ross Tester and Jashank Jeremy
  5. Feature: Soldering: The Game is Changing
  6. Project: A 2.5GHz 12-digit Frequency Counter, Pt.1 by Jim Rowe
  7. Project: USB Power Monitor by Nicholas Vinen
  8. Project: High-Energy Ignition System For Cars, Pt.2 by John Clarke
  9. Project: High-Power Class-D Audio Amplifier, Pt.2 by John Clarke
  10. Project: Modifications For The Induction Motor Speed Controller by Leo Simpson
  11. Project: Hacking A Mini Wireless Web Server, Pt.2 by Andrew Snow and Nicholas Vinen
  12. Vintage Radio: The Philips Twins – the Australian model 138 & the Dutch BX221-U by Rodney Champness
  13. PartShop
  14. Order Form
  15. Book Store
  16. Market Centre
  17. Advertising Index
  18. Outer Back Cover

This is only a preview of the December 2012 issue of Silicon Chip.

You can view 24 of the 112 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 "A 2.5GHz 12-digit Frequency Counter, Pt.1":
  • 2.5GHz 12-Digit Frequency Counter Main PCB [04111121] (AUD $20.00)
  • 2.5GHz 12-Digit Frequency Counter Display PCB [04111122] (AUD $12.50)
  • 2.5GHz 12-Digit Frequency Counter Add-on PCB [04106141a/b] (AUD $12.50)
  • PIC16F877A-I/P programmed for the 2.5GHz 12-Digit Frequency Counter [0411112C.HEX] (Programmed Microcontroller, AUD $20.00)
  • VK2828U7G5LF TTL GPS/GLONASS/GALILEO module with antenna and cable (Component, AUD $25.00)
  • 2.5GHz 12-Digit Frequency Counter front panel [04111123] (PCB, AUD $25.00)
  • Firmware for the 2.5GHz 12-Digit Frequency Counter project [0411112C.HEX] (Software, Free)
  • 2.5GHz 12-Digit Frequency Counter Main PCB pattern (PDF download) [04111121] (Free)
  • 2.5GHz 12-Digit Frequency Counter Display PCB pattern (PDF download) [04111122] (Free)
  • Long Gating Time Add-on Module for the 2.5GHz 12-Digit Frequency Counter PCB pattern (PDF download) [04106141a/b] (Free)
  • 2.5GHz 12-Digit Frequency Counter front and rear panel artwork (PDF download) [04111123] (Free)
Articles in this series:
  • A 2.5GHz 12-digit Frequency Counter, Pt.1 (December 2012)
  • A 2.5GHz 12-digit Frequency Counter, Pt.1 (December 2012)
  • A 2.5GHz 12-Digit Frequency Counter, Pt.2 (January 2013)
  • A 2.5GHz 12-Digit Frequency Counter, Pt.2 (January 2013)
  • L-o-o-o-n-g Gating Times For The 12-Digit Counter (July 2014)
  • L-o-o-o-n-g Gating Times For The 12-Digit Counter (July 2014)
Items relevant to "USB Power Monitor":
  • USB Power Monitor PCB [04109121] (AUD $10.00)
  • PIC18F45K80-I/PT programmed for USB Power Monitor [0410912A.HEX] (Programmed Microcontroller, AUD $15.00)
  • USB Power Monitor Updated Firmware [0410912B.HEX] (Software, Free)
  • USB Power Monitor Firmware [0410912A.HEX] (Software, Free)
  • USB Power Monitor PCB pattern (PDF download) [04109121] (Free)
Items relevant to "High-Energy Ignition System For Cars, Pt.2":
  • High Energy Electronic Ignition PCB [05110121] (AUD $10.00)
  • PIC16F88-E/P programmed for the High Energy Electronic Ignition System / Jacob's Ladder [0511012A.HEX] (Programmed Microcontroller, AUD $15.00)
  • ISL9V5036P3-F085 360V, 46A IGBT for the High-Energy Electronic Ignition System (Component, AUD $10.00)
  • High Energy Electronic Ignition System Firmware (HEX/ASM - zipped) [0511012A.HEX] (Software, Free)
  • High Energy Electronic Ignition PCB pattern (PDF download) [05110121] (Free)
  • High-Energy Electronic Ignition System front panel label artwork (PDF download) (Panel Artwork, Free)
Articles in this series:
  • High-Energy Ignition System for Cars, Pt.1 (November 2012)
  • High-Energy Ignition System for Cars, Pt.1 (November 2012)
  • High-Energy Ignition System For Cars, Pt.2 (December 2012)
  • High-Energy Ignition System For Cars, Pt.2 (December 2012)
Items relevant to "High-Power Class-D Audio Amplifier, Pt.2":
  • CLASSiC-D PCB [01108121] (AUD $20.00)
  • CLASSiC-D Speaker Protector PCB [01108122] (AUD $5.00)
  • CLASSiC-D PCB pattern (PDF download) [01108121] (Free)
  • CLASSiC-D Speaker Protector PCB pattern (PDF download) [01108122] (Free)
Articles in this series:
  • High-Power Class-D Audio Amplifier, Pt.1 (November 2012)
  • CLASSIC-D Speaker Protector (November 2012)
  • High-Power Class-D Audio Amplifier, Pt.1 (November 2012)
  • CLASSIC-D Speaker Protector (November 2012)
  • CLASSIC-D Amplifier Power Supply (December 2012)
  • High-Power Class-D Audio Amplifier, Pt.2 (December 2012)
  • CLASSIC-D Amplifier Power Supply (December 2012)
  • High-Power Class-D Audio Amplifier, Pt.2 (December 2012)
Items relevant to "Modifications For The Induction Motor Speed Controller":
  • 1.5kW Induction Motor Speed Controller PCB [10105122] (AUD $35.00)
  • dsPIC33FJ64MC802-E/SP programmed for the 1.5kW Induction Motor Speed Controller [1010512B.HEX] (Programmed Microcontroller, AUD $25.00)
  • SL32 10015 NTC thermistor (Component, AUD $7.00)
  • Firmware for 1.5kW Induction Motor Speed Controller [1010512B.HEX] (Software, Free)
  • 1.5kW Induction Motor Speed Controller panel artwork and heatsink drilling template (PDF download) (Free)
Items relevant to "Hacking A Mini Wireless Web Server, Pt.2":
  • Scripts for the Mini Wireless Webserver (WR703N) (Software, Free)
Articles in this series:
  • Hacking A Mini Wireless Webserver, Pt.1 (November 2012)
  • Hacking A Mini Wireless Webserver, Pt.1 (November 2012)
  • Hacking A Mini Wireless Web Server, Pt.2 (December 2012)
  • Hacking A Mini Wireless Web Server, Pt.2 (December 2012)
By NICHOLAS VINEN USB POWER MONITOR Above: the unit operating in Power mode. It shows that the flash drive is drawing 0.343W from the laptop’s USB port. Curious about how much power your USB peripherals use? Perhaps you are building a USB device and want to check its consumption. Or maybe you want to figure out how many devices you can plug into an un-powered hub or what impact a USB device has on your laptop battery life. Build this USB Power Monitor and find out. T HIS SIMPLE, compact device connects in series with one or more USB devices and displays the current they are drawing at any given time. It can also show you the bus voltage and calculate the power consumption in watts. It’s auto-ranging so it will read down to just a few microamps and up to over an amp. Similarly, it will read out in milliwatts or watts. You can cycle the modes simply by pressing a button. It uses a low value (50mΩ) shunt to measure the current so this will have little effect on the voltage received by the peripherals. The readings are displayed on a 4-digit LCD panel, similar to that used by digital multimeters. This is readable from a wide range of angles. Calibration is performed by the microcontroller the first time it is powered up and can be repeated later to keep measurements as accurate as possible. The whole unit measures 90 x 35 x 10mm and is encased in clear heatshrink tubing. When plugged in, it’s like a wide USB flash drive with an LCD on top. It can either go straight into a USB port or be connected via a USB extension cable. It can be used 36  Silicon Chip with ports on either side of a laptop (using the display flip feature), although it’s optimised for use on the righthand side. USB power overview The Universal Serial Bus consists of four lines per port: two for power (0V & 5V) and two differential signals for bidirectional data (D+ & D-). The supply is nominally 5V but due to imperfect regulation at the source and voltage drops across the wiring, a device can expect to receive between 4.4V and 5.25V. A USB device is allowed to initially draw 100mA but can negotiate for more current; up to 500mA. With the nominal 5V supply, that means that no more than 2.5W can be drawn from any given port. Some (but not all) USB ports provide current limiting so that if too many devices are connected or if a device tries to draw too much power, the supply is cut and the port reset. In practice though, certain devices such as portable hard drives will draw more than 500mA when they are first plugged in (eg, as the hard disk motor spins up) so the USB port current limit is not strictly enforced; many ports will allow up to 1A or more to be drawn before shutting down. This is a low enough limit to prevent a short circuit from damaging the port but high enough that most connected devices should get enough power. To complicate matters, multiple devices can be connected to a single USB port using a hub. The power drawn by an unpowered hub is its own operating power (usually ~50mW) plus that of all the devices plugged into it. You can see how you can easily exceed 500mA per port by plugging enough devices into a hub – you can even plug hubs into hubs! Powered hubs are another matter; these have their own power supply (typically a plugpack) and so only a minimal amount of current is drawn from the upstream port. Standby mode When a computer enters standby or sleep (power saving) mode, it sends a signal to the connected USB peripherals to do the same. When in standby, they are expected to draw no more than 0.5mA (2.5mW). When the computer subsequently “wakes up”, it sends another signal to the peripherals which siliconchip.com.au can then resume normal operation. When in standby, devices can wake up the host and this feature is most often used by USB mouses and keyboards. Also, devices may go into standby mode if they are currently inactive, for example, a hub with no connected devices will generally drop into standby mode after a few seconds but will resume normal (higher power) operation if you plug a device into the hub. So you can see how a USB power monitor has a number of useful applications. You can test devices to ensure that they do not draw more than 0.5mA in standby or 100mA before they have been configured. You can check the total power draw of a hub and its attached devices. You can even see how the power consumption changes depending on what the devices are doing, in real time. Also, devices running from a portable computer’s USB ports will cause its battery to discharge faster and you may wish to determine just how much effect this has on battery life. By measuring how many watts each device draws, you can divide this by the battery capacity in watt-hours to determine the proportion of battery charge those devices will deplete per hour of operation. For example, say you have a 3G wireless internet dongle and the USB Power Monitor tells you that it draws 2.5W while active. If your laptop has a 12V, 5Ah (60Wh) battery then this will drain 2.5W ÷ 60Wh = 4.2% of the battery’s capacity, per hour of use. If your laptop normally lasts four hours on battery then it will typically draw 60Wh ÷ 4h = 15W, so we can calculate that it will last 60Wh ÷ (15W + 2.5W) = 3 hours 30 minutes with the 3G dongle connected and operating, ie, using the 3G dongle will reduce the battery life by 30 minutes. Design We have seen other designs for USB power meters and while we liked the concept, we weren’t so impressed with the execution. While you can measure the current drawn by a USB device with just a USB plug, socket, shunt resistor, shunt monitor and panel meter, this approach is quite limited. A typical panel meter has a full scale sensitivity of 200mV which means you can either measure up to 200mA with 0.1mA resolution or up to 2A with 1mA siliconchip.com.au Features & Specifications Measurement modes: current, voltage, power Current resolution: 1μA (0-10mA), 1mA (10mA-1A+) Voltage resolution: 10mV (4.4-5.5V) Power resolution: 10μW (0-10mW), 1mW (10mW-1W), 10mW (1-5W+) Current accuracy: ±2.5% ±0.1mA (mA range), ±5% ±10µA (μA range) Voltage accuracy: ±2.5% ±10mV Power precision: ±5% ±0.1mW Temperature-related error: typically <1μA/°C Load voltage drop: typically less than 50mV Power consumption: 5.3mA/26mW Other features: display flip mode, mode memory, digital calibration resolution. Really, we want to measure to at least 500mA and we want a minimum resolution of 0.1mA; preferably better at lower current readings. Our design, while a little more complex, does even better, with readings beyond 1A and a resolution of 1µA for readings below 10mA. By using a microcontroller we can also add some extra modes such as voltage and power reading which just make it so much more convenient to use. We were also able to keep the unit fairly slim and compact, with large, easy-to-read digits. Circuit description Refer now to Fig.1 for the complete circuit diagram of the USB Power Monitor. All the parts shown mount on a single double-sided PCB. USB plug CON1 goes into the computer or USB charger. Current then flows from its pin 1 (+5V) through the 0.05Ω shunt resistor to pin 1 of CON2, the USB socket. Return current passes directly from pin 4 of CON2 (ground) to CON1. The USB D+ and D- data signals pass straight through from pins 2 & 3 of CON1 to CON2, with the tracks running right across the PCB. They are close together so that any interference couples into both lines by a similar amount, preserving the integrity of the differential signal. The 0.05Ω resistor is a special type with “Kelvin connections”, ie, it has four terminals, each pair of which are internally joined to the resistive element. This prevents resistance in the solder joints from affecting current measurements; otherwise, this resistance would effectively be in series with the resistor itself and thus its USB Power Delivery Enabled Devices Currently, virtually all USB ports supply a nominal 5V and this project relies on that fact. USB 3.0 has introduced ports able to supply up to 900mA (which this device can handle), increasing the power delivery from 2.5W per port to 4.5W. But for a lot of devices, that still isn’t enough. Hence, a new specification has been developed. Called “USB Power Delivery”, it is designed to allow compatible devices to draw much more power from a USB 2.0 or USB 3.0 port – up to 100W. Partly this is achieved by the device negotiating for a higher supply voltage of either 12V or 20V, as well as beefier cables to carry up to 5A. We haven’t seen any devices which comply with this spec yet but when they arrive, you’ll have to be careful not to connect the USB Power Monitor between a port and device which may be operating at 12V or 20V. If you do and the bus voltage is increased, it will almost certainly destroy the USB Power Monitor. Part of the spec involves having the hardware able to check that the attached cable(s) are capable of carrying the higher voltages and currents, so it’s possible that they will refuse to deliver a higher voltage with the USB Power Monitor attached. But we wouldn’t rely on it. December 2012  37 Parts List 1 double-sided PCB, code 04109121, 65 x 36mm 1 4-digit LCD (Jaycar ZD1886) 1 PCB-mount right-angle USB Type A plug (element14 1696544 or 2067044) 1 PCB-mount right-angle USB Type A socket (Jaycar PS0916, Altronics P1300, or equivalent) 1 5-pin header, 2.54mm pitch (CON3) 1 PCB-mount tactile pushbutton 1 80mm length of clear heatshrink tubing, 25-30mm diameter Semiconductors 1 PIC18F45K80-I/PT programmed with 0410912A.hex (IC1) 1 INA282AID shunt monitor (IC2) 1 OPA2376AID dual op amp (IC3) Capacitors (SMD 3216, X5R/X7R) 1 10µF 6.3V 3 220nF 16V Resistors (SMD 3216, 1% 1/8W) 1 120kΩ 3 10kΩ 1 100Ω 1 50mΩ 0.5% 0.5W 4-terminal shunt (element14 1462296) Note: kits for this project will be available from Jaycar Electronics with SMDs presoldered – Cat KC-5516). value would be higher than expected. We measure the current flowing through the shunt by sensing the voltage drop across it. Ohm’s Law tells us that this will be 50mV/A ±0.5% (the resistor tolerance). So we will be measuring very small voltages; the unit will read down to 10 microamps or less, giving a voltage drop of around 0.5µV. The voltage across the shunt is amplified by IC2, an INA282 chopperstabilised “zero-drift” current shunt monitor. This operates in a similar manner to an instrumentation amplifier but is specifically designed for measuring current. It runs directly off the 5V USB supply from CON1, with a 220nF bypass capacitor to ensure low supply impedance. As well as amplifying the voltage drop, it provides an output that is referenced to ground or some other low voltage, regardless of the supply 38  Silicon Chip voltage fed to the shunt which can be in the range of -14V to 80V. It can even measure current flow in either direction but we are not using that feature in this circuit. The INA282 has an internal 1:1 resistive divider between the REF1 and REF2 pins which can be used to generate a half-supply rail, so that the output can swing symmetrically for bidirectional current measurement. As we aren’t using that feature, we simply tie the REF1 and REF2 pins together and drive them with a low-impedance voltage source which is then the reference (signal ground) voltage for IC2’s output. With no voltage across the shunt resistor, the output at pin 5 sits at the same voltage as we are driving the REF1/REF2 pins (3 & 7) with. As the voltage across the shunt rises, the output voltage increases proportionally above this reference level. The INA282 has a fixed internal gain of 50, giving us an output of 2.5V/A. IC2 can have an input offset voltage of up to ±70µV and with a 50mΩ shunt, that gives an equivalent error of ±1.4mA or ±3.5mV at the output. This offset error varies from device to device but remains fairly constant over its life and with variations in supply voltage and temperature. The error is usually well under 3.5mV but can be enough to seriously affect low current readings (eg, in the microamp range) so we need a way to trim it out. If that error was always positive, we could simply connect REF1 and REF2 to ground, have microcontroller IC1 (PIC18F45K80) measure IC2’s output with no current flow, store that value and subtract it from future readings. But the offset voltage can be negative too and this scheme would fail to correct negative output errors. To solve this, we are driving the REF1 and REF2 pins with a nominal 385mV reference level which is derived from the 5V supply using a resistive divider (120kΩ/10kΩ). This voltage is buffered by op amp IC3a, configured as a voltage follower. This ensures that REF1 and REF2 are driven with a low impedance, maintaining the accuracy of IC2’s measurements. The software in the micro measures the output of IC2 with no current flowing, which is the ~385mV reference plus IC2’s output offset error. It can then subtract this from future readings and since the reference voltage is higher than the largest possible negative offset error, this will always be able to correct for the offset. It should not require frequent re-calibration as IC2 has a very low offset drift (hence its “zero-drift” moniker). Microamp measurements Op amp IC3b amplifies the output of IC2 by 100 times, to allow IC1 to accurately read low current values. Unfortunately, this also amplifies IC2’s offset error by a factor of 100. IC3b itself contributes a further offset of up to ±2.5mV but this pales in comparison to the up to ±350mV error (±3.5mV x 100) contributed by IC2. This is why we chose a reference voltage of around 385mV, to allow for the full range of offset variations to be trimmed out. The 220nF capacitor across IC3b’s feedback resistor (10kΩ) greatly reduces the amount of noise from IC3b’s output, as it dramatically reduces the gain stage’s bandwidth to about 72Hz. IC3b’s effective signal “ground” is the same reference voltage that is fed to IC2. Microcontroller IC1 measures the output of shunt monitor IC2 at its AN2 input (pin 21). Similarly, the amplified signal from IC3b goes to the AN3 input at pin 22. The micro can then select which voltage to measure. In practice, it does this by first measuring the voltage at AN3 and if this indicates a reading of 10mA or more, it measures AN2 instead for a greater measurement range. We interpret readings from AN2 as 2.5mV/mA and for AN3, 250mV/mA. IC1 uses an internal 4.096V reference as the full-scale voltage for each conversion, giving a maximum reading of about 1.5A for input AN2 and 15mA for input AN3. With a 5V supply, the output of IC2 can go as high as 4.8V, giving us a maximum possible reading of about 1.75A. As well as a very low offset voltage, op amp IC3 (OPA2376) has a number of other attributes which make it suitable for use in this type of application. It’s designed to run from low supply voltages (2.7-5.5V) and has low noise, high bandwidth (5.5MHz), low quiescent current (~1.5mA) and an output that can swing to both supply rails (down to 0V and up to 5V). Note that the ~385mV reference voltage will vary with the USB supply voltage as it is derived from it. This could introduce an error in the current siliconchip.com.au R1 0.05 Vbus C ON1 1 USB PLUG C ON2 Vbus 2 3 D– 2 D+ 3 GND 4 Vin 1 USB SOC KET 4 Vout 40 39 38 37 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 21 4f 4a 3f 3a 3b 4g 3g C OL 2f 2a 2b 2g 1b 1f 1a 1g NC NC 4b 4d 4c 4e DP3 3d 3c DP2 DP3 3e 2e 2d 2c C OM1 NC DP2 DP1 3 4 3 DP1 1c 2 7 NC GND 120k 5 1e 1d REF1 NC NC INA282 REF2 +IN : 8.8.8.8 C OL 2 1 NC 8 4 V+ LC D1 ZD1886 1 –IN 220nF 6 C OM1 IC 2 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 IC 3: OPA2376 3 10k 2 IC 3a 1 4 220nF 100 8 5 6 IC 3b 7 10k 220nF C ON3 10k 1 2 IC SP C ONN. 3 4 5 S1 7 6 SC 2012 28 Vdd Vdd 8 RC 7 RB0 9 RB1 RC 6 10 RB2 RC 5 11 RC 4 RB3 14 RB4 RC 3 15 RB5 RC 2 16 RB6 RC 1 17 RB7 RC 0 12 IC 1 NC RD7 13 PIC 18F45K80 NC RD6 19 RA0/AN0 RD5 20 RA1/AN1 RD4 27 RD3 RE2/AN7 26 RD2 RE1/AN6 25 RD1 RE0/AN5 18 RD0 RE3/MC LR 24 OSC 1/RA7 RA5/AN4 21 OSC 2/RA6 AN2/RA2 22 VDDCORE/VCAP AN3/RA3 33 NC NC Vss Vss 29 1 44 43 42 37 36 35 32 5 4 3 2 41 40 39 38 30 31 23 34 10 F USB POWER MONITOR Fig.1: the complete circuit of the USB Power Monitor. USB current passes through a 50mΩ shunt resistor and the voltage drop across this is amplified by shunt monitor IC2 and then further amplified by op amp IC3b. Microcontroller IC1 uses its internal ADC to measure the current and display it on LCD1. Op amp IC3a buffers a reference voltage, used to allow IC1 to determine the static (offset) error in the current measurements. siliconchip.com.au December 2012  39 VBUS LCD1 CON1 4 3 2 1 ZD1886 : CON2 4 8.8:.8.8 10F CON2 4 3 2 3 2 1 1 10k 10k 12 220nF 0.05 CON1 IC2 INA282 4 120k IC1 PIC18F45K80 1 S1 220nF 23 34 3 2 IC3 2376 GND 100 ICSP CON3 1 1 220nF 10k (BACK VIEW) (FRONT VIEW) Fig.2: top and bottom views of the USB Power Monitor PCB. The LCD, connectors and pushbutton switch S1 (used to change modes) are the only components on the top. All the active circuitry goes on the underside and this keeps the unit compact. The VBUS & GND pads are provided so you can measure the USB voltage for calibration. The completed PCB assembly can be housed in clear heatshrink tubing for protection. measurements but microcontroller IC1 can compensate for this by measuring the supply voltage and adjusting the value that it subtracts from each reading. This mostly eliminates the effect of supply variation on readings. Note also that part of the reason for selecting a 50mΩ shunt is to keep its dissipation low over the expected current range. At 1A, it will dissipate just 50mW (I2R) and even at 2A, it will be a manageable 200mW – the part is rated for up to 0.5W. Display driving The 4-digit LCD (LCD1) is driven directly by microcontroller IC1. The LCD has a total of 32 segments – four 7-segment digits plus three decimal points (DP1-DP3) and a colon. Each segment is connected at one end to a dedicated pin while at the other end, all segments are joined together and connect to a pair of common pins, COM1 & COM2 at left. To turn a segment on (dark), we drive the segment with a 6-10V peak-to-peak square wave and to turn it off, we maintain 0V across the segment. This is achieved by driving all the LCD pins (including COM1 & COM2) with one of two 5V 50Hz square waves which are 180° out of phase, ie, one is an inverted version of the other. Any segments driven with the same signal as the common pins have no voltage across them and so remain off. Those driven with the inverted square wave, compared to the common pins, receive 10V peak-to-and so turn on. We use an AC drive signal since DC drive slowly damages the LCD by an electrochemical process. In this case, it’s also required to provide a sufficient drive voltage as this method doubles the RMS voltage across the segments, The USB Power Meter is shown here measuring the voltage (in this case, 5.04V) of a laptop’s USB port. The “b” on the LCD indicates that the unit is operating in bus voltage mode. 40  Silicon Chip ie, they receive 10V rather than 5V. The AC signals are generated using one the microcontroller’s internal timers and two of the compare units, combined with an interrupt handler routine that updates the output pins at 100Hz. Like the analog chips, microcontroller IC1 runs directly off the USB bus voltage. Note that we haven’t made any additional connections from the USB supply to allow it to sense that voltage, in order to display it. Rather, this is achieved by configuring its ADC to sample its internal (nominal) 1.024V reference in relation to its supply voltage. It can then calculate the reciprocal of this in order to determine what its supply voltage and thus what the bus voltage actually is. The same 1.024V reference is multiplied by four using an internal op amp, to produce the 4.096V ADC reference voltage which allows current measurements to be made accurately. In addition to a 220nF bypass capacitor across the 5V supply, IC1 has a 10µF filter capacitor connected to its VDDCORE pin, which is required to allow its internal 2.5V core regulator to function properly. A pushbutton is connected between pin 18 of IC1 (RE3/MCLR) and ground, with a 10kΩ pull-up resistor. Normally, this pin is used to reset the micro but we have programmed it to disable that function so that we can use this pin as a digital input, to sense when the button is pressed. The button is used to change modes and also re-calibrate the unit. The micro can still be programmed since the programmer pulls the MCLR pin well above 5V to activate programming. An in-circuit programming header (CON3) is provided although the header does not need to be solsiliconchip.com.au These views show the unit before the clear heatshrink tubing is fitted. Take care when soldering in the SMDs – they must be correctly aligned with their pads. You can easily remove any solder bridges using solder wick. dered to the PCB and can be left out altogether if a pre-programmed chip is used. Software The software for IC1 is fairly simple but performs multiple tasks. It must constantly update all the LCD drive pins, sample the ADC inputs, perform calculations to determine what to display, monitor the pushbutton state and handle calibration tasks. It digitally averages the readings from each analog input pin 2048 times to improve resolution and reduce noise. When reading microamps or microwatts, some additional time averaging is performed on successive readings, if the readings are fairly steady, to prevent the bottom digit from jumping around due to circuit and power supply noise. Input pin RE3 is monitored to check if S1 is pressed and if so, the display mode is changed. The current display mode is stored in EEPROM so that if you unplug and re-plug the unit, it retains its mode. This is convenient but we also found that plugging certain USB devices in can cause the USB Power Meter to reset and since it powers back on in the same mode after a reset, the event is barely noticeable (besides a brief period with a blank or frozen display). The software also contains calibration routines which measure the offset voltage and store it in EEPROM to siliconchip.com.au adjust future measurements. During calibration, you can also correct for errors in the micro’s internal 1.024V reference generator (specified as ±7% over the full temperature range). This offset is also stored in EEPROM and it is recommended that you trim this voltage as it also affects current readings, since the 4.096V ADC reference is derived from it. The software compensates for power lost in the shunt when measuring the power drawn. This is necessary since the USB voltage measured is at the supply side rather than the load. This error is only significant for fairly high readings; eg, readings at 2.5W would be 0.5% high. Construction The components are all fitted on a PCB coded 04109121 (65 x 36mm). The LCD module, USB connectors and pushbutton go on one side and everything else on the other. Start by installing the surface-mount parts. It’s best to begin with the three ICs and then follow with the passive components. These are all fairly large for SMDs so you should not encounter too many difficulties. We’ve covered SMD soldering on a number of occasions in the past so we will just cover the basics here. For more information, refer to pages 80 & 81 in the June 2012 issue of SILICON CHIP. Start by applying some solder to one of the IC pads and then, using tweezers, slide the part into place while heating the solder on that pad. Remove the iron and check that the part is correctly orientated (pin 1 dot/ divot as shown) and that it is properly centred on its pads. If not, re-heat the solder and gently nudge the chip into place. Repeat until it’s right and then solder the rest of the pins. Remember to re-fresh the solder on the first pin you soldered when you’re finished. If you accidentally bridge any of the pins, simply use solder wick to clean it up. A dab of no-clean flux paste applied to the bridge beforehand makes it disappear a lot more quickly and easily. The same basic technique applies for the passive parts although they only have two pads so it’s generally much easier and alignment is less critical. The exception is the 50mΩ shunt resistor which has four (small) pads but as long as you line it up correctly and don’t use an excessive amount of solder, it should all go smoothly. Check the shunt resistor carefully with a magnifying glass after you have soldered it, to ensure that the closelyspaced pairs of pads at each end have not been bridged. If they have, use flux paste and solder wick to remove the excess solder. With all the SMDs in place, flip the PCB over and fit the LCD. First you must bend the pins straight; they are kinked but will not fit through the holes in the PCB until you straighten them. This is easily done with small, straight pliers, one pin at a time. When you’re finished, they should leave the LCD module at right-angles and have no kinks. You can then fit the LCD module into place but be sure to install it the right way around. To do this, first hold the module at an angle to the light so that you can see where the decimal points are – these go towards the bottom of the PCB. The straightened pins can be tricky to line up with the holes in the PCB so you will probably have to feed them through one at a time. Once you have them all in, push the module down so that it sits flat against the PCB and then solder all the pins. You can then finish up by installing the USB plug and socket and the pushbutton switch. In each case, these should be pushed down fully onto the board before being soldered. For the December 2012  41 USB plug and socket, solder the large mounting pins first and then the four signal pins. The plug goes on the left and the socket on the right. There won’t be much of a gap between the LCD and the socket but it should fit. Testing and calibration To test the unit, you simply plug it into a USB port. You should immediately see a display on the screen which will read “C5.00” or similar, with the number indicating the sensed USB supply voltage. The decimal point should also be flashing. This indicates that the unit is in calibration mode. If you don’t get such a display, unplug it and check for faults such as bad solder joints or bridged pads. Assuming it’s OK, set your DMM to DC volts and measure the voltage between the “VBUS” and “GND” points on the PCB (top corners). You should get a reading pretty close to that shown on the unit but it may be slightly off. If it’s off, press pushbutton S1 briefly and release it. Shortly afterwards, you should see the reading on the display change slightly. Continue pressing S1, with a pause after each press to check the new reading, until the unit shows the same voltage as your multimeter, to within 10mV. You may need to re-check the DMM reading in case the USB voltage has changed slightly as you approach the correct reading. Once the display is correct, press and hold pushbutton S1 for several seconds until the display shows “CALI” and then release it. After a couple of seconds, calibration will complete and the unit will display the measured current in milliamps, which should be very close to zero. Now plug in a USB device (eg, a hub) and check that the reading increases. You can then press the switch to cycle through the current, voltage and power modes (see below) and check that each reading is approximately correct. Once you are happy that the unit is working and correctly calibrated, you can then trim the heatshrink tubing so that it is about 10mm longer than the PCB, slip it over the unit and apply some gentle heat (from a heat gun on low or a hairdryer) to shrink it. Trim away any excess tubing that protrudes past the ends of the PCB. 42  Silicon Chip imp_silicon_prototype_2012-10-03.indd 1 siliconchip.com.au 4/10/2012 6:12:20 PM Pressing the pushbutton switch at lower right on the PCB cycles through the various operating modes. Here the unit is shown in Current mode and is displaying the current drawn by the flash drive, ie, 68.9mA. You can still access the VBUS and GND terminals to re-calibrate it later, if that becomes necessary, through the ends of the tubing. It may then be more convenient to use the USB plug shell as your ground reference point. Display During normal operation, there are three modes: current, voltage and power. Pressing S1 briefly cycles through these modes. In current mode, there are three ranges and the unit switches automatically. Typically, it will read either “x.xxx” or “xxx.x” where x is a digit from 0 to 9. These readings are in milliamps and the lower range (with microamp resolution) is automatically selected for readings below 10mA. For 1A and above, the display changes to “x.xxA”. In voltage mode, the read-out is always in the format “bx.xx” where x.xx will be a number usually between 4.40 and 5.50. “b” is short for “bus voltage” (it’s not possible to do a V with a 7-segment display). In power mode, there are three possible ranges and again it is auto-ranging. For readings 10mW and above, you will get a read-out in watts of either “Px.xx” or “P.xxx”, both in watts. Below 10mW, the display will change to “Lx.xx”, with the reading in milliwatts. The “L” stands for “low power”. To re-enter calibration, hold down S1 for several seconds. You can then go through the steps above to recalibrate the unit. Flip mode If you plug the unit into a left-side USB port, the reading will be upside-down. This can be fixed by holding down S1 while plugging it in, which enables flip mode. The decimal points are now at the top of the display but the digits will be shown the right way up and you can read it as normal. To disable flip mode, you again hold down S1 while plugging the unit in. Otherwise, it will stay in flip mode. That’s it. Now you will no longer be in the dark about SC the power your USB devices consume. siliconchip.com.au December 2012  43