Silicon ChipCoin Cell Emulator - November 2024 SILICON CHIP
  1. Contents
  2. Publisher's Letter: The challenges of making electronics work worldwide
  3. Feature: The Fox Report by Barry Fox
  4. Feature: Net Work by Alan Winstanley
  5. Project: Ideal Diode Bridge Rectifiers by Phil Prosser
  6. Feature: Practically Speaking by Jake Rothman
  7. Back Issues
  8. Feature: Max’s Cool Beans by Max the Magnificent
  9. Project: Multi-Channel Volume Control, part one by Nicholas Vinen
  10. Feature: Teach-In 2024 – Learn electronics with the ESP32 by Mike Tooley
  11. Feature: Techno Talk by Max the Magnificent
  12. Project: Coin Cell Emulator by Tim Blythman
  13. Feature: Circuit Surgery by Ian Bell
  14. Review: MG4 XPower electric vehicle by Julian Edgar
  15. Subscriptions
  16. Feature: 14-segment, 4-digit LED Display Modules by Jim Rowe
  17. PartShop
  18. Advertising Index
  19. Market Centre
  20. Back Issues

This is only a preview of the November 2024 issue of Practical Electronics.

You can view 0 of the 80 pages in the full issue.

Articles in this series:
  • The Fox Report (July 2024)
  • The Fox Report (September 2024)
  • The Fox Report (October 2024)
  • The Fox Report (November 2024)
  • The Fox Report (December 2024)
  • The Fox Report (January 2025)
  • The Fox Report (February 2025)
  • The Fox Report (March 2025)
  • The Fox Report (April 2025)
  • The Fox Report (May 2025)
Articles in this series:
  • Win a Microchip Explorer 8 Development Kit (April 2024)
  • Net Work (May 2024)
  • Net Work (June 2024)
  • Net Work (July 2024)
  • Net Work (August 2024)
  • Net Work (September 2024)
  • Net Work (October 2024)
  • Net Work (November 2024)
  • Net Work (December 2024)
  • Net Work (January 2025)
  • Net Work (February 2025)
  • Net Work (March 2025)
  • Net Work (April 2025)
Articles in this series:
  • Practically Speaking (November 2024)
  • Practically Speaking (February 2025)
Articles in this series:
  • Max’s Cool Beans (April 2024)
  • Max’s Cool Beans (May 2024)
  • Max’s Cool Beans (June 2024)
  • Max’s Cool Beans (July 2024)
  • Max’s Cool Beans (August 2024)
  • Max’s Cool Beans (September 2024)
  • Max’s Cool Beans (October 2024)
  • Max’s Cool Beans (November 2024)
  • Max’s Cool Beans (December 2024)
Items relevant to "Multi-Channel Volume Control, part one":
  • 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 Part 2 (January 2024)
  • Multi-Channel Volume Control, part one (November 2024)
  • Multi-Channel Volume Control, Part 2 (December 2024)
Articles in this series:
  • Teach-In 2024 (April 2024)
  • Teach-In 2024 (May 2024)
  • Teach-In 2024 – Learn electronics with the ESP32 (June 2024)
  • Teach-In 2024 – Learn electronics with the ESP32 (July 2024)
  • Teach-In 2024 – Learn electronics with the ESP32 (August 2024)
  • Teach-In 2024 – Learn electronics with the ESP32 (September 2024)
  • Teach-In 2024 – Learn electronics with the ESP32 (October 2024)
  • Teach-In 2024 – Learn electronics with the ESP32 (November 2024)
