-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdaqIO_VI.py
258 lines (202 loc) · 9.65 KB
/
daqIO_VI.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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
""" A set of experiments to measure current as a function of several applied voltages
These experiments all use the PCI-6259 DAQ and a current to voltage amplifier. """
from __future__ import division
import time, os, math
import msvcrt
import numpy as np
import matplotlib.pylab as plt
import matplotlib.animation as animation
import nidaqmx
import exptools.exptools as tools
from threading import Thread
class DAQIO_gateTest():
""" Uses the DAQ to put out a bias voltage then sweeps the
back gate starting and ending at zero while measuring current with
a current to voltage amplifier.
This should be the safest way to measure the resistance of CNT samples
at room temperature. """
def __init__(self):
""" This doesn't do much other than create the end_run variable. """
self.end_run = False
self.data = [0.0]
def run_simple(self, bias, samples = 1.0, gateDelay = 0.75, field = 0.0,
biasDivider = 1e-3, cvAmp = -1e-6, gateAmp = 9.1788,
filename = 'DAQIO_gateTest_{0:.0f}'.format(time.time())):
""" This runs the actual experiment. It can be called independently of the
run() function. """
tools.write_log('DAQIO_gateTest', locals(), filename+'.log.txt')
file = open(filename+'.dat.txt','a')
self.end_run = False
#setup output channels
bias_channel = 'Dev1/ao0'
bias_out = nidaqmx.AnalogOutputTask()
bias_out.create_voltage_channel(bias_channel, min_val = -10.0, max_val = 10.0)
gate_channel = 'Dev1/ao1'
gate_out = nidaqmx.AnalogOutputTask()
gate_out.create_voltage_channel(gate_channel, min_val = -10.0, max_val = 10.0)
gat = np.arange(0,10.1,0.1)
gates = np.append(gat, [gat[::-1], -gat, -gat[::-1]])
self.data = np.zeros((len(gates), samples+3))
sample_data = np.zeros((samples,1))
#setup input channel
input_channel = 'Dev1/ai0' #if using differential mode this should be the high side
sample_rate = 5000
itask = nidaqmx.AnalogInputTask()
itask.create_voltage_channel(input_channel, terminal = 'diff', min_val = -10.0, max_val = 10.0)
itask.configure_timing_sample_clock(rate = sample_rate, samples_per_channel = samples,
sample_mode = 'finite')
itask.alter_state('commit')
print 'bias turning on...'
bias_out.write(bias/biasDivider)
time.sleep(10.0)
#run experiment
exitGate = 0.0
print 'GO!'
for i, gate in enumerate(gates):
itask.start()
gate_out.write(gate/gateAmp)
time.sleep(gateDelay)
sample_data = itask.read()
itask.wait_until_done()
itask.stop()
self.data[i,0] = gate
self.data[i,1] = sample_data.mean()*cvAmp
self.data[i,2] = bias/self.data[i,1]
self.data[i,3:] = sample_data.transpose()
np.savetxt(file, [self.data[i]], fmt = '%+.6e', delimiter = '\t')
if (msvcrt.kbhit() and ord(msvcrt.getch()) == 113) or self.end_run:
exitGate = gate
print "Program ended by user."
break
bias_out.write(0.0)
bias_out.clear()
gate_out.write(0.0) #turn off gate, should already be at 0
gate_out.clear()
del gate_out, bias_out #delete DAQ object so it can be reused
file.close()
print 'Done.'
def run(self, *args, **kwargs):
""" This will run the animation as the main thread and start a
second thread for the measurement.
Takes all of the arguments and keyword arguments and passes them
to self.run_simple """
runArgs = args
runKwargs = kwargs
def update_current_gate(num, line, ax):
poin = np.count_nonzero(self.data[:,1])
line.set_data(self.data[0:poin,0], self.data[0:poin,1])
ax.set_xlim(np.amin(self.data[0:poin,0]), np.amax(self.data[0:poin,0]))
ax.set_ylim(np.amin(self.data[0:poin,1]),np.amax(self.data[0:poin,1]))
return line, ax
t = Thread(target = self.run_simple, args = runArgs, kwargs = runKwargs)
t.start()
time.sleep(5.0)
while np.count_nonzero(self.data[:,1]) < 3:
time.sleep(0.2) #wait for at least three points to plot
fig = plt.figure()
ax = fig.add_subplot(111)
ax.grid(True)
title_text = plt.title('bias = {0:+.2e}V'.format(args[0]))
line, = ax.plot([], [],'r-o')
plt.xlabel('gate (V)')
plt.ylabel('current (A)')
line_ani = animation.FuncAnimation(fig, update_current_gate, fargs=(line, ax),
interval=1000, blit=False)
plt.show()
self.end_run = True
class DAQIO_stabilityTest():
""" Uses the DAQ to put out a bias voltage then takes data at a few
back gate values while measuring current with
a current to voltage amplifier.
This should help in determining the problems with my gate setup. """
def __init__(self):
""" This doesn't do much other than create the end_run variable. """
self.end_run = False
self.data = 0.0
def run_simple(self, bias, gateDelay = 1.0, measDelay = 0.75,
field = 0.0, biasDivider = 1e-3, cvAmp = -1e-6, gateAmp = 9.1788,
filename = 'DAQIO_gateTest_{0:.0f}'.format(time.time())):
""" This runs the actual experiment. It can be called independently of the
run() function. """
tools.write_log('DAQIO_gateTest', locals(), filename+'.log.txt')
file = open(filename+'.dat.txt','a')
self.end_run = False
sample_rate = 1000
sample_average = 1000
sample_number = 25
#setup output channels
bias_channel = 'Dev1/ao0'
bias_out = nidaqmx.AnalogOutputTask()
bias_out.create_voltage_channel(bias_channel, min_val = -10.0, max_val = 10.0)
gate_channel = 'Dev1/ao1'
gate_out = nidaqmx.AnalogOutputTask()
gate_out.create_voltage_channel(gate_channel, min_val = -10.0, max_val = 10.0)
gates = [0.0, 1.0, 0.0, -1.0, 0.0]
# self.data = np.zeros((, ))
# sample_data = np.zeros((sample_average,1))
#setup input channel
input_channel = 'Dev1/ai0' #if using differential mode this should be the high side
itask = nidaqmx.AnalogInputTask()
itask.create_voltage_channel(input_channel, terminal = 'diff', min_val = -5.0, max_val = 5.0)
itask.configure_timing_sample_clock(rate = sample_rate, samples_per_channel = samples,
sample_mode = 'finite')
itask.alter_state('commit')
print 'bias turning on...'
bias_out.write(bias/biasDivider)
time.sleep(1.0)
#run experiment
exitGate = 0.0
print 'GO!'
for i, gate in enumerate(gates):
gate_out.write(gate/gateAmp)
time.sleep(gateDelay)
for j in range(25):
itask.start()
sample_data = itask.read()
itask.wait_until_done()
itask.stop()
self.data[i,0] = gate
self.data[i,1] = sample_data.mean()*cvAmp
self.data[i,2] = bias/self.data[i,1]
self.data[i,3:] = sample_data.transpose()
np.savetxt(file, [self.data[i]], fmt = '%+.6e', delimiter = '\t')
if (msvcrt.kbhit() and ord(msvcrt.getch()) == 113) or self.end_run:
exitGate = gate
print "Program ended by user."
break
bias_out.write(0.0)
bias_out.clear()
gate_out.write(0.0) #turn off gate, should already be at 0
gate_out.clear()
del gate_out, bias_out #delete DAQ object so it can be reused
file.close()
print 'Done.'
def run(self, *args, **kwargs):
""" This will run the animation as the main thread and start a
second thread for the measurement.
Takes all of the arguments and keyword arguments and passes them
to self.run_simple """
runArgs = args
runKwargs = kwargs
def update_current_gate(num, line, ax):
poin = np.count_nonzero(self.data[:,1])
line.set_data(self.data[0:poin,0], self.data[0:poin,1])
ax.set_xlim(np.amin(self.data[0:poin,0]), np.amax(self.data[0:poin,0]))
ax.set_ylim(np.amin(self.data[0:poin,1]),np.amax(self.data[0:poin,1]))
return line, ax
t = Thread(target = self.run_simple, args = runArgs, kwargs = runKwargs)
t.start()
time.sleep(4.0)
while np.count_nonzero(self.data[:,1]) < 3:
time.sleep(0.2) #wait for at least three points to plot
fig = plt.figure()
ax = fig.add_subplot(111)
ax.grid(True)
title_text = plt.title('bias = {0:+.2e}V'.format(args[0]))
line, = ax.plot([], [],'r-o')
plt.xlabel('gate (V)')
plt.ylabel('current (A)')
line_ani = animation.FuncAnimation(fig, update_current_gate, fargs=(line, ax),
interval=1000, blit=False)
plt.show()
self.end_run = True