Line Regulation Measurement Coding in Python

In the last two blogs, I have written about continual learning as an engineer; Learning Is Not Just for New Engineers and pulling an all-nighter, Pulling an All-Nighter made me think a little more about coding and writing scripts. These topics reminded me that I had not given many details on the Python coding I had done for the LDO measurements I discussed in my blog posts, Measuring LDO Line Regulation for a Novice and Measuring LDO Load Regulation for a Novice. If you recall, when I was discussing the continual learning an engineer must undertake, I had discussed a few different programming languages. I discussed how having some skills in coding can be useful to an engineer. In pulling that all-nighter, I had written some Python code to perform measurements during the testing I was performing at the time. Having the skill to do coding has proven useful many times for me over the course of my career. I am by no means an expert coder but, as the saying goes, I know enough to be dangerous. I would like to take a few moments to give folks some insight into some of the coding that I did when measuring LDO line regulation.

First let’s review the required equipment and test setup for measuring the line regulation of an LDO. The equipment is important because there are different software commands for different equipment. Before we can write a measurement script, we need to know the proper commands so that the equipment executes the required measurement. For the purposes of this test I used a Keithley 2230 DC source meter and a Keysight 34461A digital multimeter.

The Keithley is used to provide the DC input voltage for the regulator as well as provide the input current to the LDO. The Keysight digital multimeter is used to provide the measured output voltage from the LDO. The input current reading is not required for the line regulation measurement; however, it can be optionally added to monitor the current as an indicator of proper device operation. The current limit on the power supply should be set to provide a safeguard against drawing too much current. For the purposes of this measurement the current limit on the output of the Keithley DC source meter was set to about 5-10% above the maximum rated current of the LDO. This allows a little margin for any extra current in the setup and ensures that the output doesn’t current limit unnecessarily.

Recall that line regulation is the measurement of the output voltage variation when the input voltage is varied. When measuring the line regulation of the LDO we have a load resistance (RL ) installed such that there is maximum current draw from the LDO. Typically the line regulation of the LDO is specified at the maximum load current at it is the worst case condition for the output. The LDO will not be used without some load current drawn so it makes sense to measure at the maximum current.

Line Regulation Measurement Setup

Line Regulation Measurement Setup

The basic objective for the script is to vary the input voltage and monitor the output voltage. In order to better understand the Python script I have broken the code down into three main sections and a few subsections. The three main sections are: 1 – Library setup, 2 – Filename and variable setup, and 3 – Main function. The Main function section is further subdivided into three sections: A – Script checking, B – Loop to record values to a file, and C – Creates file header and writes file.

The first section of the program, Library setup, is where all the libraries required for the script are called. In this case there are some built-in Python libraries used as well as some internally generated ADI libraries. This is one of the great features of Python. Library functions can be created and then called by various Python scripts that one generates. In this case I am using some libraries that were generated to make communicating to equipment much easier via USB and GPIB. I should express my gratitude here for those who have more advanced coding skills and were able to create these libraries for folks like myself to use when generating their own code. In addition, I am using a library that enables me to be able to easily write to a CSV file to collect the data.

I have a few other libraries as well such as the MessageBox which allows me to display text in a message box pop up window wherever specified in the program. Notice in this case I have a line in the Script checking section commented out (the # symbol at the beginning of a line comments the ensuing code on that line). This was used during the debug of the code. Placing operations like this in the code helps during the debugging phase to see how far the code progresses before it runs into an error. Unless you are a super programmer with much better skill than I, then it is handy to have this tool as I have not been able to get a script to run without error on the first attempt.

Click here for larger image 

Python Script for Measuring LDO Line Regulation

Python Script for Measuring LDO Line Regulation

Python Script for Measuring LDO Line Regulation

The next section is the Filename and variable setup. In this section a filename is set and is where the output data from the script will be stored. In addition, variables are defined here that are used in the main function of the program. I have set up important information for the column labels in the file in this section. Notice I have a board number (to serialize data), the output being tested (useful if more than one output on a device), and a test condition. In my view, it is better to provide a lot of variables for description of the test being performed so that there are no questions later on regarding the specifics of the data.

In the Main function section of the script, the primary actions of the script are performed. In addition there is some script checking that was used during debug of the code. In this section the code is setting up the CSV file and defining the addresses of the Keithley DC source meter and the Keysight multimeter. In this section, a ‘for loop’ is defined to sweep the input DC voltage from the Keithley DC source meter across a range of voltages and to simultaneously measure the output voltage using the Keysight multimeter. The ‘for loop’ defines the range and the step size (increment) for the line regulation voltage sweep.

At the beginning of the main function, the Keithley DC source meter is enabled and at the end it is disabled. The main function also includes a section to create the header in the output CSV file so that the data columns are distinguishable. Once the program finishes execution, the compiler (Boa Constructor in this case) will alert the user that the program is complete. Optionally, the MessageBox library could be used to display a message box alerting the user that the program has executed.

I hope this has given a little insight into a simple, yet effective, Python script. Obviously programs and scripts could be much more complex, but I hoped this has shown how powerful just a small piece of code can be in a lab environment. As I have mentioned in my previous blogs, programming is an excellent tool to have in an engineer’s toolbox. Even the ability to generate short and simple scripts can make our daily tasks much easier and our time spent much more efficient. Stay tuned as we look next to the Python script used for the load regulation measurement.

0 comments on “Line Regulation Measurement Coding in Python

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.