14
14
% Rob Campbell - Basel 2015
15
15
16
16
17
+ % Define a cleanup object that will release the DAQ gracefully
18
+ tidyUp = onCleanup(@stopAcq );
19
+
20
+
17
21
% ----------------------------------
18
22
% User settings
19
23
amp= 2 ; % Scanner amplitude
24
28
% ----------------------------------
25
29
26
30
27
- % Define a cleanup object in case the user does a ctrl-c and we end up with the
28
- % stages having peculiar speed settings, etc
29
- tidyUp = onCleanup(@stopAcq );
31
+ % - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
32
+ % CONNECT TO THE HARDWARE
30
33
31
34
% Create a session using NI hardware
32
35
s= daq .createSession(' ni' );
33
36
34
37
35
- % Add an analog input channel
38
+ % Add an analog input channel for the PMT signal
36
39
AI= s .addAnalogInputChannel(' Dev1' , ' ai1' , ' Voltage' ); % Hard-coded. This is a PCI 6115
37
40
AI.Range = [-2 ,2 ];
38
41
39
42
40
43
% Add a listener to get data back from this channel
41
44
addlistener(s ,' DataAvailable' , @plotData );
42
45
43
- % Add analog output channels for scanners 0 is x and 1 is y
46
+
47
+ % Add analog two output channels for scanners 0 is x and 1 is y
44
48
s .addAnalogOutputChannel(' Dev1' ,0 : 1 ,' Voltage' ); % the 6115 is assigned to Dev1
45
49
46
50
47
- % Calculate the number of samples per line
48
- samplesPerLine = pointsPerLine * samplesPerPoint ;
49
51
50
- yWaveform = linspace(amp ,-amp ,samplesPerLine * linesPerFrame );
51
52
52
53
53
- % The output buffer is re-filled for the next line when it becomes half empty
54
- s.NotifyWhenScansQueuedBelow = round(length( yWaveform )* 0.5 );
54
+ % - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
55
+ % BUILD THE GALVO WAVEFORMS
55
56
57
+ % Calculate the number of samples per line
58
+ samplesPerLine = pointsPerLine * samplesPerPoint ;
56
59
57
- % The sample rate is fixed, so we report the frame rate
58
- s.Rate = sampleRate ;
59
- frameRate = length(yWaveform )/sampleRate ;
60
- fprintf(' Scanning at %0.2f frames per second\n ' ,1 / frameRate )
60
+ % So the Y waveform is:
61
+ yWaveform = linspace(amp ,-amp ,samplesPerLine * linesPerFrame );
61
62
62
63
% Produce the X waveform
63
64
xWaveform = linspace(-amp , amp , samplesPerLine )*1 ;
64
65
xWaveform = repmat(xWaveform ,1 ,length(yWaveform )/length(xWaveform ));
65
66
66
-
67
67
% Assemble the two waveforms into an N-by-2 array
68
68
dataToPlay = [xWaveform(: ),yWaveform(: )];
69
69
fprintf(' Data waveforms have length %d\n ' ,size(dataToPlay ,1 ))
70
70
71
71
72
- % Plot the waveforms
73
- hFig= clf ;
74
- plot(dataToPlay )
75
- drawnow
76
-
77
72
78
- % This listener tops up the output buffer
79
- addlistener(s ,' DataRequired' , @(src ,event ) src .queueOutputData(dataToPlay )); % add listener on the DataRequired event to top it up
80
73
74
+ % - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
75
+ % PREPARE TO ACQUIRE
76
+
77
+ % The sample rate is fixed, so we report the frame rate
78
+ s.Rate = sampleRate ;
79
+ frameRate = length(yWaveform )/sampleRate ;
80
+ fprintf(' Scanning at %0.2f frames per second\n ' ,1 / frameRate )
81
+
82
+ % The output buffer is re-filled for the next line when it becomes half empty
83
+ s.NotifyWhenScansQueuedBelow = round(length(yWaveform )*0.5 );
84
+
85
+ % This listener tops up the output buffer
86
+ addlistener(s ,' DataRequired' , @(src ,event ) src .queueOutputData(dataToPlay ));
81
87
82
88
s.IsContinuous = true ; % needed to provide continuous behavior
83
89
s .queueOutputData(dataToPlay ); % queue the first frame
86
92
s.NotifyWhenDataAvailableExceeds= size(dataToPlay ,1 ); % when to read back
87
93
88
94
95
+
96
+
97
+ % - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
98
+ % SET UP THE FIGURE WINDOW THAT WILL DISPLAY THE DATA
99
+
89
100
% We will plot the data on screen as they come in, so make a blank image
90
- clf( hFig ) ;
101
+ hFig= clf ;
91
102
histAx= subplot(1 ,2 ,1 );
92
103
93
104
imAx= subplot(1 ,2 ,2 );
94
105
hAx= imagesc(zeros(linesPerFrame ,pointsPerLine ));
95
106
colormap gray
96
107
97
- s .startBackground % start the acquisition in the background
98
108
99
- % Block. User presses ctrl-C to to quit, this calls stopAcq
100
- while 1 ,pause(0.1 ), end
101
109
102
110
111
+ % - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
112
+ % START!
113
+ s .startBackground % start the acquisition in the background
103
114
115
+ % Block. User presses ctrl-C to to quit, this calls stopAcq
116
+ while 1 ,pause(0.1 ), end
104
117
105
118
119
+ % -----------------------------------------------
106
120
function stopAcq
107
121
fprintf(' Zeroing AO channels\n ' )
108
122
s .stop ;
112
126
113
127
fprintf(' Releasing NI hardware\n ' )
114
128
release(s );
115
- end
129
+ end % stopAcq
116
130
117
131
118
132
function plotData(src ,event )
@@ -134,7 +148,6 @@ function plotData(src,event)
134
148
set(hAx ,' CData' ,im );
135
149
set(imAx ,' CLim' ,[0 ,2 ]);
136
150
137
-
138
- end
151
+ end % plotData
139
152
140
- end
153
+ end % scanAndAcquire
0 commit comments