This repository was archived by the owner on Jan 10, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathread_lockin.m
More file actions
56 lines (44 loc) · 1.27 KB
/
read_lockin.m
File metadata and controls
56 lines (44 loc) · 1.27 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
48
49
50
51
52
53
54
55
56
clear
instrreset
% Runtime parameters:
savefile = true;
label = '60sec_0.25dt_2BC_3000V_Efield';
runtime = 60; % seconds
dt = 0.25; % seconds
npts = runtime/dt;
lockin1 = gpib('ni', 0, 1);
lockin2 = gpib('ni', 0, 2);
fopen(lockin1);
fopen(lockin2);
V1vals = zeros(1, npts);
V2vals = zeros(1, npts);
timevals = zeros(1, npts);
starttime = now;
disp('Beginning intensity read...')
for i = drange(1:npts)
fprintf(lockin1,'outp? 3')
ans1 = fscanf(lockin1);
V1vals(i) = str2num(ans1);
fprintf(lockin2,'outp? 3')
ans2 = fscanf(lockin2);
V2vals(i) = str2num(ans2);
timevals(i) = (now - starttime)*86400;
subplot(1,1,1);
plot(timevals(1:i), V1vals(1:i), timevals(1:i), V2vals(1:i));
legend('Lockin 1', 'Lockin 2')
xlabel('Time');
ylabel('Voltage');
pause(dt - 0.1);
end
if savefile
path = 'C:\Users\314 Lab\Documents\Tom, Aayush, and Rebecca\data\';
filename = [path num2str(starttime-737456, '%2.4f') '_' label '.csv' ];
csvwrite(filename, transpose([timevals; V1vals; V2vals]));
disp(['Data saved to: ' filename])
end
fclose(lockin1);
delete(lockin1);
fclose(lockin2);
delete(lockin2);
disp(['Average 1:' num2str(mean(V1vals))])
disp(['Average 2:' num2str(mean(V2vals))])