Friday, September 5, 2025

0

Automating Power Supply Measurements with PyVisa & Pytest

Summary:

In this post, I share my experience with the automation of professional electronics lab equipment, in particular power supplies and source measure units. 

Such equipment is valuable for testing power managment features of IoT products in R&D environment. Example tests include: (power consumption measurements, battery charging and runtime tests, DC-DC converter effeciency, etc)

To boost the experience of using such equipment, I created a small Python library to automate most of their functions. Therfore, manual testing effort is reduced. At the same time, more complex testing scenarios could be run where multiple instruments are controlled via Python. 

In additon, mesurements could be plotted and documented in a nice form using Python Matplotlib, Numpy libraries.

Hardware: 

I had access to the following two instruments:

Keysight U3606B: Combination of a 5.5 digit digital multimeter and 30-W power supply in a single unit
Keysight U2723A: Modular source measure unit (SMU) Four-quadrant operation (± 120 mA/± 20 V)

Both have USB programming access and support SCPI standard, which means they could directly be detected and used via PyVisa given their required VISA drivers are installed. 

Now knowing that such equipment can be expensive and difficult to obtain, you can still refer to my other expierment post where I use more cheaper / student freindly kits.  

 Software:

For automating the functions of  the above instruments, I used Python for its simplicity, wide adoption in the industry for automation and I can directly start using its PyVisa library to control the instruments.

The next step was to create wrapper classes that implement the control and measurement functions for the instruments and test them. For that, I looked for their SCPI programming manuals that list all supported commands by the interface and their syntax. 

So it was just a matter of going through the manuals to get the required SCPI commands / queries for a given instrument function and then sending it over to the instrument using PyVisa write and query functions.

The last step was to craete pytest-fixtures that could be used for testing. The fixtures simplify the instruments configuration (i.e. setup and tear down) in testing context. 

For example, a common workflow that could be implemented as a fixture is to connect to a target power supply at the beginning of a test session, configure its output mode (constant voltage or constant current), set the output value and enable its output. The same fixture could reset the power supply configuration to a default state and disable its output at the end of a testing session. Thus, making the testing experience with the power supply really neat.

The result of all this work is packaged in my small Python library: pypm-test which includes the wrappers to control the above instruments, pytest fixtures and most important usage examples / tests

Example Measurement: 

DC-DC Conversion Test:

A classical example application with a power supply and source measure unit is to evaluate the efficiency of DC-DC conversion for a given system (e.g. IoT product powered via Li-ion battery and having a low power MCU that requires 1.2 V supply). 
 
In such scenario the power supply and source mesure unit are connected to the respecitve voltage rails. The source measure unit is used as an electronic load to simulate constant current loads at the output, while the power supply is used to supply a sweep of varying input voltages.
 
So this example becomes a nice candiate parameteric study for automation to see how does the output power compares to the input power (i.e. effeciency) at different inputs voltges / sink currents.
 
P.S: I had additionally an Analog Discovery 3 scope to capture any voltage oscillations on the input and output that might be interesting. Checkout my pytest-analog python library if you are interested in automating your Analog Discovery functions.
 

 

You can view the code behind this test directly from my repo here . An example result which could be generated from such a test is shown below:
 

0 comments:

Post a Comment