Articles in this series:
  • (November 2020)
  • Techno Talk (December 2020)
  • Techno Talk (January 2021)
  • Techno Talk (February 2021)
  • Techno Talk (March 2021)
  • Techno Talk (April 2021)
  • Techno Talk (May 2021)
  • Techno Talk (June 2021)
  • Techno Talk (July 2021)
  • Techno Talk (August 2021)
  • Techno Talk (September 2021)
  • Techno Talk (October 2021)
  • Techno Talk (November 2021)
  • Techno Talk (December 2021)
  • Communing with nature (January 2022)
  • Should we be worried? (February 2022)
  • How resilient is your lifeline? (March 2022)
  • Go eco, get ethical! (April 2022)
  • From nano to bio (May 2022)
  • Positivity follows the gloom (June 2022)
  • Mixed menu (July 2022)
  • Time for a total rethink? (August 2022)
  • What’s in a name? (September 2022)
  • Forget leaves on the line! (October 2022)
  • Giant Boost for Batteries (December 2022)
  • Raudive Voices Revisited (January 2023)
  • A thousand words (February 2023)
  • It’s handover time (March 2023)
  • AI, Robots, Horticulture and Agriculture (April 2023)
  • Prophecy can be perplexing (May 2023)
  • Technology comes in different shapes and sizes (June 2023)
  • AI and robots – what could possibly go wrong? (July 2023)
  • How long until we’re all out of work? (August 2023)
  • We both have truths, are mine the same as yours? (September 2023)
  • Holy Spheres, Batman! (October 2023)
  • Where’s my pneumatic car? (November 2023)
  • Good grief! (December 2023)
  • Cheeky chiplets (January 2024)
  • Cheeky chiplets (February 2024)
  • The Wibbly-Wobbly World of Quantum (March 2024)
  • Techno Talk - Wait! What? Really? (April 2024)
  • Techno Talk - One step closer to a dystopian abyss? (May 2024)
  • Techno Talk - Program that! (June 2024)
  • Techno Talk (July 2024)
  • Techno Talk - That makes so much sense! (August 2024)
  • Techno Talk - I don’t want to be a Norbert... (September 2024)
  • Techno Talk - Sticking the landing (October 2024)
  • Techno Talk (November 2024)
  • Techno Talk (December 2024)
  • Techno Talk (January 2025)
  • Techno Talk (February 2025)
  • Techno Talk (March 2025)
  • Techno Talk (April 2025)
  • Techno Talk (May 2025)
  • Techno Talk (June 2025)
Articles in this series:
  • Circuit Surgery (April 2024)
  • STEWART OF READING (April 2024)
  • Circuit Surgery (May 2024)
  • Circuit Surgery (June 2024)
  • Circuit Surgery (July 2024)
  • Circuit Surgery (August 2024)
  • Circuit Surgery (September 2024)
  • Circuit Surgery (October 2024)
  • Circuit Surgery (November 2024)
  • Circuit Surgery (December 2024)
  • Circuit Surgery (January 2025)
  • Circuit Surgery (February 2025)
  • Circuit Surgery (March 2025)
  • Circuit Surgery (April 2025)
  • Circuit Surgery (May 2025)
  • Circuit Surgery (June 2025)
