-
Notifications
You must be signed in to change notification settings - Fork 0
/
example_curve.py
77 lines (60 loc) · 1.87 KB
/
example_curve.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# -*- coding: utf-8 -*-
"""
@author: simon burkhardt
@copyright (c) 2020 eta systems GmbH. All rights reserved.
@date 2020-07-27
@brief Example to trace and plot a simple resistor curve with 100 data points
This Software is distributed WITHOUT ANY WARRANTY;
without even the implied warranty of MERCHANTABILITY
or FITNESS FOR A PARTICULAR PURPOSE.
"""
import time
from sys import stderr
import serial
from curve_tracer import curvetracer
import numpy as np
import matplotlib.pyplot as plt
#%%
# PARAMETERS
com = 'COM3'
baudrate = '115200'
VOLTS_MIN = 0.0
VOLTS_MAX = 3.0
CURR_MIN = -0.01
CURR_MAX = 0.006
N_POINTS = 100
VOLTS_SWEEP = VOLTS_MAX - VOLTS_MIN
T_SETTLE = 0.050
val = {}
val['source'] = {}
val['source']['voltage'] = np.zeros(N_POINTS)
val['source']['current'] = np.zeros(N_POINTS)
#%%
tracer = curvetracer(com, baudrate, log_level=1)
tracer.write(':SOUR:CURR:LIM ' + str(CURR_MAX))
time.sleep(T_SETTLE)
tracer.write(':SOUR:VOLT:LEV ' + str(VOLTS_MIN))
time.sleep(T_SETTLE)
tracer.write(':CURR:RANG ' + str(0.005))
time.sleep(T_SETTLE)
for k in range(0, N_POINTS):
vset = round(VOLTS_MIN + (VOLTS_SWEEP / N_POINTS * k), 3)
tracer.write(':SOUR:VOLT ' + str(vset))
time.sleep(T_SETTLE)
vread = float(tracer.request(':MEAS:VOLT?'))
time.sleep(T_SETTLE)
iread = float(tracer.request(':MEAS:CURR?'))
val['source']['voltage'][k] = vread
val['source']['current'][k] = iread
tracer.write(':SOUR:VOLT:LEV ' + str(VOLTS_MIN))
tracer.close()
#%%
# use r'$3.4 \Omega$' for Latex Math mode
plt.figure(figsize=(8,5))
plt.plot(val['source']['voltage'][10:], val['source']['current'][10:])
plt.xlabel(r'voltage [V]')
plt.ylabel(r'current [A]')
plt.title(r'current-voltage curve of a 1$k\Omega$ resistor')
plt.grid()
#%% close COM Port if exeption occurrs
tracer.close()