-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathCrudeESR.m
More file actions
76 lines (61 loc) · 1.94 KB
/
CrudeESR.m
File metadata and controls
76 lines (61 loc) · 1.94 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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
function CrudeESR(startFreq,stopFreq,points,dBm,dt)
LoadNIDAQmx;
global hCPS gSG;
fopen(gSG.serial);
NRead = 20;
dt=dt/NRead;
TimeOut = dt * NRead * 1.1;
Freq = 1/dt;
hCounter = SetCounter(NRead+1);
[~, hPulse] = DigPulseTrainCont(Freq,0.5,10000);
hCPS.hCounter = hCounter;
hCPS.hPulse = hPulse;
vec=startFreq:(stopFreq-startFreq)/(points-1):stopFreq;
for i=1:points
WriteSG(gSG.serial,1,vec(i),dBm);
status = DAQmxStartTask(hCounter); DAQmxErr(status);
status = DAQmxStartTask(hPulse); DAQmxErr(status);
DAQmxWaitUntilTaskDone(hCounter,TimeOut);
DAQmxStopTask(hPulse);
A = ReadCounter(hCounter,NRead+1);
DAQmxStopTask(hCounter);
A = diff(A);
f(i)=sum(A)/(NRead * dt);
end
DAQmxClearTask(hPulse);
DAQmxClearTask(hCounter);
%WriteSG(sg,stopFreq,dBm,0);
fclose(gSG.serial);
figure
plot(vec,f)
function task = SetCounter(N)
DAQmx_Val_Volts= 10348; % measure volts
DAQmx_Val_Rising = 10280; % Rising
DAQmx_Val_FiniteSamps = 10178; % Finite Samples
DAQmx_Val_CountUp = 10128; % Count Up
DAQmx_Val_CountDown = 10124; % Count Down
DAQmx_Val_GroupByChannel = 0; % Group per channel
DAQmx_Val_ContSamps =10123; % Continuous Samples
[ status, TaskName, task ] = DAQmxCreateTask([]);
if status,
disp(['NI: Create Counter Task :' num2str(status)]);
end
status = DAQmxCreateCICountEdgesChan(task,'Dev1/ctr0','',...
DAQmx_Val_Rising , 0, DAQmx_Val_CountUp);
if status,
disp(['NI: Create Counter :' num2str(status)]);
end
status = DAQmxCfgSampClkTiming(task,'/Dev1/PFI13',1.0,...
DAQmx_Val_Rising,DAQmx_Val_FiniteSamps ,N);
if status,
disp(['NI: Cofigure the Clk :' num2str(status)]);
end
function readArray = ReadCounter(task,N)
numSampsPerChan = N;
timeout = 0;
%readArray = libpointer('int64Ptr',zeros(1,N));
readArray = zeros(1,N);
arraySizeInSamps = N;
sampsPerChanRead = libpointer('int32Ptr',0);
[status, readArray]= DAQmxReadCounterF64(task, numSampsPerChan,...
timeout, readArray, arraySizeInSamps, sampsPerChanRead );