Articles in this series:
  • El Cheapo Modules From Asia - Part 1 (October 2016)
  • El Cheapo Modules From Asia - Part 2 (December 2016)
  • El Cheapo Modules From Asia - Part 3 (January 2017)
  • El Cheapo Modules from Asia - Part 4 (February 2017)
  • El Cheapo Modules, Part 5: LCD module with I²C (March 2017)
  • El Cheapo Modules, Part 6: Direct Digital Synthesiser (April 2017)
  • El Cheapo Modules, Part 7: LED Matrix displays (June 2017)
  • El Cheapo Modules: Li-ion & LiPo Chargers (August 2017)
  • El Cheapo modules Part 9: AD9850 DDS module (September 2017)
  • El Cheapo Modules Part 10: GPS receivers (October 2017)
  • El Cheapo Modules 11: Pressure/Temperature Sensors (December 2017)
  • El Cheapo Modules 12: 2.4GHz Wireless Data Modules (January 2018)
  • El Cheapo Modules 13: sensing motion and moisture (February 2018)
  • El Cheapo Modules 14: Logarithmic RF Detector (March 2018)
  • El Cheapo Modules 16: 35-4400MHz frequency generator (May 2018)
  • El Cheapo Modules 17: 4GHz digital attenuator (June 2018)
  • El Cheapo: 500MHz frequency counter and preamp (July 2018)
  • El Cheapo modules Part 19 – Arduino NFC Shield (September 2018)
  • El cheapo modules, part 20: two tiny compass modules (November 2018)
  • El cheapo modules, part 21: stamp-sized audio player (December 2018)
  • El Cheapo Modules 22: Stepper Motor Drivers (February 2019)
  • El Cheapo Modules 23: Galvanic Skin Response (March 2019)
  • El Cheapo Modules: Class D amplifier modules (May 2019)
  • El Cheapo Modules: Long Range (LoRa) Transceivers (June 2019)
  • El Cheapo Modules: AD584 Precision Voltage References (July 2019)
  • Three I-O Expanders to give you more control! (November 2019)
  • El Cheapo modules: “Intelligent” 8x8 RGB LED Matrix (January 2020)
  • El Cheapo modules: 8-channel USB Logic Analyser (February 2020)
  • New w-i-d-e-b-a-n-d RTL-SDR modules (May 2020)
  • New w-i-d-e-b-a-n-d RTL-SDR modules, Part 2 (June 2020)
  • El Cheapo Modules: Mini Digital Volt/Amp Panel Meters (December 2020)
  • El Cheapo Modules: Mini Digital AC Panel Meters (January 2021)
  • El Cheapo Modules: LCR-T4 Digital Multi-Tester (February 2021)
  • El Cheapo Modules: USB-PD chargers (July 2021)
  • El Cheapo Modules: USB-PD Triggers (August 2021)
  • El Cheapo Modules: 3.8GHz Digital Attenuator (October 2021)
  • El Cheapo Modules: 6GHz Digital Attenuator (November 2021)
  • El Cheapo Modules: 35MHz-4.4GHz Signal Generator (December 2021)
  • El Cheapo Modules: LTDZ Spectrum Analyser (January 2022)
  • Low-noise HF-UHF Amplifiers (February 2022)
  • A Gesture Recognition Module (March 2022)
  • Air Quality Sensors (May 2022)
  • MOS Air Quality Sensors (June 2022)
  • PAS CO2 Air Quality Sensor (July 2022)
  • Particulate Matter (PM) Sensors (November 2022)
  • Heart Rate Sensor Module (February 2023)
  • UVM-30A UV Light Sensor (May 2023)
  • VL6180X Rangefinding Module (July 2023)
  • pH Meter Module (September 2023)
  • 1.3in Monochrome OLED Display (October 2023)
  • 16-bit precision 4-input ADC (November 2023)
  • 1-24V USB Power Supply (October 2024)
  • 14-segment, 4-digit LED Display Modules (November 2024)
  • 0.91-inch OLED Screen (November 2024)
  • The Quason VL6180X laser rangefinder module (January 2025)
  • TCS230 Colour Sensor (January 2025)
  • Using Electronic Modules: 1-24V Adjustable USB Power Supply (February 2025)
