-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathV_V_plot.py
More file actions
48 lines (35 loc) · 1.08 KB
/
Copy pathV_V_plot.py
File metadata and controls
48 lines (35 loc) · 1.08 KB
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
# V/V plotter DAC/ADC example.
import EasyMCP2221
from time import sleep
import matplotlib.pyplot as plt
# DAC output impedance is about 5k per step according to datasheet
# so measurements could be inaccurate as the current increases.
# Thus, we need GP1 to measure the actual DAC output.
mcp = EasyMCP2221.Device()
mcp.set_pin_function(
gp1 = "ADC", # monitoring DAC output
gp2 = "DAC", # DAC output
gp3 = "ADC") # device voltage
# Configure device pins ADC and DAC reference.
mcp.DAC_config() # set Vref = Vdd
mcp.ADC_config() # set Vref = Vdd
Vr = 32 * [0]
Vd = 32 * [0]
for step in range(0,32):
mcp.DAC_write(step)
#sleep(0.05) # settle time
(V1, _, V3) = mcp.ADC_read()
# 10 bit, 5V ref
Vr[step] = V1 / 1024 * 5
Vd[step] = V3 / 1024 * 5
print("Step: %2d of 32: Vr = %3.2fV, Vd = %3.2fV" %
(step+1, Vr[step], Vd[step]))
mcp.DAC_write(0)
plt.plot(Vr, Vd, 'o-')
plt.axline((1,1), slope=1, color='g', linestyle='dotted')
plt.axis([0,5,0,5])
plt.xlabel("Vr (V)")
plt.ylabel("Vd (V)")
plt.title("Simple curve tracer")
plt.grid()
plt.show()