Silicon ChipCoin Cell Emulator - December 2023 SILICON CHIP
  1. Outer Front Cover
  2. Contents
  3. Publisher's Letter: How our magazine is distributed
  4. Feature: The History of Electronics, Pt3 by Dr David Maddison
  5. Review: Arduino Uno R4 Minima by Jim Rowe
  6. PartShop
  7. Project: Ideal Diode Bridge Rectifiers by Phil Prosser
  8. Project: Secure Remote Switch, Pt1 by John Clarke
  9. Feature: Electronic Markets in Shenzhen by Edison Zhang
  10. Project: Multi-Channel Volume Control, Pt1 by Tim Blythman
  11. Project: Coin Cell Emulator by Tim Blythman
  12. Serviceman's Log: Mixing it up a bit by Dave Thompson
  13. Vintage Radio: Recreating Sputnik-1, Part 2 by Dr Hugo Holden
  14. Market Centre
  15. Advertising Index
  16. Notes & Errata: Breadboard PSU Display Adaptor, December 2022; 30V 2A Bench Supply Mk2, September-October 2023; 16-bit 4-input ADC, November 2023
  17. Outer Back Cover

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

You can view 37 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.

Articles in this series:
  • The History of Electronics, Pt1 (October 2023)
  • The History of Electronics, Pt1 (October 2023)
  • The History of Electronics, Pt2 (November 2023)
  • The History of Electronics, Pt2 (November 2023)
  • The History of Electronics, Pt3 (December 2023)
  • The History of Electronics, Pt3 (December 2023)
  • The History of Electronics, part one (January 2025)
  • The History of Electronics, part one (January 2025)
  • The History of Electronics, part two (February 2025)
  • The History of Electronics, part two (February 2025)
  • The History of Electronics, part three (March 2025)
  • The History of Electronics, part three (March 2025)
  • The History of Electronics, part four (April 2025)
  • The History of Electronics, part four (April 2025)
  • The History of Electronics, part five (May 2025)
  • The History of Electronics, part five (May 2025)
  • The History of Electronics, part six (June 2025)
  • The History of Electronics, part six (June 2025)
Items relevant to "Arduino Uno R4 Minima":
  • Sample software for the Arduino Uno R4 Minima (Free)
Items relevant to "Ideal Diode Bridge Rectifiers":
  • Ideal Bridge Rectifier PCB, 28mm spade version [18101241] (AUD $2.00)
  • Ideal Bridge Rectifier PCB, 21mm square PCB pin version [18101242] (AUD $2.00)
  • Ideal Bridge Rectifier PCB, 5mm pitch SIL version [18101243] (AUD $2.00)
  • Ideal Bridge Rectifier PCB, mini SOT-23 version [18101244] (AUD $1.00)
  • Ideal Bridge Rectifier PCB, standalone D2PAK SMD version [18101245] (AUD $2.50)
  • Ideal Bridge Rectifier PCB, standalone TO-220 through-hole version [18101246] (AUD $5.00)
  • Ideal Bridge Rectifier PCB, standalone TO-220 through-hole version, light copper (35um) [18101246] (AUD $2.50)
  • Ideal Bridge Rectifier kit, 28mm spade version (Component, AUD $30.00)
  • Ideal Bridge Rectifier kit, 21mm square PCB pin version (Component, AUD $30.00)
  • Ideal Bridge Rectifier kit, 5mm pitch SIL version (Component, AUD $30.00)
  • Ideal Bridge Rectifier kit, mini SOT-23 version (Component, AUD $25.00)
  • Ideal Bridge Rectifier kit, standalone D2PAK SMD version (Component, AUD $35.00)
  • Ideal Bridge Rectifier kit, standalone TO-220 through-hole version (Component, AUD $45.00)
  • Ideal Bridge Rectifier PCBs patterns (PDF download) [18101241-6] (PCB Pattern, Free)
Items relevant to "Secure Remote Switch, Pt1":
  • Secure Remote Switch receiver PCB [10109231] (AUD $5.00)
  • Secure Remote Switch transmitter PCB [10109232] (AUD $2.50)
  • Secure Remote Switch transmitter PCB [10109233] (AUD $2.50)
  • PIC16F1459-I/P programmed for the Secure Remote Switch receiver (1010923R.HEX) (Programmed Microcontroller, AUD $10.00)
  • PIC16LF15323-I/SL programmed for the Secure Remote Switch transmitter (1010923A.HEX) (Programmed Microcontroller, AUD $10.00)
  • Secure Remote Switch receiver short-form kit (Component, AUD $35.00)
  • Secure Remote Switch transmitter short-form kit (module version) (Component, AUD $15.00)
  • Secure Remote Switch transmitter complete kit (discrete version) (Component, AUD $20.00)
  • Firmware (ASM and HEX) files for the Secure Remote Switch (Software, Free)
  • Secure Remote Switch PCB patterns (PDF download) [10109231-3] (Free)
  • Panel labels for the Secure Remote Switch (Panel Artwork, Free)
