-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathV_T_plot_C.py
61 lines (43 loc) · 1.11 KB
/
V_T_plot_C.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
# Plotter for capacitor change/discharge
import EasyMCP2221
import time
import math
import matplotlib.pyplot as plt
import matplotlib.ticker as mtick
import numpy as np
capture_time = 1
# Configure device pins
mcp = EasyMCP2221.Device()
mcp.set_pin_function(
gp2 = "GPIO_OUT",
gp3 = "ADC")
mcp.ADC_config()
V = []
T = []
print("Discharging...")
mcp.GPIO_write(gp2 = False)
while mcp.ADC_read()[2] / 1024:
pass
print("Charging...")
mcp.GPIO_write(gp2 = True)
start = time.perf_counter()
while time.perf_counter() - start <= capture_time:
t = time.perf_counter()
Vc = mcp.ADC_read()[2]
# 10 bit
Vc = Vc / 1024 * 100
T.append(t - start)
V.append(Vc)
mcp.GPIO_write(gp2 = False)
plt.plot(T, V, 'o-')
plt.axis([-0.05, capture_time, 0, 105])
plt.gca().yaxis.set_major_formatter(mtick.PercentFormatter())
plt.gca().xaxis.set_major_locator(mtick.MultipleLocator(0.1))
#plt.xticks(np.arange(0,capture_time,0.1))
plt.xlabel("Time (s)")
plt.ylabel("V (%)")
plt.title("Capacitor charge plot")
# 1st RC line
plt.axhline(y = 100 * (1-1/math.e) , color='g', linestyle='dotted')
plt.grid()
plt.show()