Constructional Project 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 volt­ age to sag due to internal resistance. Coin cells also exhibit a reduced ca­ pacity at high discharge rates, com­ pounding the effect. While many circuits can be char­ acterised 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 micro­ amp 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 be­ haviour substantially. In other words, the burden voltage starts to dominate the reading. One possible solution is the Micro­ Current DMM Adaptor from the May Features & Specifications 2011 issue. 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 be­ haves as the cell discharges. The Emulator can also mimic some of the non-ideal characteristics of coin cells, such as internal resist­ ance & voltage fall-off as the battery discharges. Design Like the MicroCurrent DMM Adaptor mentioned earlier, the Coin Cell Em­ ulator 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 cur­ rent of 1pA. These are a few orders of magnitude lower than we are trying to » 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 52 measure, so they are unlikely to inter­ fere with our readings. This is a necessary feature but in­ sufficient 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 averag­ ing 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 boardlevel supply bypassing. IC1 is an eightbit 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 tran­ sistor 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 for­ ward voltage of around 0.6V. Assum­ ing the base voltage is constant, the Practical Electronics | November | 2024 Coin Cell Emulator 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 rais­ ing the voltage at the emitter. If the emitter voltage rises, the tran­ sistor base current decreases, and less current comes in through the collec­ tor. So the circuit maintains the emit­ ter voltage at a steady ~0.6V below the base voltage. A 1µF capacitor provides some fil­ tering and can provide brief bursts of current to the load. The 1kW emitter resistor provides a stable load and en­ sures that the output voltage decreases if the base voltage decreases. The 22W resistor acts as a current measuring shunt, with two of the mi­ crocontroller’s ADC pins monitor­ ing 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. Practical Electronics | November | 2024 The downstream side of the 22W re­ sistor is the positive side of the emulat­ ed 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) moni­ tors 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 oper­ ate normally when powered. Op amp operation If a small current flows through the 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 cur­ rents can be sensed by measuring the voltage across the 10kW resistor and applying Ohm’s Law. Eventually, the op amp output satu­ rates and cannot supply enough cur­ rent. 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. 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 53 Constructional Project 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 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. 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 affect­ ing current readings. This is handy, especially if you are running every­ thing from a computer. The test point labelled RST was originally included to allow the Emu­ lator 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 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 proto­ type got quite hot around that resistor 54 One design consideration was en­ suring 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 un­ affected by loads; transistor Q1 and op amp IC2 drive the VSHUNT and ILSENSE lines, respectively. Effec­ tively, they are upstream of their re­ spective shunts. On the other hand, any load applied to the VOUT line would be indistin­ guishable 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 con­ nected 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 re­ sistance. Another point to consider is that the ADC capacitor is not discharged be­ tween samples, so the load presented by the switched capacitor is not equiv­ alent to a load to ground, but rather as a resistance between the different sampling points. That raises its effec­ tive resistance. The PIC16F18146 has an ADCC (analog to digital converter with com­ putation) module. We previously used some of its advanced features in the Digital Boost Regulator that was pub­ lished in the December 2023 issue. 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 informa­ tion area) that holds information such as the measured value of the chip’s in­ ternal voltage references. This means we can measure voltages against this reference without a separate calibra­ tion 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 cir­ cuits 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 pow­ ered 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 capaci­ tor 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! There are several characteristics of coin cells that we are explicitly mod­ elling. We’re not claiming that the model is comprehensive, but it mimics the behaviour of a real coin cell well enough to be useful. Practical Electronics | November | 2024 Coin Cell Emulator Our model is based mainly on a CR2032 cell, as that is what we have used the most. We fitted graphs pro­ vided by several CR2032 manufactur­ ers to curves described by simple equa­ tions, 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 be­ haviour of the Emulator is similar to a typical coin cell. Firstly, coin cells have internal re­ sistance. 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 in­ ternal resistance. So the Emulator will also be suitable for thinner cells of the same diameter but might not be as ac­ curate 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 resis­ tor can also be used as a current meas­ uring 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 di­ vided by the β (gain). So it adds around 2.5W (1000W ÷ 400) of resistance for a β of around 400. The next factor is that, like most bat­ teries, 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 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. 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 be­ haviour compared with the emulated behaviour. 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 real­ ity for usability. Our simple voltage 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. Practical Electronics | November | 2024 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 operation, 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 dis­ charge of 3mA, nearly halving its ef­ fective 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. 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) Fig.3: the reduction in useful capacity is modelled as a straightforward quadratic curve. It’s a compromise between simplicity and accuracy. 55 Constructional Project 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. would have a gradient of two, suggest­ ing a quadratic equation of some sort (a quadratic is a second-order poly­ nomial). We found that the slopes of these log/log plots were just over two. So we modelled this with a quadratic equa­ tion 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 capac­ ity 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 type of cell if that is 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. Firmware For the most part, the microcontroller allows the user to set the output volt­ age, although it can modify that based on the discharge modelling. It moni­ tors the voltages around the circuit and calculates and sums the currents in the two measuring shunts. 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. 56 A timer keeps track of time inter­ vals and allows the current to be ac­ cumulated over time for the charge and capacity calculations. The meas­ ured 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 ac­ cumulator. The test can be ended man­ ually 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 meas­ ure 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 in­ ternal EEPROM memory (which can withstand more write cycles than flash memory), the calibration and setup parameters are immediately stored in EEPROM when modified. Response time Figs.4 and 5 show the rise and fall times of the output voltage in response to a change in the setpoint. These charts 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. Practical Electronics | November | 2024 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. 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. 100nF IC2 MAX4239 D1 K CON3 PIC16F18146 1 10 m F 100nF 100nF + 10kW BC817 – + CON4 – 1kW Q1100nF10k 1kW 1mF 22W 10k 100nF 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 silk­ screen 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 sim­ ilar process, starting with one lead to locate the part. Both ICs should have a small pin 1 divot in one corner, so 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) 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) Silicon Chip Coin Cell Emulator Kit Capacitors (all SMD M3216/1206 X7R) SC6823 (~£18 + P&P) 1 10μF 10V 1 1μF 16V https://pemag.au/link/AC1J 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) IC1 100nF CON1 Parts List – Coin Cell Emulator Practical Electronics | November | 2024 GND VCC SCL SDA 4148 MOD1 10kW LL4148 CON2 10kW 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 were taken in an unloaded state (al­ though the Emulator accurately indi­ cated 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. RST Coin Cell Emulator S1 S2 S3 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 com­ ponents 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 Emula­ tor measures, any contaminants can cause leakage and interfere with meas­ urements. Your flux might recommend a sol­ vent, but we find that isopropyl alco­ hol works well (another great option is Chemtools Kleanium G2). Wipe away any excess solvent and allow the re­ mainder to evaporate thoroughly. Give the PCB a thorough check now that it has been cleaned, as any prob­ lems 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, align­ ing the pin markings and spacing it above the other components on the PCB. When you are happy with its lo­ cation, 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 the Silicon Chip Online 57 Constructional Project 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. 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. 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% 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 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. The displayed value is the period of the timer counter Default = 243 Press S1 to return to normal operation 58 Shop come 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 exten­ sion 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 ac­ tions, 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 set­ tings. We recommend just running the au­ tomatic “Calibrate” step. If the Emula­ tor’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 Set R(lo) (10kW) Actual value of 10kW resistor Default = 10000W Screen CON3, CON4 and the circular pads can all be used to connect to a circuit under test. For most of our prototyp­ ing, 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 oppo­ site shows the Emulator connected to our Advanced Test Tweezers. It probably won’t work with other cell holder types where the cell is insert­ ed from above. Since the PCB is only 1.6mm thick, it will not be a tight fit for holders that expect a 3.2mm-high CR2032 Practical Electronics | November | 2024 Coin Cell Emulator 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. cell, although many holders are de­ signed 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 56. 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 measured current. It is in a larger font as it is the most important pa­ rameter 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 re­ lates to IC2’s headroom). At 3V output, it will occur at around 130μA. The second-last line shows the stop­ watch 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 meas­ urements on the next line are also ac­ cumulating. The µAh reading on the last line measures actual charge consump­ tion (not adjusted). It can be used to validate the total current consump­ tion 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 cur­ rent 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 volt­ age 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 up­ stream 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 the emu­ lated cell is nearly flat. The fourth line (in larger text) shows 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 PE 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. Practical Electronics | November | 2024 59