Articles in this series:
  • Secure Remote Switch, Pt1 (December 2023)
  • Secure Remote Switch, Pt1 (December 2023)
  • Secure Remote Switch, Pt2 (January 2024)
  • Secure Remote Switch, Pt2 (January 2024)
Items relevant to "Multi-Channel Volume Control, Pt1":
  • Multi-channel Volume Control volume PCB [01111221] (AUD $5.00)
  • Multi-channel Volume Control control PCB [01111222] (AUD $5.00)
  • Multi-channel Volume Control OLED PCB [01111223] (AUD $3.00)
  • PIC16F18146-I/SO programmed for the Multi-Channel Volume Control [0111122B.HEX] (Programmed Microcontroller, AUD $10.00)
  • PIC16F15224-I/SL programmed for the Multi-Channel Volume Control [0111122C.HEX] (Programmed Microcontroller, AUD $10.00)
  • Pulse-type rotary encoder with pushbutton and 18t spline shaft (Component, AUD $3.00)
  • 0.96in cyan OLED with SSD1306 controller (Component, AUD $10.00)
  • 2.8-inch TFT Touchscreen LCD module with SD card socket (Component, AUD $25.00)
  • Multi-channel Volume Control control module kit (Component, AUD $50.00)
  • Multi-channel Volume Control volume module kit (Component, AUD $55.00)
  • Multi-channel Volume Control OLED module kit (Component, AUD $25.00)
  • Firmware (C and HEX) files for the Multi-Channel Volume Control (Software, Free)
  • Multi-channel Volume Control PCB patterns (PDF download) [01111221-3] (Free)
Articles in this series:
  • Multi-Channel Volume Control, Pt1 (December 2023)
  • Multi-Channel Volume Control, Pt1 (December 2023)
  • Multi-Channel Volume Control Part 2 (January 2024)
  • Multi-Channel Volume Control Part 2 (January 2024)
  • Multi-Channel Volume Control, part one (November 2024)
  • Multi-Channel Volume Control, part one (November 2024)
  • Multi-Channel Volume Control, Part 2 (December 2024)
  • Multi-Channel Volume Control, Part 2 (December 2024)
Items relevant to "Coin Cell Emulator":
  • Coin Cell Emulator PCB [18101231] (AUD $5.00)
  • PIC16F18146-I/SO‎ programmed for the Coin Cell Emulator [1810123A.HEX] (Programmed Microcontroller, AUD $10.00)
  • 1.3-inch blue OLED with 4-pin I²C interface (Component, AUD $15.00)
  • 1.3-inch white OLED with 4-pin I²C interface (Component, AUD $15.00)
  • Coin Cell Emulator kit (Component, AUD $30.00)
  • Firmware (C and HEX) files for the Coin Cell Emulator [1810123A.HEX] (Software, Free)
  • Coin Cell Emulator PCB pattern (PDF download) [18101231] (Free)
Items relevant to "Recreating Sputnik-1, Part 2":
  • Sputnik design documents and Manipulator sound recording (Software, Free)
Articles in this series:
  • Recreating Sputnik-1, Part 1 (November 2023)
  • Recreating Sputnik-1, Part 1 (November 2023)
  • Recreating Sputnik-1, Part 2 (December 2023)
  • Recreating Sputnik-1, Part 2 (December 2023)

Purchase a printed copy of this issue for $12.50.

