Table of Contents
Introduction
This blog post shows how I went about adding programmability to an old power supply! More generally, there is plenty of old equipment out there, some with no control/monitoring interfaces, and some with ancient or proprietary protocols running over (say) RS-232 or perhaps RS-485 connections.
In the test equipment world, there is a popular (and fairly easy-to-understand) protocol called SCPI, and it can be run over a USB protocol called USBTMC. If you’re intending to use equipment in a lab, then SCPI is a great protocol to use (whether it is over USB, or Ethernet, or RS-232), because of the compatibility with various test orchestration software. You can then control/operate and monitor the equipment with (say) NI LabView, or MATLAB, or Python.
If legacy equipment does not support SCPI or USBTMC, then it may still be possible to add USB to it and create the functionality. This blog post discusses the steps involved.
What’s the Problem being Solved?
I purchased an old manually-adjustable power supply from ebay. Unfortunately, it came with no computer interface for setting and monitoring the voltage and current. Without such an interface, it would be very tedious to run tests that required the voltage to be adjusted in steps repeatedly for instance.
An RS-232 interface was an optional extra that could have been purchased back in the early 1990’s! However, Jan Cumps managed to locate the PDF service manual for the power supply, and it was discovered that it would be very straightforward to retrofit it, simply by adding a couple of optocouplers and a serial DB-9 connector. The power supply firmware can be made aware that the interface exists, by holding down some buttons at power-up. This was all great, however the protocol was proprietary, running over a 2.4 kbps connection. Furthermore, I don’t have a PC with an RS-232 interface. It would be far better if the power supply could be modified to incorporate a USB socket supporting SCPI!
What’s Inside?
The photo below shows the legacy power supply internals. The design looks very early 1990’s : ) I was impressed that quite a lot of attention has been paid by the designers, to reduce noise. It’s a linear supply, with two adjustable channels, and a third fixed 5V channel. As well as the input mains filter and really nice low-capacitance (between primary and secondary windings) transformer, the outputs have an LC filter attached (not visible).
The optional RS232 interface fits in the gap visible near to the power entry/fuse area, if the partially-punched metal is knocked out.
The photo below shows the PROM chip (I dumped out the firmware, if anyone wants to disassemble it!), and to the left of it, is a 3-pin socket where the optional RS232 interface board would connect.
It’s a pretty ancient power supply; it has a very basic user interface, quite confusing to read since everything needs to fit the 16x2 LCD screen. SCPI capability would be highly desirable to simplify usage of this supply!
Solution Overview
About a year ago, Jan Cumps Jan Cumps developed software called the Pico SCPI labTool, or PST for short. The software, which runs on a tiny Pi Pico microcontroller board, implements USBTMC SCPI functionality. By default, it accepts commands to turn on/off some spare GPIO pins on the Pi Pico. It can also be used to take analog measurements from the ADC pins on the Pi Pico.
The PST software can be easily added to, to create new SCPI functionality. What I would need to do, is to implement a software adapter to convert between SCPI commands and the legacy commands that the power supply unit supports.
In terms of hardware, I would need to connect up the Pi Pico to the legacy power supply, using a similar optocoupler scheme as the RS-232 adapter board would have used, if it had been installed. In other words, as far as the legacy power supply is concerned, the new hardware looks just like if the RS232 interface were fitted.
The legacy power supply accepts RS232 commands such as VSET and ISET in order to set the voltage or current. However modern SCPI-capable power supplies accept commands such as SOURCE:VOLTAGE:LEVEL or SOURCE:CURRENT:LEVEL. The firmware running on the Pi Pico will interwork between the SCPI world and the commands that the legacy power supply supports.
That’s it! This project is nice and simple.
Circuit Diagram
The service manual was examined to see how the RS232 interface worked. As can be seen, the UART signals, called RXD and TXD originate at the 8051-compatible microcontroller, and, through inverter buffers (more on that later!) become signals called RXDD and TXDD, and they attach via optocouplers to the DB-9 connector that would ordinarily connect to a PC with RS232 interface. The signal flow is shown in orange for the transmit, and green for receive (from the legacy equipment perspective).
The optocoupler circuitry and the DB-9 connector were not present. A partially-punched hole at the rear of the equipment is where the DB-9 connector and (presumably) a small circuit board would connect if the RS232 interface was purchased and installed.
For the new module, similar optocoupler circuitry was used and was attached to the Pi Pico. The USB connector on the Pi Pico is quite small, so a larger Type B USB socket was soldered.
Building It
I didn’t create a printed circuit board for this project. You can see the optocouplers and the Pi Pico in the photo below. The three wires at the top-left go to the 3-pin connector that was mentioned earlier, on the legacy equipment.
I didn’t want to have to keep opening up the equipment each time there is a firmware change on the Pi Pico, so I added a BOOTSEL (boot select) button next to the USB socket. It is flush, and not easy to accidentally press, but can be pushed in with fingernails when connecting the USB socket to the PC, in order to get the Pico into the boot mode.
This project was easy to assemble with point-to-point wiring on perfboard:
I took a gamble and installed it without testing it first! Anyway, it worked out.
It looks weird seeing a modern QFN-package microcontroller inside the ancient equipment.
Software
There is a ton of documentation on the Pico SCPI labTool, and many code examples.
I mostly followed the example described at the following link, skipping immediately to the section titled Implementing the ADC Functionality, changing the code as I went, to implement a 2400 baud UART instead of an ADC: Creating a Pi Pico based High-Resolution Measurement Instrument
I’m happy to explain any of my work if required, but it’s very self-explanatory; the code is almost entirely in a single file called psu_utils.c (and associated psu_utils.h header file). Everything else relies on Jan’s code. By looking at the psu_utils source and header files, it is easy to see how the SCPI commands invoke UART messages to perform the interworking between the SCPI world and the legacy power supply.
Testing It
Initially, it didn't work! After some thinking, the root cause was easily spotted (maybe you've already seen the issue if you saw the circuit diagrams!). I often forget that RS232 voltage levels are not only different, but are inverted, i.e. logic '1' is not a positive voltage and logic '0' is not a negative voltage. That was why the inverters were present in the original circuit. By inserting my module where the RS232 board went, the logic levels were inverted for me. I didn't want to now modify the module and add inverters! Fortunately, the solution was extremely simple. The Pi Pico C SDK offers the capability to automatically invert signals! Once I added that bit of configuration into the pin setup code, and re-uploaded the firmware into the Pico, all was well and I could begin testing the SCPI commands.
If you have NI VISA installed, then there is a simple tool called NI-VISA Interactive Control, where you can directly type SCPI commands and see the results. I used a very similar tool called Tektronix OpenChoice Talker Listener, since that was already installed on the PC.
I was able to issue voltage and current setting commands such as the ones shown below, and see the power supply update it’s LCD screen! I measured the voltage using a multimeter. The explanation of these SCPI commands would be in any typical modern power supply programming manual (I copied them from a BK Precision PSU programming manual).
SOUR1:VOLT:LEV:IMM:AMP 1.4
SOUR1:CURR:LEV:IMM:AMP 0.3
The full expansion for setting the voltage on channel 1 to (say) 2.34V is:
SOURCE1:VOLTAGE:LEVEL:IMMEDIATE:AMPLITUDE 2.34
The power supply can also report the current measured voltage and current values, and the SCPI commands implemented to do that are shown here:
SOUR1:VOLT:LEV:IMM:AMP?
SOUR1:CURR:LEV:IMM:AMP?
The power supply channels can be switched on/off with the following SCPI command (the value 1 or 0 at the end sets the channel on or off respectively:
SOUR1:OUTP:STAT 1
Summary
The Pi Pico, running the Pico SCPI labTool software, can extend the life of equipment, and also save costs! I saved quite a bit of money by buying a cheaper power supply and then adding the interface.
If you're interested in converting equipment to incorporate the SCPI functionality with PST, there are plenty of code examples out there, and it’s very easy to modify the code to incorporate the desired SCPI functionality.
Thanks for reading.