Silicon ChipBattery Monitor Logger - February 2022 SILICON CHIP
  1. Outer Front Cover
  2. Contents
  3. Subscriptions: PE Subscription
  4. Subscriptions: PicoLog Cloud
  5. Back Issues: PICOLOG
  6. Publisher's Letter
  7. Feature: Should we be worried? by Mark Nelson
  8. Feature: Net Work by Alan Winstanley
  9. Project: Arduino-based Adjustable Power Supply by Tim Blythman
  10. Project: Battery Monitor Logger by TIM BLYTHMAN
  11. Project: ELECTRONIC Wind Chimes by John Clarke
  12. Project: Mini Digital AC Panel Meters by Jim Rowe
  13. Feature: KickStart by Mike Tooley
  14. Feature: Flowcode Graphical Programming by Martin Whitlock
  15. Feature: Max’s Cool Beans by Max the Magnificent
  16. Feature: AUDIO OUT by Jake Rothman
  17. Feature: Circuit Surgery by Ian Bell
  18. Feature: Make it with Micromite by Phil Boyce
  19. PCB Order Form
  20. Advertising Index

This is only a preview of the February 2022 issue of Practical Electronics.

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

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)
Off grid? On grid with battery backup? How do you monitor the state of your batteries? Battery Monitor Logger By TIM BLYTHMAN Knowing the condition of your batteries is essential for keeping them healthy longterm. A system that can monitor and log vital battery statistics is a great aid, and can help you to avoid having to shell out for expensive replacements. It can also be used for troubleshooting, such as when you don’t know which device is responsible for periodically discharging a battery. S olar and wind power is growing in use and getting cheaper, so there is a need to maintain batteries associated with such systems. You might also have a large battery in a shed, caravan, boat or another vehicle that you need to monitor. Backup batteries for mains power failures are another case where you might need a battery monitor or logger. Our new Battery Monitor Logger is versatile and capable, being able to handle a charger and two separate loads outof-the-box. It is based on a Micromite LCD BackPack, so can be reprogrammed in MMBasic, Micromite’s variant of the BASIC language. But as we have written software with many useful features, you don’t need to do any programming. New features Our design supports up to three shunts, so it can monitor three separate current paths, helping you to split out the charging or discharging figures across multiple loads and/ or generators. It even includes a fourth internal shunt for monitoring its own power usage. For example, you might have a solar panel array and a wind generator (or several) and want to keep track of the energy they generate separately. Or you might have several loads like a fridge, lights and a kettle and want to see which one is consuming the most energy. The design allows 100V at its input and the PIC32 we have used has plenty of storage space, so it can record more data for long periods. The battery voltage and currents are sampled at 10-second intervals. That data is averaged every hour to give up to two days of hourly samples. The hourly samples are also averaged over each day to give about a fortnight of daily values. 22 The flow of both charge and energy is logged, to provide capacity values in Ah (amp-hours) and Wh (watt-hours). You specify the full and empty voltages of your battery, plus the battery capacity, so that the unit can self-calibrate when the battery is either fully charged or discharged. A simple, linear voltage state-of-charge value is also calculated, giving a rough indication of battery state when the more accurate information is not available. Operating concept Fig.1(a) shows the simplest way to use the Battery Monitor Logger. The battery connects to a two-way screw terminal (CON3) while the positive ends of up to three loads or charging sources connect to the contacts of three-way screw terminal CON3a. The negative ends of those loads/charging sources connect directly to the battery negative (ground). This allows the Battery Monitor Logger to independently measure and display the current flowing to or from each load or charging source. It also produces a total current in/out figure and uses this to keep track of the battery’s state of charge in amp-hours (Ah). Multiplying this by the battery’s current voltage gives a nominal watt-hours (Wh) figure for the current state of charge. If you have more than three external devices to connect, they can share terminals on CON3a, as shown in Fig.1(b). For example, one terminal is shared by two loads (LOAD1 and LOAD2). The measurement on that channel will be the total load current for these two devices. Another terminal is shared by two charging sources (SOLAR and WIND), and likewise, their currents will be summed. The third terminal is shared by LOAD3 and a mains charger. In this Practical Electronics | February | 2022 case, the unit will measure the net current flow in/out – ie, it will see a flow into the battery if the charger current exceeds the current drawn by LOAD3, a flow out if the situation is reversed, and will measure zero if the two currents are equal (ie, the LOAD3 current is supplied by the charger). If you need to monitor currents over 10A, you can use the same arrangement except with external shunts. These will typically have a lower resistance and also can handle higher dissipation, both factors allowing greater currents to flow safely. For example, you can get 100A shunts quite easily, or even 500A shunts. Circuit design The circuit of the Battery Monitor Logger is shown in Fig.2. It has been designed as a complete Micromitecompatible board, rather than an add-on board for a Micromite LCD BackPack. This allows us to control its power usage better, reducing the current drawn from the battery. As with any batteryoperated device, it’s important to consider power consumption during the design phase. The battery and load/charger terminals are at lower right, with the bottom half of the right-hand page showing the sensing circuitry. Other external connections (USB, serial, programming etc) are arranged along the left-hand side, with the BackPack circuitry occupying most of the left-hand page, plus the display at centre-right. The unit’s power supply is across the top of both pages. The Micromite V2 BackPack (May 2018) is the closest BackPack variant to our design. This comparison is only for the sake of explaining some of our design choices; it is not important if you are coming to this circuit without knowing about the earlier designs. We’ve opted to use the 2.8in (7cm diagonal) LCD touchscreen in this design, rather than the 3.5in (9cm) version we’ve been using more recently (eg, in the V3 BackPack), as the smaller display uses slightly less power. The V3 BackPack also has many features which simply aren’t needed in this case, hence our choice of the V2 BackPack as the basis for this design. The main advantage it has compared to the original Micromite BackPack is the inbuilt USB-Serial interface. Battery sensing The main battery sensing circuitry centres on IC5 (an AD7192) and REF1 (a MAX6071). IC5 is a four-channel 24-bit ADC (analogue-to-digital converter) with an SPI serial interface. It is supplied from REG2’s 3.3V output, with its analogue rail filtered by a 10µH inductor. Each of its 3.3V supply pins is bypassed by a 100nF capacitor. IC5 shares the SPI bus with the LCD touchscreen, with IC1’s pin 24 used for the CS function, to indicate when IC5 is being addressed. IC5 needs a stable reference voltage to convert voltages into digital values, and this comes from REF1, a MAX6071 2.5V Practical Electronics | February | 2022 reference. It is a very low-noise and precise voltage reference chip, and it is supplied with 3.3V from REG2, with 100nF capacitors on its input and output. Its output supplies IC5’s REFIN1+ (pin 15), while IC5’s REFIN1− (pin 16) is tied to analogue ground. Each of the four analogue inputs to IC5 is fed by a 390kW/10kW divider, bypassed at the bottom by a 100µF capacitor. This means that the nominal full-scale reading is 100V with a resolution of around 6µV, and settling times of around ten seconds. We use the ADC to perform a conversion cycle (of all channels) about once every ten seconds, a slow rate needed to obtain maximum resolution. One of the dividers is connected directly across the battery at CON3. The other three monitor the voltage at the load/ charger end of the three shunts which connect between the BAT terminal of CON3 and the terminals of CON3A. By measuring the difference between the voltages fed to the ADC, we can determine the current flow into or out of each terminal. The PCB provides pads for 15mW shunt resistors which allow a theoretical resolution under 10mA. These are 3W Fig.1: three examples of how you could use the Battery Logger/Monitor. The simplest configuration, at top, uses its internal shunts to monitor the currents (up to 10A) into or out of three loads/charging sources. Or as shown in (B), you can connect more than three loads/charging sources, with some of them sharing shunts. For higher-current applications (up to hundreds of amps), external shunts can be used, as in (C). 23 parts, notionally allowing up to 14A to be sensed. In practice, the terminals limit this to around 10A. If larger external shunts are used instead, you just need to run low-current sensing wires from both their ends, back to CON3/CON3A. The shunt values can be set in the software to account for practically any resistance value. A local analogue ground net separates the analogue voltages from digital SPI signals. Supply current The current drawn by the circuit itself is modest but not insignificant, and needs to be accounted for to get accurate measurements. Since it is a fairly low current, we use a different technique to monitor it. Any current flowing into our circuit from the battery at CON3 flows out through a 100mW shunt resistor, generating a voltage below ground proportional to the current. IC6 is a single-channel op amp in a five-pin SOT23-5 SMD package. It is wired as an inverting amplifier with a gain of 100 (100kW/1kW), presenting a voltage to IC1’s pin 4 where the micro’s internal ADC can read it. The 100nF capacitor and 100kW resistor provide similar smoothing on this signal (a time constant of around ten seconds) so that it too can be sampled at similar intervals to the other channels. When the Battery Monitor Logger is operating, the LED backlight of the LCD panel consumes the most power, so l Battery Multi-logger SC Ó Fig.2: the circuit includes the equivalent of an entire Micromite V2 BackPack, a precision multi-channel ADC and a switchmode regulator capable of running the device from a DC supply between 6V and 100V. It monitors the battery voltage, the current to/from three external points and its own current consumption and logs all this (plus the current battery state-of-charge) to the internal Flash memory of microcontroller IC1. 24 Practical Electronics | February | 2022 a high PWM frequency is used to ensure that this measurement is accurate. Power supply There are two possible power sources in this circuit; USB socket CON5 can supply 5V, while the battery connection at CON3 handles up to 100V from the battery being monitored. (Several components on the board have a 100V maximum rating, so this is a hard limit and should not be exceeded.) A switchmode buck regulator chip, IC4 (LM5163) efficiently steps the battery voltage down to 5V. Its supply from the battery via CON3 is bypassed with a 2.2µF capacitor and fed into pins 2 (VIN) and 1 (GND). Practical Electronics | February | 2022 A voltage above 1.5V on pin 3 (EN) enables the regulator, which is equivalent to a voltage of around 5.5V at CON3 due to the 1MW/390kW resistive divider. Apart from accepting up to 100V at its input, IC4 also has an extremely low idle current of just 10.5µA with no load, and not much more at light loads. Its efficiency varies with the input voltage and load current, but is typically in the 75-90% range. See the panel below for more details on this handy little chip. It switches its pin 8 output (SW) alternately between VIN and GND using a pair of internal N-channel MOSFETs. The upper MOSFET has its gate voltage supplied from the 2.2nF capacitor on pin 7 (BOOST). 25 can cram more onto the PCB, and most of the other ICs are only available as SMDs anyway. In this case, its pins are relatively far apart (on a 1.27mm/0.05in • Battery voltage: 6-100V pitch) so it is not difficult to solder. • Current monitoring: up to three chargers or loads, To save power, the micro can switch 5V power monitored separately on and off to the touchscreen via the 14-way LCD • Current handling: limited only by the shunts used header. A high level on IC1’s pin 10 turns on N(10A with onboard shunts) channel MOSFET Q4, which is otherwise held off by a 10kW pull-down resistor. When Q4 is on, it pulls • Current resolution: 0.1% (10mA with onboard shunts) P-channel MOSFET Q3’s gate low, which allows 5V • Operating current: <1mA while logging (with display off) to flow from Q3’s source to drain and into the LCD • User interface: 2.8-inch colour touchscreen panel’s supply pin. • Firmware: Programmed in BASIC A similar arrangement, controlled by IC1’s pin • Data logging: can be viewed on device graphically, 26 via MOSFETs Q2 and Q1, switches power to the LCD panel’s LED backlight. Typically, a PWM or do nloaded as files signal is applied to pin 26, modulating the back• Measurements: current charge (Ah) and energy (Wh) light brightness. • State of charge: displayed based on voltage and charge. Unlike the Micromite BackPack V2, which had PWM brightness control, we have omitted the option of manual backlight control as the backlight is easily The pulses are smoothed by the 120µH inductor and a 22µF the biggest user of power in the circuit. So it needs to be capacitor to provide the output voltage. The voltage on feed- fully shut off during logging and monitoring. back pin 5 (FB) is internally compared to a 1.2V reference, so the 30kW/10kW divider sets the output voltage to 4.8V. Serial communications This is set to be slightly less than 5V so that if an alterna- IC1 sends display data and gets touch events back from the tive 5V supply is available, it takes over from the battery. touchscreen using an SPI serial bus on its pins 3, 14 and 25 Schottky diode D2 feeds the 4.8V into a pi filter formed of (MOSI, MISO and SCK). These connect to the LCD panel’s two further 10µF capacitors and a 10µH inductor. pin 6 and 12 (MOSI), pin 13 (MISO) and pins 7 and 10 (SCK). The 1nF capacitor across the 30kW resistor at the top of ‘MISO’ stands for ‘master in, slave out’ while ‘MOSI’ stands the FB divider helps with the stability of the circuit that for ‘master out, slave in’. drives the output pulses, by ensuring sufficient ripple at the The MISO line has a series 1kW resistor so that it can still FB pin for the circuit to operate correctly. See our panel for operate when the LCD panel is switched off. These signals, more detail on this. plus a chip select signal from IC1’s pin 9, also connect to the SD card header at the other end of the LCD panel PCB Microcontroller details via a four-pin header. This approximately 5V rail then feeds the Micromite section We had planned to use the SD card to store data, but Flash of the circuit. MCP1700-3.3 REG2 and its associated bypass memory limitations in the micro mean that there isn’t enough capacitors provide the 3.3V supply for microcontroller IC1. space to include the (rather large) libraries needed to do this. This is a 32-bit, 50MHz micro (PIC32MX170F256B) and is IC2 is an 8-bit PIC16F1455 microcontroller programmed surrounded by its own complement of bypass capacitors. with the Microbridge firmware. This allows it to act as a IC1 is programmed with the MMBasic firmware and USB-Serial bridge, and it can also be used to program the runs a BASIC program to implement the Battery Monitor PIC32 microcontroller. Logger functions. Pushbutton S1 is used to switch IC2 between USB-Serial While some Micromite BackPacks used the 28-pin DIP and programming modes, with LED1 flashing to indicate version of this IC, the Battery Monitor Logger uses the 28-pin that it is passing serial data, or lighting up solidly when in SMD (SOIC) part. It works identically but is smaller, so we programming mode. Features and specifications These photos show an earlier prototype, which was missing the MISO series resistor and CON6 (which is not used by the current version of the software). Some of the resistor and capacitor values are slightly different too, but overall it looks quite similar to the final version. Take note of the values shown on the silkscreen PCB overlay diagram during construction. 26 Practical Electronics | February | 2022 Screen1: The main screen provides all the critical statistics for your battery, as well as three simple menu options for accessing other features. The greyed values seen are capacity calculations which are not yet valid, as the Logger has not detected a complete charge and discharge cycle; they will light up brighter when that happens. Screen2: The Data screen provides a graphical view of the logged data. Different timespans can be shown, and the display will automatically scroll once a minute to show current data. The Weeks option provides around a fortnight of data. Data can also be dumped as CSV rows over the console serial port with the Export button. Mini USB Type-B socket CON5 is used both for USB communications (D+/D−) as well as optionally supplying 5V power. Schottky diode D1 feeds USB 5V to the Micromite 5V rail. Jumper JP1 provides the means to bypass D1 if needed. REG1 is identical to REG2 and supplies 3.3V to IC2 independently. Serial TX and RX signals are bridged to and from the virtual USB-Serial port by IC2. These connect between its pins 5 and 6, via 1kW resistors, to Micromite console pins 11 and 12 on IC1. IC2’s pins 2, 3 and 7 can be used to program IC1 via its ICSP interface; they are connected to IC1’s pins 4, 5 and 1 respectively. The PGD signal travels via JP2, which allows IC1’s pin 4 to be used as an analogue input when it is not being used for programming. Both IC1 and IC2 have their in-circuit serial programming (ICSP) pins broken out to the edge of the PCB at CON2 and CON1 respectively. This is a feature not seen on the other BackPacks, but we have included it here because the SMD ICs used here are more difficult to program out-of-circuit than through-hole (DIP) chips. A DS3231 real-time clock (IC3) provides accurate timekeeping over long periods. Its I2C serial bus pins 15 and 16 (SDA and SCL) connect to IC1 at pins 18 and 17, the I2C pins used by the Micromite firmware. Two 4.7kW resistors provide the pullups needed by the I2C protocol. DS3231 MEMS variant The DS3231 real-time clock IC has been the go-to choice for keeping track of time for the last five years or so. Its appeal is no doubt enhanced by the fact that it is available in an easy-to-use module typically sold as an rduino accessory Such a module was the subect of our first l heapo odules feature from anuary 2 1 , hich e used in several pro ects, typically in combination ith a icromite he module includes R and a cell holder I2 pullup resistors, an 2 The module simplifies connection as it includes all that is needed for the 2 1 chip to ork, but sometimes it’s too big. We used the bare DS3231 IC ( hich comes in a ide 1 -pin package) in our icromite ack ack ( ugust 2 2 ) and the l imer clock ( ugust 2 21) o support those pro ects, e kept a stock of those s ne day, e ere surprised to receive a package of small -pin parts instead of the ide 1 -pin s that e ere e pecting Had we been conned? o e had received the 2 1 variant instead hose familiar ith the 2 1 ill kno that it only uses eight of its pins the lo er pins are marked ( not connected ) he Practical Electronics | February | 2022 reason for the large package is not that it needs 16 pins, but because it includes a temperature-compensated crystal oscillator inside the plastic case, hich ould not fit inside an -pin package chip ut ith the advance of technology, the crystal oscillator inside the 2 1 has been superseded by a smaller device o given their small si e and decent performance, e decided to try them out in this pro ect We found the 2 1 to ork the same as the 2 1 he nominal accuracy is slightly orse at ppm compared to ppm, but for situations here si e is of concern, the smaller package is the overriding concern he part doesn t appear to suffer from crystal ageing either, hich means that in the longer term, it could be more accurate unless this is compensated for in the earlier version of the chip he backup battery current dra appears to be higher for the part in typical cases, but in most cases, the battery life ill still be close to its shelf life n this particular pro ect, e ve made allo ances for either part in the design, ith a dual footprint that suits both the ide 1 -pin part and the narro er -pin part We don t kno if the 2 1 ill end up more popular than the original 2 1, but e re ready for either eventuality 27 – Parts list – Battery Monitor Logger 1 double-sided PCB coded 11106201, measuring 86mm x 50mm, available from the PE PCB Service 1 2.8in LCD touch panel with ILI9341 controller 1 UB3 Jiffy box (optional, depending on desired mounting) 1 laser-cut acrylic panel to suit LCD and UB3 box 2 5-pin right-angle headers (CON1, CON2; both optional, for programming IC2 and IC1) 1 2-way 5/5.08mm-pitch screw terminal (CON3) 1 3-way 5/5.08mm-pitch screw terminal (CON3A) 2 2-pin headers (CON4 and JP1; both optional) 1 SMD mini-USB socket (CON5) 1 3-way pin header (CON6, serial port; optional) 1 3-pin header (JP2) 2 jumpers/shorting blocks (JP1,JP2) 1 SMD coin cell holder (BAT1) [BAT-HLD-001 – Digi-key, Mouser] 1 CR2032/CR2025 cell or similar (BAT1) 1 120µH 6mm x 6mm SMD inductor (L1) [eg, SRN6045TA-121M – Digi-Key, Mouser etc] 2 10µH 1206/3216-size SMD chip inductors (L2,L3) 1 SMD or through-hole 4-pin tactile pushbutton switch (S1) 1 14-pin header socket strip (for LCD) 1 4-way female socket strip (for LCD) 8 M3 x 6mm panhead machine screws 4 M3 x 12mm tapped spacers 4 M3 x 1mm untapped spacers (eg, stacks of 3mm ID washers) 3 heavy-duty current shunts [eg, Jaycar QP5415, Altronics Q0480 – optional, see text] hookup / heavy-duty wiring to suit shunts, batteries, load (see text) Semiconductors 1 PIC32MX170F256B-I/SO 32-bit microcontroller programmed with MMBasic or 11110620A.hex, SOIC-28 (IC1) 1 PIC16F1455-I/SL 8-bit microcontroller programmed with icrobridge firm are, SOIC-14 (IC2) 1 DS3231/DS3231M real-time clock IC, wide SOIC-16 or SOIC-8 (IC3) 1 LM5163DDAR synchronous buck regulator, SOIC-8 (IC4) 1 AD7192BRUZ 24-bit ADC, TSSOP-24 (IC5) 1 NCS325 CMOS op amp, SOT-23-5 (IC6) 1 MAX6071AAUT25+TT high-precision 2.5V reference, SOT23-6 (REF1) 2 MCP1700-3.3 low-dropout 3.3V regulators, SOT-23 (REG1,REG2) 2 IRLML2244TRPBF P-channel MOSFETs, SOT-23 (Q1,Q3) 2 2N7002 N-channel MOSFETs, SOT-23 (Q2,Q4) 1 3mm or SMD M3216/1206 LED (LED1) 2 SS14 (or equivalent) 40V 1A SMD schottky diodes, DO-214AC (D1,D2) Capacitors (all SMD M3216/1206 size) 4 100µF 6.3V X5R 1 22µF 16V X5R 7 10µF 50V X7R 1 2.2µF 100V X7R 10 100nF 50V X7R 1 2.2nF 50V C0G/NP0 1 1nF 50V C0G/NP0 Resistors (1% 21 /12 si e 1/ W metal film e cept where noted) 1 1MW (code 105 or 1004) 5 390kW (code 394 or 3903) 2 100kW (code 104 or 1003) 2 30kW (code 303of 3002) 8 10kW (code 103 or 1002) 2 4.7kW (code 472 or 4701) 8 1kW (code 102 or 1001) 1 0.1W (code R100 or 0R10) 3 15mW 1% 3W (M6331/2512 size; not needed if external current shunts are used) 28 The PCB is also fitted with a SOIC-8 footprint to allow the similar DS3231M (which uses a MEMS oscillator rather than a crystal) to be used instead. See the separate panel explaining the differences. Software operation Some of the following may seem obscure to those not familiar with MMBasic, but this information could come in handy if you want to change the code. MMBasic certainly makes driving the LCD (TFT) panel easy, as it performs startup initialisation and has builtin BASIC commands for drawing on and writing to the display. But it needs some help to work with our circuit arrangement, which starts with the LCD panel powered off, and therefore not ready to accept the initialisation commands that are automatically sent. So we need to add a routine (in the MM.STARTUP subroutine) to set pin 10 as an output and set it high, then re-run the LCD initialisation code. Every time we power up the display after shutting it down, we need to trigger that code. We also need to control the other lines that run to the LCD panel, as some of these idle high by default and would therefore waste power. MMBasic does not allow direct control of these, as the firmware reserves them to control the LCD panel, so we need to POKE directly to IC1’s registers and then run a command to reinitialise the LCD controller. Similarly, shutting down the controller requires direct POKEs to shut down those pins. No software deinitialisation is needed as the LCD can simply be powered down from any state. Despite this complication, it’s relatively easy to sense touches on the LCD panel even if it is shut down. This is necessary, as the user needs some way to wake the unit up if it is in a low-power state. Even when the LCD is powered off, the TIRQ pin (which is connected to IC1’s pin 15) is pulled to GND whenever the panel is touched. As the Micromite firmware provides a weak pullup on this pin, simply monitoring the state of this pin is sufficient to know if a touch has occurred. The main job of the MMBasic program is to read the battery voltage and the voltage across the three shunts to infer battery voltages and currents. It logs these to variables which are kept in RAM and they are regularly saved to internal Flash memory. With the circuit running from the battery it is monitoring, it would take a major fault to shut it down and lose the contents in RAM, so only longer-term samples are saved to Flash memory hourly. If the unit needs to be disconnected to work on the battery, at most one hour of data will be lost. When saving to Flash, the data is averaged over a period before being archived. This means that less data needs to be stored, but a good amount of data can be kept for historical purposes. For example, you might like to compare how much power your solar panels are putting into your battery over a period of a few weeks. Data about current and power usage is also used to calculate parameters such as battery capacity and state of charge. The MMBasic program also provides a user interface to allow settings to be changed and values to be graphed and viewed. Plus there is the option to dump the data over a serial port so that it can be exported to a PC program for graphing and analysis. We’ll delve further into the software operation during the setup procedure in Part 2 next month. Practical Electronics | February | 2022 The LM5163 switchmode regulator IC Our initial design plans for the Battery Logger set the ambitious target of designing it to work at up to 80V, improving on the 60V limit of an older design. That one used an LM2574HV integrated s itchmode operating at a fi ed fre uency of k , re uiring a si eable toroidal inductor and electrolytic capacitor Hoping that that state of the art had progressed in the last decade, we decided to look for newer parts. We found plenty of parts capable of working with a 100V supply, which is impressive. 1 s itching fre uencies are no longer uncommon his much higher s itching fre uency means that a smaller inductor and capacitors are needed, helping us to keep our board compact. Many parts we found could only deliver 100mA. While this might have been sufficient ith careful control of the backlighting, we wanted more headroom. The LM5163 came in as the cheapest part capable of more than 100mA (500mA) in an easily-soldered - package, hich is a good compromise bet een si e and ease of handling. As is typical of modern buck regulator designs, it is a synchronous type, meaning it has two internal switches. The incoming voltage is switched to the inductor by a high-side internal MOSFET. When the MOSFET is off, a second, low-side MOSFET is switched on to provide a path for the inductor current to circulate. This removes the need for an e ternal diode to serve this role and increases its efficiency The LM5163 is a COT (constant on-time) design; the time that the high-side is s itched on is set by an e ternal resistor, after which it is switched off. The feedback pin monitors the output voltage, and when the output voltage has decayed, another on-cycle begins. So the duty cycle is modulated to maintain the desired output voltage, but the constant on-time means that the s itching fre uency varies, although it can be predicted. When e built our first prototype, everything orked as e pected e ere truly impressed ith ho e ible and easy-to-use this tiny part as ut then, it started s uealing he tone ould change ith load ( hich e could easily modulate by ad usting the backlight intensity) and input voltage. It was bad enough, especially around 12V, that we needed to do something about it. The cause was electrical noise, which was affecting when it would switch on. It might switch on early, which causes the output voltage to rise his ill cause the ne t s itch-on to be delayed, as the controller will be waiting for the output voltage to drop below its threshold. The output pulses start to cluster into bursts, and it is these clusters that occur at audible fre uencies, causing the high-pitched s uealing e ere hearing ( subharmonic oscillation ) see belo s e found ith our itchmode replacement ( ugust 2021), trying to get these sort of parts to operate optimally over a ide range of input voltages can be tricky n that case, e tra output capacitance helped. Fortunately, a section of the LM5163 data sheet (reproduced in Fig.4) describes methods to avoid this. The aim is to increase the ripple seen by the FB pin, so that the regulator has a clearly defined time to s itch on, despite the presence of noise. We tried the Type 1 method, which involves adding series resistance to the output capacitor. The e tra resistance means that the voltage seen at the pin is in uenced less by the capacitor and more by the pulses from the inductor. But it also means that the output capacitor is less effective at filtering the output voltage, and e found it did little to reduce the s uealing So we tried part of the Type 2 method (omitting the series resistor from ype 1) and simply added the feedfor ard capacitor in parallel with the top feedback divider resistor. This means that the FB pin sees the full amplitude of the output ripple voltage, as it is coupled directly by the capacitor rather than being simply divided by the resistor chain. his effectively uadruples the ripple seen by the pin ith our 30kW/10kW divider, ithout degrading filtering hat eliminated the s uealing, so e have kept it in our final design Any switching device which depends on a feedback voltage from a divider to s itch its output elements can benefit from having a feedfor ard capacitor t depends on the fre uency of operation, capacitor value and divider ratio, though. A word of caution: while this capacitor may appear to be a cure-all, it does have the side-effect of slowing down response to transients as it reduces the closed-loop gain for higher fre uency components Fig.4: Texas Instruments’ recommended solutions for subharmonic oscillation or ‘squegging’ in the LM5163. We tried Type 1, and it didn’t work, but Type 2 did. It only requires the addition of a low-value feedforward capacitor, Cff, across the upper half of the feedback divider. Type 3 is similar but adds another pole for improved transient response; that’s overkill in our application. Fig.3: usually, low ESR is considered desirable in a capacitor as it gives superior filtering, but when it filters out the ripple too effectively, it affects the regulator’s ability to produce pulses regularly. Next month The second and final part of this feature will have the complete PCB assembly details, microcontroller programming procedures, setup and operation instructions, calibration information along with the final construction procedure. Practical Electronics | February | 2022 Reproduced by arrangement with SILICON CHIP magazine 2022. www.siliconchip.com.au 29