Project by Tim Blythman When designing or testing a device that runs from a coin cell, you need to know how much current it draws to determine the cell’s life. That can be difficult given the low currents often involved. This device will power such a circuit while showing the voltage, current and other helpful statistics. Coin Cell Emulator W e have published many designs powered by coin cells (usually the CR2032). They must not draw an excessive current; a high current draw reduces the cell life and causes its voltage to sag due to internal resistance. Coin cells also exhibit a reduced capacity at high discharge rates, compounding the effect. While many circuits can be characterised with a standard multimeter, that doesn’t work well for this type of circuit. A typical multimeter’s shunt on the microamp range has quite a high resistance; values around 100W are typical. That is OK for readings in the microamp range, but when the current draw might briefly jump to 5mA or so, the meter is suddenly dropping half a volt, which can change the circuit behaviour substantially. In other words, the burden voltage starts to dominate the reading. One possible solution is the MicroCurrent DMM Adaptor (April 2009 issue, siliconchip.au/Article/1400). That article discusses burden voltage in detail. However, this Coin Cell Emulator does more than just measure current. It can accumulate the current readings to calculate a capacity value in mAh. It can also produce a varying voltage, so you can test how your circuit behaves as the cell discharges. The Emulator can also mimic some of the non-ideal characteristics of coin cells, such as internal resistance & voltage fall-off as the battery discharges. Design Like the MicroCurrent DMM Adaptor mentioned earlier, the Coin Cell Emulator uses the MAX4238/ MAX4239 ultra-low offset, low noise precision op amp to sense very small currents without influencing them. This op amp has a typical input offset of 0.1µV and an input offset current of 1pA. These are a few orders of magnitude lower than we are trying to Features & Specifications » Emulates the properties of a coin cell, including internal resistance and discharge over time » Emulates reduced capacity at high currents » Adjustable voltage » Current and charge measurement » Stopwatch/Timer » Automatically stops when a threshold voltage is reached » Dummy PCB can be slotted into a coin cell holder » Voltage setting: in 0.1V steps » Typical accuracy: 1% » Current measurement: 0.1μA resolution up to 200mA » Charge measurement: 1μAh resolution up to 9Ah » Voltage measurement: 0.01V resolution up to 3.4V » Time measurement: 1s resolution up to 999 days 72 Silicon Chip Australia's electronics magazine measure, so they are unlikely to interfere with our readings. This is a necessary feature but insufficient to ensure we can measure a wide range of currents. Our design has an upper limit of around 200mA but can measure down to 0.1µA. To do this across a single range would require an ADC (analog-to-digital converter) with 21 bits of resolution. Instead, our design uses two ranges and a 12-bit ADC that’s built into the microcontroller. Oversampling (making multiple measurements and averaging them) gives us a few more bits of resolution, providing the necessary dynamic range. Circuit details Fig.1 is the circuit diagram for the Emulator. 5V power comes in via mini-USB connector CON1, with a 10µF capacitor providing board-level supply bypassing. IC1 is an eight-bit PIC16F18146 microcontroller that controls and monitors the Emulator’s operation. IC1’s internal DAC (digital-to-analog converter) can deliver 0-4V from pin 17. Unlike some older PICs, the DAC on the PIC16F18146 has an internal buffer and thus has a reasonable drive strength. The DAC voltage goes to NPN transistor Q1’s base via a 1kW resistor. Q1 is configured as an emitter follower, so its emitter ranges from 0V to 3.4V, about one diode drop below the 4V maximum from the DAC. Its collector is connected to the 5V rail. The emitter-follower relies on the reasonably constant base-emitter forward voltage of around 0.6V. Assuming the base voltage is constant, the siliconchip.com.au Fig.1: the cunning part of this circuit is the op amp feeding current back into the output through the 10kW resistor to cancel out the voltage drop across the 22W resistor. This allows the circuit to work with two current measuring resistances of vastly differing values, giving it a very wide current measurement range. transistor switches on harder if the voltage at the emitter drops, increasing the collector-emitter current and raising the voltage at the emitter. If the emitter voltage rises, the transistor base current decreases, and less current comes in through the collector. So the circuit maintains the emitter voltage at a steady ~0.6V below the base voltage. A 1µF capacitor provides some filtering and can provide brief bursts of current to the load. The 1kW emitter resistor provides a stable load and ensures that the output voltage decreases if the base voltage decreases. The 22W resistor acts as a current measuring shunt, with two of the microcontroller’s ADC pins monitoring the voltage across the shunt via 10kW resistors. Each ADC pin also has a 100nF capacitor to ground to present a low impedance to the ADC sampling stage. The ADC pins are labelled VSHUNT, upstream of the shunt resistor, and VOUT, downstream. siliconchip.com.au The downstream side of the 22W resistor is the positive side of the emulated coin cell, with circuit ground being the negative side. This is available at a pair of 2-pin connectors (CON3 and CON4) and a couple of large pads on a circular part of the PCB. This part of the PCB has a pad on each side and can be slotted into some 2032-sized coin cell holders. Op amp IC2 has its input pins (pins 2 and 3) connected across the 22W shunt, with its output (pin 6) feeding back into the low side of the shunt via diode D1 and a 10kW resistor. A third ADC pin of IC1 (pin 10; labelled ILSENSE) monitors the voltage at the diode’s cathode via another 10kW resistor and 100nF capacitor arrangement. A 100nF capacitor bypasses IC2’s 5V supply (pin 7) and ground (pin 4). Pin 1 (SHDN) is also pulled up to the 5V rail, allowing the op amp to operate normally when powered. Op amp operation If a small current flows through the Australia's electronics magazine 22W resistor, a voltage appears across the op amp’s input terminals and its output rises. Current flows through the diode and 10kW resistor back to its inverting input and the downstream end of the shunt resistor. The diode ensures the op amp can only source and not sink current. Effectively, the op amp overrules the shunt and supplies current to the output of the Emulator. Smaller currents can be sensed by measuring the voltage across the 10kW resistor and applying Ohm’s Law. Eventually, the op amp output saturates and cannot supply enough current. It has nearly rail-to-rail operation, so its maximum output is around 4.9V. Assuming the Emulator output is at about 3V, there is around 1.3V across the 10kW resistor, with the op amp supplying around 130µA. Coin Cell Emulator Kit SC6823 ($30 + postage): contains all parts and the optional 5-pin header. December 2023  73 The Coin Cell Emulator is a compact but handy development and testing tool. Even if you don’t design circuits for coin cell operation, it’s a useful low-voltage PSU with current monitoring. The voltage across the 22W resistor can now develop and is measured by the ADC channels connected across it. We can thus measure across a wide dynamic range since we are effectively using two shunts with vastly different resistances. Combining the currents is as simple as adding them. Using a high-side measuring shunt also means that the ground circuit is uninterrupted and can be shared with any other gear that needs to be attached (programmers, debugging gear or other meters) without affecting current readings. This is handy, especially if you are running everything from a computer. The test point labelled RST was originally included to allow the Emulator to control a connected circuit by pulsing its reset line low. But since the Emulator can power cycle the circuit, we did not implement this feature. Instead, a nominal 1Hz clock signal is available at this pin. This can be used to trim IC1’s internal timer for accurate timekeeping. Short circuit handling Let’s examine what happens when a short circuit is applied to the output of the Emulator. With the DAC set to its maximum of 4V, around 140mA flows through the 22W resistor. With a typical transistor β (gain) of around 400, the base current is around 350μA and the 1kW resistor on Q1’s base drops 0.35V, so the voltage at the emitter falls from 3.4V to around 3V. The transistor thus dissipates around 280mW (2V × 140mA), comfortably within its 500mW rating. The remaining voltage is across the 74 Silicon Chip 22W resistor and it dissipates around 400mW. That’s a bit on the high side for the typical 1/4W rating of an M3216/1206-size SMD part. Our prototype got quite hot around that resistor with the output short-circuited, but it was not damaged. 1/2W resistors are available in this size, so that’s what we’re specifying. That allows the Emulator to handle a short circuit on its output indefinitely. ADC input impedance One design consideration was ensuring that the ADC sampling did not unduly load the Emulator’s output. A load of even 1MW to ground would be measurable, as it would draw 3µA at 3V. Two ADC channels are fed directly from low-impedance sources and unaffected by loads; transistor Q1 and op amp IC2 drive the VSHUNT and ILSENSE lines, respectively. Effectively, they are upstream of their respective shunts. On the other hand, any load applied to the VOUT line would be indistinguishable from a load at the Emulator output. The ADC input used to sense the VOUT voltage is such a load. The ADC input consists of a small capacitor, nominally 28pF, which is connected to the ADC pin to sample the voltage. The capacitor is then connected to the internal ADC circuitry (and disconnected from the pin) to perform the conversion. The ‘switched capacitor’ model can be used to calculate an equivalent DC resistance. A switched capacitor is simply a capacitor that is switched between two different connections at a known frequency. The resistance of such an arrangement is simply 1/CF, where C is the capacitance in farads and F is the frequency in hertz. With our 100Hz sampling, this comes out to around 350MW, which is more than high enough. Higher sampling rates would reduce this apparent resistance. Another point to consider is that the ADC capacitor is not discharged between samples, so the load presented by the switched capacitor is not equivalent to a load to ground, but rather as a resistance between the different sampling points. That raises its effective resistance. Australia's electronics magazine The PIC16F18146 has an ADCC (analog to digital converter with computation) module. We previously used some of its advanced features in the Digital Boost Regulator (December 2022; siliconchip.au/Article/15588). The differential ADC inputs make it much easier and more accurate to measure the difference between two voltages, as we are doing here. The sampling time is also programmable, so we have extended it slightly to ensure the sampling capacitor can fully settle at the input voltage. There is also a DIA (device information area) that holds information such as the measured value of the chip’s internal voltage references. This means we can measure voltages against this reference without a separate calibration step. The DAC mentioned earlier is an 8-bit type with a 4.096V (nominal) voltage reference. It can deliver up to around 4V in 16mV steps and can produce a voltage with 0.1V precision. The output voltage at VSHUNT and VOUT is thus limited by design to around 3.4V. This works well with circuits using 3.3V microcontrollers that typically have a 3.6V upper limit. The MAX4238 op amp specifies a common mode voltage up to around 3.6V (with a 5V supply) and the op amp inputs stay within that range. Microcontroller and interface IC1’s pins 2, 3 and 5 connect to switches S1, S2 and S3, respectively, with their other sides grounded. The micro applies an internal weak pullup current to each, so it can detect button presses as level changes on those pins. An I2C OLED module is connected to IC1’s pins 12 and 13 for the SDA and SCL signals. The OLED is powered from 5V; it has an onboard 3.3V regulator with I2C pullups, allowing it to interface with a microcontroller running from 3.3V or 5V. IC1 has a local 100nF bypass capacitor between its pin 1 supply and pin 20 ground. Pin 4 (MCLR) is pulled up to 5V by a 10kW resistor, allowing the microcontroller to run. These pins and pins 18 and 19 (PGC and PGD) are taken to CON2 for in-­ circuit serial programming (ICSP) of the microcontroller. Coin cell behaviour model As the saying goes, all models are incorrect, but some are still useful! siliconchip.com.au There are several characteristics of coin cells that we are explicitly modelling. We’re not claiming that the model is comprehensive, but it mimics the behaviour of a real coin cell well enough to be useful. Our model is based mainly on a CR2032 cell, as that is what we have used the most. We fitted graphs provided by several CR2032 manufacturers to curves described by simple equations, adjustable by a single parameter. There is a lot of variation between manufacturers and even between cells from the same manufacturer under different conditions. The default behaviour of the Emulator is similar to a typical coin cell. Firstly, coin cells have internal resistance. For CR2032 cells, the value is around 20W, but it can change with load and state of charge. Other 20mm diameter cells, such as the CR2016 (half as thick as a CR2032 at 1.6mm), appear to have a similar internal resistance. So the Emulator will also be suitable for thinner cells of the same diameter but might not be as accurate for those with a smaller diameter. A simple way to model the internal resistance is with a fixed resistor, and we chose the 22W part that we have already explained. One advantage of using a fixed resistor is that this resistor can also be used as a current measuring shunt. The actual circuit appears to have an internal resistance of around 24.5W, as the 1kW base resistor carries a current in proportion to the load current divided by the β (gain). So it adds We have used a socket header to attach the OLED module in our prototype, but the Emulator will be much more robust if you solder the display directly to the main PCB. around 2.5W (1000W ÷ 400) of resistance for a β of around 400. The next factor is that, like most batteries, the terminal voltage drops as the cell discharges until it is flat. For coin cells, the voltage drops a little at the start, then is quite steady for most of the cell life. Once it starts to fall after that, it does so quite dramatically. While we looked at using a curve to model this, curves that fit all three stages were complex, and we found that they weren’t helpful for observing circuit behaviour as the cell goes flat. Instead, we have implemented a simple model that maintains a flat voltage and then linearly changes the output voltage as the cell’s state of charge (SoC) nears its endpoint. For example, with this set to 10%, the voltage is flat from 100% to 10% SoC, then drops to half by 5% SoC. Finally, the voltage is ramped to zero when the Emulator determines the cell is flat. This feature can be turned off (set to 0%) to disable this behaviour. Fig.2 shows the graph of the data sheet behaviour compared with the emulated behaviour. Fig.2: our emulated cell voltage curve is much simpler than that seen in many coin cell data sheets, but it still mimics the cell going flat. Otherwise, we prefer to manually adjust the voltage and observe what happens. siliconchip.com.au While we could have more closely emulated this with, say, four linear sections, we decided not to do that. We found that a constantly changing voltage during use interfered with monitoring the device’s operation. In other words, we have sacrificed reality for usability. Our simple voltage curve provides a voltage that behaves very predictably. It does omit the higher voltage at the start, but that can easily be emulated manually by initially setting the voltage to 3.2V, observing the operating, then manually dropping the voltage to 3V. Another well-known aspect is that a cell’s apparent capacity (in mAh) is reduced if it needs to supply a heavier load. The manufacturers also provide graphs to characterise this behaviour. One typical graph we saw showed that a nominally 240mAh cell provides only 150mAh with a continuous discharge of 3mA, nearly halving its effective capacity. We found quite a few curves that demonstrate this behaviour. The data varied quite a bit, but it was clearly some form of polynomial relationship. Fig.3: the reduction in useful capacity is modelled as a straightforward quadratic curve. It’s a compromise between simplicity and accuracy. Australia's electronics magazine December 2023  75 Firmware The Coin Cell Emulator shown at actual size, along with the wire added to the back of the PCB (right). This increases the thickness of the PCB to bring it nearer to that of a CR2032 cell (3.2mm thick vs 1.5-1.6mm thick for the PCB). You’ll need to apply a bit of heat to get the solder to take to the large copper area. A good technique for finding the order of polynomial relationships is to take a plot of the logarithms of the variables in question. The order of the polynomial is related to the slope of this graph. Consider the quadratic equation y = x2. The value of log(x2) is equal to 2log(x), for positive values of x, so the graph of log(y) or 2log(x) against log(x) would have a gradient of two, suggesting a quadratic equation of some sort (a quadratic is a second-order polynomial). We found that the slopes of these log/log plots were just over two. So we modelled this with a quadratic equation and found that it fit quite well to the manufacturer data and was simple enough for the 8-bit micro to calculate. We didn’t see any charts that show behaviour much above 5mA but this model also allows us to extrapolate. This extrapolation suggests severely degraded capacity as the current enters this region. Our experience is that coin cells discharge very quickly if you draw much more than 5mA from them, so this makes sense. Our model takes a parameter equal to the current at which the cell capacity is halved. We have used a default value of 3.5mA, which matches the CR2032 data sheets we examined. It also makes it easier to match your Emulator to a specific cell if required. If this value is set to zero, then there is no modelling and the Emulator will show the same capacity no matter what current is drawn. Fig.3 shows the graph of the model against typical data from a cell data sheet. Regarding the short circuit behaviour noted earlier, it should be apparent that, like a real coin cell, the Emulator will quickly ‘go flat’, effectively ending the short-circuit condition. Fig.4: the rise time of the output is limited by the capacity of the circuit to supply the current to charge the 1µF capacitor at its output (the timebase is in µs here). The DAC that controls the voltage has a settling time of around 10µs. 76 Silicon Chip For the most part, the microcontroller allows the user to set the output voltage, although it can modify that based on the discharge modelling. It monitors the voltages around the circuit and calculates and sums the currents in the two measuring shunts. A timer keeps track of time intervals and allows the current to be accumulated over time for the charge and capacity calculations. The measured charge (in mAh) is taken from the actual value, while the SoC calculation is based on the modified behaviour at higher currents. All this information is displayed on the OLED screen. There are modes to allow a test to be started and paused. These tests turn on the output voltage, start the timer and start the charge accumulator. The test can be ended manually or automatically at a previously set endpoint voltage. Alternatively, the Emulator can simply be used as a power supply that can monitor the current consumed by the circuit under test. A settings screen can be used to trim the parameters used to set the output voltage. Since the Emulator can measure its output, a calibration routine can set these automatically. You can also trim the resistance values of the shunt resistors and adjust numerous parameters that control the coin cell emulation. Since the PIC16F18146 has an internal EEPROM memory (which can withstand more write cycles than flash Fig.5: the longer fall time of the Emulator output is almost entirely due to the 1ms time constant of the 1kW/1µF RC combination. After about 4ms (four time constants), the voltage settles near its 0V endpoint. Australia's electronics magazine siliconchip.com.au Assembly The Emulator is built on a small PCB with surface-mounting components. They are the typical range of SOIC, SOT-23 and M3216/1206 parts that are fairly easy to solder. Fig.6 is the PCB overlay diagram; you can also refer to the photo of the PCB before the OLED module is attached. We recommend using a fine-tipped soldering iron, solder flux paste, thin solder wire, tweezers, a magnifier and good lighting. Solder wicking braid is helpful for removing bridges and excess solder. Work outside if you don’t have good ventilation or fume extraction. 1 double-sided PCB coded 18101231, 78 × 44mm 1 Mini-USB SMD connector (CON1) 1 5-way right-angle male header, 2.54mm pitch (CON2; optional, for ICSP) 1 1.3in I2C blue OLED module (MOD1) [Silicon Chip SC5026] 3 2-pin SMD tactile switches (S1-S3) 4 small self-adhesive rubber feet Semiconductors 1 PIC16F18146-I/SO microcontroller programmed with 1810123A.HEX, wide SOIC-20 (IC1) 1 MAX4238 or MAX4239 low-offset op amp, SOIC-8 (IC2) 1 BC817-40 NPN transistor, SOT-23 (Q1) 1 LL4148 SMD diode, SOD-80/MiniMELF (D1) Capacitors (all SMD M3216/1206 X7R) 1 10μF 10V 1 1μF 16V 6 100nF 50V Resistors (all SMD M3216/1206 1% ¼W unless noted) 5 10kW (code 1002 or 103) 2 1kW (code 1001 or 102) 1 22W ½W (code 22R0 or 22R) MAX4239 K CON3 1 10 m F 100nF 100nF + 10kW BC817 – + CON4 – 1kW Q1100nF10k 1kW 1mF 22W 10k 100nF Start with the mini-USB socket, CON1. Apply flux to all its pads and rest the part on top. Its locating pegs should lock into holes in the PCB, aligning it. Clean your iron’s tip and add a small amount of fresh solder, then touch it to where the pins meet the PCB pads. After that, apply a generous amount of solder to the four larger pads that affix the connector’s shell. If you have bridges between the pins, add some extra flux and press some fresh braid against the bridge with the iron. When the braid has taken up solder, slowly draw both away together. If the part is flat against the PCB, surface tension should leave enough solder to form a solid joint. Fit Q1 next by spreading flux on its PCB pads and resting it in place, being sure to align the body with the silkscreen printing. Tack one lead, ensure the part is flat and aligned within all pads, then solder the remaining leads. Solder the two ICs next, using a similar process, starting with one lead to locate the part. Both ICs should have Parts List – Coin Cell Emulator IC1 PIC16F18146 D1 4148 100nF 10kW LL4148 CON1 RS T GND VCC SCL SDA 10kW MOD1 IC2 Figs.4 and 5 show the rise and fall times of the output voltage in response to a change in the setpoint. These charts were taken in an unloaded state (although the Emulator accurately indicated the expected 0.3µA draw from the 10MW scope probe at 3V!). As expected, the rise time is short, about 20µs from 0V to 3V. About half of this is due to the 10µs settling time of the DAC, with the other half being the time to charge the 1µF capacitor with the 200mA available. The fall time is dominated by the 1ms time constant of the 1kW/1µF pair and takes about 4ms to settle near its final value. An external load will speed this up. CON2 100nF Response time Fig.6: assembling the PCB mainly involves fitting SOIC and M3216/1206 SMD parts. Take care with the orientation of the two ICs and D1. ‘Mousebites’ are provided so you can separate the PCB between CON3 and CON4; the two halves can be rejoined with some light-duty figure-8 wire. ICSP memory), the calibration and setup parameters are immediately stored in EEPROM when modified. S1 S2 S3 a small pin 1 divot in one corner, so align that with the PCB markings. For IC2, this might be a notch at the pin 1 end. For diode D1, ensure its cathode stripe aligns with the ‘K’ marking on the PCB. After this, none of the components are polarised. The capacitors will not be marked, so be careful not to get them mixed up. The resistors will be marked with codes, as shown in the parts list. The PCB will now need a thorough cleaning to remove flux residue. At the minuscule currents the Emulator measures, any contaminants can cause leakage and interfere with measurements. Your flux might recommend a solvent, but we find that isopropyl alcohol works well (another great option is Chemtools Kleanium G2). Wipe away any excess solvent and allow the remainder to evaporate thoroughly. Give the PCB a thorough check now that it has been cleaned, as any problems will be easier to spot and repair before the OLED is fitted, as it covers many of the components. Now solder on the three tactile switches, being sure to align them within their silkscreen outlines and keep them flat against the PCB. If you need to program your microcontroller, add the CON2 ICSP header. Next, solder the OLED module in place using its four-pin header, aligning the pin markings and spacing it above the other components on the PCB. When you are happy with its location, solder stiff wires to the lower corners of the OLED module and secure them to the through-hole pads in the PCB below. Finally, attach the rubber feet to the underside of the PCB so it won’t scratch your work surface. Programming PICs supplied in kits or purchased separately from our Online Shop come December 2023  77 Table 1 – Settings Page – Parameter Notes Set Cap The default allows for brief tests. It can be set from 1-10mAh steps of 1mAh or up to 250mAh in steps of 5mAh. Endpoint It can be set from 0 to 3.4V in 0.1V steps, the same as the output voltage. Current Comp. The current at which the effective cell capacity is halved. It can be set in steps of 0.1mA; if set to 0mA, there is no compensation. 3.5mA is typical for CR2032 cells. Voltage Fall Below this level, the cell voltage setpoint is linearly decreased to reach 0V at 0% SoC. If set to 0%, then there is no decline in voltage. Nominal emulated cell capacity Default = 10mAh The voltage at which tests stop Default = 2V Determines how cell capacity is affected by high currents Default = 3.5mAh SoC at which the cell voltage starts to decline Default = 5% Screen Calibrate Ensure the output is not connected to any loads and press S1 to start. This sets the Q1 Vbe and DAC span automatically. Pressing S2 sets all parameters back to their defaults. Set Q1 Vbe Set by the Calibrate step. If voltages across the range are still too high, increase this value. There is a slight offset below 0.3V output; voltages are not as accurate in that range. Set DAC span If the voltage offset increases across the range, decrease this; if it becomes lower, increase it. Set R(hi) (22W) It can be set in steps of 0.01W within 10% of 22W. 1% parts should not need calibration. Set R(lo) (10kW) It can be set in steps of 1W within 10% of 10kW. 1% parts should not need calibration. Trim Timer The Emulator’s 1Hz clock is available at the RST pin (with respect to ground). This can be measured to help trim the timer. Each step will change the frequency by about 0.4%. Exit Setup All values are saved to EEPROM as soon as any changes are made and new settings are used immediately. Start automatic calibration voltage Transistor Q1 baseemitter junction voltage Default = 588mV The nominal span of the DAC output Default = 4002mV Actual value of 22W resistor Default = 22.00W Actual value of 10kW resistor Default = 10000W The displayed value is the period of the timer counter Default = 243 Press S1 to return to normal operation 78 Silicon Chip Australia's electronics magazine programmed, so skip this section if you have one of those. The PIC16F18146 requires a PICkit 4, PICkit 5 or Snap programmer. If you are using a Snap (which does not provide power), you can supply power using a USB cable connected to CON1. You might need to use some short extension wires to prevent the Snap from fouling the USB cable. You can use the Microchip IPE to program the 1810123A.HEX file. If you don’t have the IPE installed, it can be downloaded and installed for free as part of the most recent MPLAB X IDE. Once programmed, the startup OLED screen should look like Screen 1. Setup The Coin Cell Emulator is usable without calibration, but we recommend doing it since it is easy and only needs to be done once. Hold in S3 until the screen goes blank, then release it to enter SETUP mode. Table 1 summarises the individual setup pages you can cycle through by pressing S3. In general, S1 decreases a parameter while S2 increases it. On some pages, they trigger specific actions, such as starting the automatic calibration process or returning to normal operation from SETUP. The first four SETUP screens relate to the emulation settings and can be skipped to reach the calibration settings. We recommend just running the automatic “Calibrate” step. If the Emulator’s other measurements are off, you could consider changing other values, such as the resistances or timer trim. Cycle to the Exit Setup page and press S1 to return to regular operation. Connections CON3, CON4 and the circular pads can all be used to connect to a circuit under test. For most of our prototyping, we simply used a header socket for CON3 and ran jumper wires to our circuit. The circular section of the PCB is designed to be slotted into the side of a cell holder. The photo opposite shows the Emulator connected to our Advanced Test Tweezers. It probably won’t work with other cell holder types where the cell is inserted from above. Since the PCB is only 1.6mm thick, it will not be a tight fit for holders that siliconchip.com.au Screen 1: the initial screen seen when the Emulator powers on allows the output voltage setpoint to be changed with pushbuttons S1 and S2. S3 switches to the other screens. Holding S3 for three seconds enters the Setup mode, shown in Table 1. Screen 2: the output can be toggled on and off when this screen is shown. Note also the supply voltage display at upper right. If this is flashing, the supply is lower than 4.5V or higher than 5.5V, and the Emulator may not function correctly. Screen 3: S1 and S2 start and reset the stopwatch timer and charge accumulator measurement, respectively. If the timer is running, this screen will show PAUSE instead, with S1 pausing the timer if pressed. expect a 3.2mm-high CR2032 cell, although many holders are designed to accept 1.6mm thick CR2016 cells. You could carefully bend the cell holder’s tabs to add more tension. We also added some thickness to the Emulator by soldering on some pieces of wire, as shown on page 76. Another option is to carefully break the PCB between CON3 and CON4 (there are ‘mouse bites’ in the PCB to facilitate this). You could then run a pair of wires between CON3 and CON4 to join them. the emulated cell is nearly flat. The fourth line (in larger text) shows the measured current. It is in a larger font as it is the most important parameter to observe. If “I(lo)” is shown, the reading is expected to be accurate to 0.1µA as only the 10kW resistor is being used as a shunt. When “I(hi)” is shown, the Emulator has switched to the higher range and the 22W resistor comes into play. When this happens depends on the output voltage and supply voltage (which relates to IC2’s headroom). At 3V output, it will occur at around 130μA. The second-last line shows the stopwatch timer, which measures up to 999 days, or almost three years. The text on this line indicates if the timer is running and, if so, the charge measurements on the next line are also accumulating. The µAh reading on the last line measures actual charge consumption (not adjusted). It can be used to validate the total current consumption and estimate potential capacity losses due to high current usage. The SoC figure does take into account the adjusted current. Pressing S3 shows Screen 2, which allows the output voltage to be switched on and off; S1 switches it off, while S2 switches it on. Screen 3 is reached by pressing S3 again; it allows the timer and charge accumulator to be paused, started and reset. S1 will start and pause the timer, while pressing S2 resets the timer and accumulator when the timer is paused. Press S3 again to reach Screen 4. Pressing S1 (“GO”) on this screen will switch on the output voltage and start the timer and accumulator; S2 (“PAUSE”) will pause the timer and switch the output off. Thus it can be used to start and stop testing cycles. Once you’ve started a test, the current draw will be shown, and the timer and accumulator will go up while the SoC goes down. As the SoC passes 5%, the output voltage will drop to simulate the cell running flat. When the output voltage reaches the endpoint, the test will pause, as if S2 were pressed on this screen, allowing the statistics to be recorded. Operation Screen 1 shows the default Emulator cell voltage of 3V, which can be changed on that page. Other features on Screen 1 are common to the operating Screens. The third line of text shows the status of the output voltage; the first figure is the setpoint (target) output voltage and whether it is on or off. The other voltages are the values upstream and downstream of the shunt, respectively. They can be considered the internal cell voltage and external ‘terminal’ voltage, respectively. The first should be very close to the set voltage (when on), except if Conclusion We’re already making good use of the Coin Cell Emulator in designing an upcoming project. It’s also coming in handy as a general power supply SC for low voltages and currents. The circular section of the PCB is designed to slot straight into the cell holder we’ve used for various projects, including the Advanced Test Tweezers shown here. In this case, testing would be easier if we separated the PCB between CON3 and CON4 for a more flexible connection. Screen 4: pressing S1 here starts the timer and charge accumulator and switches on the output voltage. S2 pauses the test, allowing the results to be recorded. The test will be automatically paused if the Emulator reaches its endpoint voltage. siliconchip.com.au Australia's electronics magazine December 2023  79