Python script to measure DC-DC converters - Page 1
Forum section: electronics / testgear

author: tszaboo
author_rank: Super Contributor
timestamp: July 20, 2024, 11:35:47 am
content: I've made a python script to measure DC-DC converters.It measures the efficiency across input voltage and load currentAnd shows the load dependency of the output voltage.I've included an example output of a very simple 7812 based power supply.Code is below. Uses python, finds the VISA connected instruments.Uses a Rigol DP832 Power supply and a Siglent SDL1020 in my case.Warning: The code will totally blow up your DUT if you don't configure it correctly.I suggest manually setting up the Overvoltage and Overcurrent conditions on both your instruments before starting.

author: tszaboo
author_rank: Super Contributor
timestamp: July 20, 2024, 11:38:56 am
content: It was running using jupyter notebook, but there is no reason why it wouldn't work from regular python console.Code:import pyvisaimport numpy as npimport itertoolsimport timeimport csvimport pandas as pdimport matplotlib.pyplot as pltimport datetimerm = pyvisa.ResourceManager()[print(x) for x in rm.list_resources()];#use instrument names OR serial numbers#Power supply settingsPSU_NAME = "DP832"VIN_NUMBER_OF_SAMPLES = 20VIN_MIN = 15VIN_MAX = 22IIN_MAX = 1#DC load settingsDC_LOAD_NAME = "SDL1020"IOUT_NUMBER_OF_SAMPLES = 20IOUT_MIN = 0.01IOUT_MAX = 0.3DELAY = 0.5CSV_FILE = 'measurements.csv'EFFICIENCY_IMAGE = 'Efficiency.png'VOLTAGE_IMAGE = 'Output.png'#Creating measurement parametersVIN = np.linspace (VIN_MIN,VIN_MAX,VIN_NUMBER_OF_SAMPLES)IOUT = np.linspace (IOUT_MIN,IOUT_MAX,IOUT_NUMBER_OF_SAMPLES)N= len(list(itertools.product(VIN,IOUT)))print (f"Taking {N} measurements")print (f"Expected time: {N*(DELAY+2)} seconds")#Connecting to instruments# Example usage:#instrument_identifier = "DP832" # Or any other identifierdef find_instrument(instrument_identifier,rm):instruments = rm.list_resources()for instrument_name in instruments:try:instrument = rm.open_resource(instrument_name)idn = instrument.query("*IDN?")if instrument_identifier in idn:print("Instrument found:")print(idn)return instrumentelse:instrument.close()except:passreturn NonePSU = find_instrument(PSU_NAME,rm)DCL = find_instrument(DC_LOAD_NAME,rm)def measure_point(vin, iin, iout):PSU.write(f"APPL CH1,{vin},{iin}")#if PSU.query(":OUTPut:STATe? CH1").find("ON") == -1:# PSU.write(":OUTPut:STATe CH1,ON")DCL.write(f":SOURce:CURRent:LEVel:IMMediate {iout}")#if DCL.query(":SOURce:INPut?").find("ON") == -1:# DCL.write(":SOURce:INPut ON")time.sleep(DELAY)a= PSU.query(":MEASure:CURRent:DC? CH1", 0.1)b= PSU.query(":MEASure:VOLTage:DC? CH1", 0.1)c= DCL.query(":MEASure:CURRent:DC?", 0.1)d= DCL.query(":MEASure:VOLTage:DC?", 0.1)a = float(a.strip())b = float(b.strip())c = float(c.strip())d = float(d.strip())#print ((a,b,c,d))print(".", end="")try:eff = (c*d)/(a*b)*100except ZeroDivisionError:eff = 0return vin,iout,eff,a,b,c,dvin,iout = next(itertools.product(VIN, IOUT))measure_point(vin,IIN_MAX,iout)PSU.write(":OUTPut:STATe CH1,ON")DCL.write(":SOURce:INPut ON")with open(CSV_FILE,'w', newline='') as csvfile:print (datetime.datetime.now())headerList = ['VIN','IOUT','EFF', 'CIN', 'VIN_A', 'IOUT_A','VOUT']writer = csv.writer(csvfile, delimiter=',')writer.writerow(headerList)for vin,iout in itertools.product(VIN,IOUT):#print (vin,iout)m = measure_point(vin,IIN_MAX,iout)writer.writerow(m)#Turn off outputPSU.write("OUTP CH1,OFF")DCL.write(":SOURce:INPut OFF")#BeepPSU.write(":SYSTem:BEEPer:IMMediate")time.sleep(0.5)PSU.write(":SYSTem:BEEPer:IMMediate")time.sleep(0.5)PSU.write(":SYSTem:BEEPer:IMMediate")print (datetime.datetime.now())print ("Measurements done")df = pd.read_csv(CSV_FILE)dfplt.tricontourf(df['VIN'], df['IOUT'], df['EFF'], cmap='seismic',levels=30)plt.xlabel('Input voltage')plt.ylabel('Output current')plt.colorbar(label='Efficiency')plt.savefig(EFFICIENCY_IMAGE) # Save the plotplt.show()plt.tricontourf(df['VIN'], df['IOUT'], df['VOUT'], cmap='viridis',levels=30)plt.xlabel('Input voltage')plt.ylabel('Output current')plt.colorbar(label='Output voltage')plt.savefig(VOLTAGE_IMAGE) # Save the plotplt.show()