| 1 |
# |
| 2 |
# This file is part of the PyMeasure package. |
| 3 |
# |
| 4 |
# Copyright (c) 2013-2023 PyMeasure Developers |
| 5 |
# |
| 6 |
# Permission is hereby granted, free of charge, to any person obtaining a copy |
| 7 |
# of this software and associated documentation files (the "Software"), to deal |
| 8 |
# in the Software without restriction, including without limitation the rights |
| 9 |
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
| 10 |
# copies of the Software, and to permit persons to whom the Software is |
| 11 |
# furnished to do so, subject to the following conditions: |
| 12 |
# |
| 13 |
# The above copyright notice and this permission notice shall be included in |
| 14 |
# all copies or substantial portions of the Software. |
| 15 |
# |
| 16 |
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 17 |
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 18 |
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 19 |
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 20 |
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 21 |
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
| 22 |
# THE SOFTWARE. |
| 23 |
# |
| 24 |
|
| 25 |
""" |
| 26 |
This example demonstrates how to make a graphical interface to preform |
| 27 |
IV characteristic measurements. There are a two items that need to be |
| 28 |
changed for your system: |
| 29 |
|
| 30 |
1) Correct the GPIB addresses in IVProcedure.startup for your instruments |
| 31 |
2) Correct the directory to save files in MainWindow.queue |
| 32 |
|
| 33 |
Run the program by changing to the directory containing this file and calling: |
| 34 |
|
| 35 |
python iv_keithley.py |
| 36 |
|
| 37 |
""" |
| 38 |
|
| 39 |
import logging |
| 40 |
import sys |
| 41 |
from time import sleep |
| 42 |
import numpy as np |
| 43 |
|
| 44 |
from pymeasure.instruments.keithley import Keithley2000, Keithley2400 |
| 45 |
from pymeasure.display.Qt import QtWidgets |
| 46 |
from pymeasure.display.windows import ManagedWindow |
| 47 |
from pymeasure.experiment import ( |
| 48 |
Procedure, FloatParameter, unique_filename, Results |
| 49 |
) |
| 50 |
|
| 51 |
log = logging.getLogger('') |
| 52 |
log.addHandler(logging.NullHandler()) |
| 53 |
|
| 54 |
|
| 55 |
class IVProcedure(Procedure): |
| 56 |
|
| 57 |
max_current = FloatParameter('Maximum Current', units='mA', default=10) |
| 58 |
min_current = FloatParameter('Minimum Current', units='mA', default=-10) |
| 59 |
current_step = FloatParameter('Current Step', units='mA', default=0.1) |
| 60 |
delay = FloatParameter('Delay Time', units='ms', default=20) |
| 61 |
voltage_range = FloatParameter('Voltage Range', units='V', default=10) |
| 62 |
|
| 63 |
DATA_COLUMNS = ['Current (A)', 'Voltage (V)', 'Resistance (Ohm)'] |
| 64 |
|
| 65 |
def startup(self): |
| 66 |
log.info("Setting up instruments") |
| 67 |
self.meter = Keithley2000("GPIB::25") |
| 68 |
self.meter.measure_voltage() |
| 69 |
self.meter.voltage_range = self.voltage_range |
| 70 |
self.meter.voltage_nplc = 1 # Integration constant to Medium |
| 71 |
|
| 72 |
self.source = Keithley2400("GPIB::1") |
| 73 |
self.source.apply_current() |
| 74 |
self.source.source_current_range = self.max_current * 1e-3 # A |
| 75 |
self.source.compliance_voltage = self.voltage_range |
| 76 |
self.source.enable_source() |
| 77 |
sleep(2) |
| 78 |
|
| 79 |
def execute(self): |
| 80 |
currents_up = np.arange(self.min_current, self.max_current, self.current_step) |
| 81 |
currents_down = np.arange(self.max_current, self.min_current, -self.current_step) |
| 82 |
currents = np.concatenate((currents_up, currents_down)) # Include the reverse |
| 83 |
currents *= 1e-3 # to mA from A |
| 84 |
steps = len(currents) |
| 85 |
|
| 86 |
log.info("Starting to sweep through current") |
| 87 |
for i, current in enumerate(currents): |
| 88 |
log.debug("Measuring current: %g mA" % current) |
| 89 |
|
| 90 |
self.source.source_current = current |
| 91 |
# Or use self.source.ramp_to_current(current, delay=0.1) |
| 92 |
sleep(self.delay * 1e-3) |
| 93 |
|
| 94 |
voltage = self.meter.voltage |
| 95 |
|
| 96 |
if abs(current) <= 1e-10: |
| 97 |
resistance = np.nan |
| 98 |
else: |
| 99 |
resistance = voltage / current |
| 100 |
data = { |
| 101 |
'Current (A)': current, |
| 102 |
'Voltage (V)': voltage, |
| 103 |
'Resistance (Ohm)': resistance |
| 104 |
} |
| 105 |
self.emit('results', data) |
| 106 |
self.emit('progress', 100. * i / steps) |
| 107 |
if self.should_stop(): |
| 108 |
log.warning("Catch stop command in procedure") |
| 109 |
break |
| 110 |
|
| 111 |
def shutdown(self): |
| 112 |
self.source.shutdown() |
| 113 |
log.info("Finished") |
| 114 |
|
| 115 |
|
| 116 |
class MainWindow(ManagedWindow): |
| 117 |
|
| 118 |
def __init__(self): |
| 119 |
super().__init__( |
| 120 |
procedure_class=IVProcedure, |
| 121 |
inputs=[ |
| 122 |
'max_current', 'min_current', 'current_step', |
| 123 |
'delay', 'voltage_range' |
| 124 |
], |
| 125 |
displays=[ |
| 126 |
'max_current', 'min_current', 'current_step', |
| 127 |
'delay', 'voltage_range' |
| 128 |
], |
| 129 |
x_axis='Current (A)', |
| 130 |
y_axis='Voltage (V)' |
| 131 |
) |
| 132 |
self.setWindowTitle('IV Measurement') |
| 133 |
|
| 134 |
def queue(self): |
| 135 |
directory = "./" # Change this to the desired directory |
| 136 |
filename = unique_filename(directory, prefix='IV') |
| 137 |
|
| 138 |
procedure = self.make_procedure() |
| 139 |
results = Results(procedure, filename) |
| 140 |
experiment = self.new_experiment(results) |
| 141 |
|
| 142 |
self.manager.queue(experiment) |
| 143 |
|
| 144 |
|
| 145 |
if __name__ == "__main__": |
| 146 |
app = QtWidgets.QApplication(sys.argv) |
| 147 |
window = MainWindow() |
| 148 |
window.show() |
| 149 |
sys.exit(app.exec()) |