-
Notifications
You must be signed in to change notification settings - Fork 0
/
example_diode_1N4007.py
117 lines (91 loc) · 2.78 KB
/
example_diode_1N4007.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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
# -*- coding: utf-8 -*-
"""
@author: simon burkhardt
@copyright (c) 2020 eta systems GmbH. All rights reserved.
@date 2020-08-02
@brief Example to trace and plot a diode 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.
"""
"""
1N4007
https://diotec.com/tl_files/diotec/files/pdf/datasheets/1n4001.pdf
https://www.diodes.com/assets/Datasheets/ds28002.pdf
If typ = 30 mA
Vf typ = 0.8 V
If max < 0.8 A
Vf max < 1.1 V
Ir max < 15 uA
Vr max < 1 kV
"""
#%%
import time
from sys import stderr
import serial
from curve_tracer import curvetracer
import le_tictoc as tt
import numpy as np
import matplotlib.pyplot as plt
#%%
# PARAMETERS
com = 'COM3'
baudrate = '115200'
VOLTS_MIN = -0.5
VOLTS_MAX = 0.64
CURR_MIN = -0.05
CURR_MAX = 0.05
N_POINTS = 100
N_OVERSAMPLE = 10
VOLTS_SWEEP = VOLTS_MAX - VOLTS_MIN
T_SETTLE = 0.010
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('*RST')
time.sleep(1.5)
tracer.close()
tracer = curvetracer(com, baudrate, log_level=1)
tracer.write(':SOUR:CURR:LIM ' + str(CURR_MAX)) # OCP
time.sleep(T_SETTLE)
tracer.write(':SOUR:VOLT:LIM ' + str(22.0)) # OVP
time.sleep(T_SETTLE)
tracer.write(':SOUR:VOLT:LEV ' + str(0.0)) # init 0V
time.sleep(T_SETTLE)
tracer.write(':CURR:RANG ' + str(0.005)) # 5mA Range
#%%
tt.tic()
for k in range(0, N_POINTS):
vset = round(VOLTS_MIN + (VOLTS_SWEEP / N_POINTS * k), 3) # round to mV
tracer.write(':SOUR:VOLT ' + str(vset))
time.sleep(T_SETTLE)
vread = 0.0
iread = 0.0
for i in range(N_OVERSAMPLE):
vread += float(tracer.request(':MEAS:VOLT?'))
time.sleep(T_SETTLE)
iread += float(tracer.request(':MEAS:CURR?'))
time.sleep(T_SETTLE)
vread /= float(N_OVERSAMPLE)
iread /= float(N_OVERSAMPLE) / 1000.0 # mA
val['source']['voltage'][k] = vread
val['source']['current'][k] = iread
tracer.write(':SOUR:VOLT:LEV ' + str(0.0))
tracer.close()
tt.toc()
#%%
# https://www.pythoninformer.com/python-libraries/matplotlib/line-plots/
# use r'$3.4 \Omega$' for Latex Math mode
plt.figure(figsize=(5,5))
#plt.plot(val['source']['voltage'][5:], val['source']['current'][5:], linewidth=2, marker='X')
plt.plot(val['source']['voltage'][5:], val['source']['current'][5:], linewidth=4)
plt.xlabel(r'$V_f$ [V]')
plt.ylabel(r'$I_f$ [mA]')
plt.title(r'current-voltage curve of a 1N4007 Diode')
plt.grid()
plt.savefig('1N4007_curve.pdf')
#%% close COM Port if exeption occurrs
tracer.close()