|
49 | 49 |
|
50 | 50 | AIDevice = 'Dev1'; |
51 | 51 | AIChans = 0; |
52 | | - AIterminalConfig = 'DAQmx_Val_RSE'; %Valid values: 'DAQmx_Val_Cfg_Default', 'DAQmx_Val_RSE', 'DAQmx_Val_NRSE', 'DAQmx_Val_Diff', 'DAQmx_Val_PseudoDiff' |
| 52 | + AIterminalConfig = 'DAQmx_Val_Cfg_Default'; %Valid values: 'DAQmx_Val_Cfg_Default', 'DAQmx_Val_RSE', 'DAQmx_Val_NRSE', 'DAQmx_Val_Diff', 'DAQmx_Val_PseudoDiff' |
53 | 53 | AODevice = 'Dev1'; |
54 | 54 | AOChan = 0; |
55 | 55 |
|
56 | 56 | minVoltage = -10; |
57 | 57 | maxVoltage = 10; |
58 | 58 |
|
59 | | - sampleRate = 10e3; %Hz |
60 | | - updatePeriod = 0.15; % How often to read |
61 | | - |
| 59 | + sampleRate = 30e3; % Samples per second |
62 | 60 |
|
63 | 61 | %Play a sinewave out of the AO |
64 | 62 | waveform = sin(linspace(-pi,pi, sampleRate/55))' * 5; % Build a sine wave to play through the AO line. NOTE: column vector |
65 | | - numSamplesPerChannel = length(waveform) ; % The number of samples to be stored in the buffer per channel |
66 | | - |
| 63 | + updatePeriod = 0.15; % How often to read |
| 64 | + readEveryNpoints=round(updatePeriod * sampleRate); % every this many points read data |
| 65 | + |
| 66 | + % Open a figure window and have it shut off the acquisition when closed |
| 67 | + % See: basicConcepts/windowCloseFunction.m |
| 68 | + fprintf('Close figure to quit acquisition\n') |
| 69 | + fig = clf; |
| 70 | + set(fig, 'CloseRequestFcn', @windowCloseFcn, ... |
| 71 | + 'Name', 'Close figure to stop acquisition') |
67 | 72 |
|
68 | 73 | try |
69 | 74 | % * Create separate DAQmx tasks for the AI and AO |
|
89 | 94 | % More details at: "help dabs.ni.daqmx.Task.cfgSampClkTiming" |
90 | 95 | % C equivalent - DAQmxCfgSampClkTiming |
91 | 96 | % http://zone.ni.com/reference/en-XX/help/370471AE-01/daqmxcfunc/daqmxcfgsampclktiming/ |
92 | | - hAITask.cfgSampClkTiming(sampleRate, 'DAQmx_Val_ContSamps', round(sampleRate*updatePeriod)*10); |
| 97 | + hAITask.cfgSampClkTiming(sampleRate, 'DAQmx_Val_ContSamps', readEveryNpoints*10); |
93 | 98 |
|
94 | 99 | % * Use a callback function to read from the buffer at the interval set by updatePeriod |
95 | 100 | % have been played out. Also see: basicConcepts/anonymousFunctionExample. |
96 | 101 | % More details at: "help dabs.ni.daqmx.Task.registerEveryNSamplesEvent" |
97 | | - hAITask.registerEveryNSamplesEvent(@readAndPlotData, round(updatePeriod * sampleRate), false, 'Scaled'); |
98 | | - |
| 102 | + hAITask.registerEveryNSamplesEvent(@readAndPlotData, readEveryNpoints, false, 'Scaled'); |
99 | 103 |
|
100 | 104 |
|
101 | 105 | %------------------------------------------------------------------------------- |
|
126 | 130 | % More details at: "help dabs.ni.daqmx.Task.cfgDigEdgeStartTrig" |
127 | 131 | % DAQmxCfgDigEdgeStartTrig |
128 | 132 | % http://zone.ni.com/reference/en-XX/help/370471AE-01/daqmxcfunc/daqmxcfgdigedgestarttrig/ |
129 | | - hAOTask.cfgDigEdgeStartTrig(['/',AIDevice,'/ai/StartTrigger'], 'DAQmx_Val_Rising'); |
130 | | - |
131 | | - |
132 | | - % Open a figure window and have it shut off the acquisition when closed |
133 | | - % See: basicConcepts/windowCloseFunction.m |
134 | | - fprintf('Close figure to quit acquisition\n') |
135 | | - fig = clf; |
136 | | - set(fig, 'Name', 'Close figure to stop acquisition') |
137 | | - fig.CloseRequestFcn = @windowCloseFcn; |
138 | | - |
| 133 | + hAOTask.cfgDigEdgeStartTrig(['/',AIDevice,'/ai/StartTrigger'], 'DAQmx_Val_Rising') |
| 134 | + |
139 | 135 | hAOTask.start(); |
140 | 136 | hAITask.start(); |
141 | 137 |
|
|
146 | 142 | hAITask.stop; % Calls DAQmxStopTask |
147 | 143 | hAOTask.stop; |
148 | 144 | delete([hAITask, hAOTask]); % The destructor (dabs.ni.daqmx.Task.delete) calls DAQmxClearTask |
| 145 | + delete(fig) |
149 | 146 | else |
150 | 147 | fprintf('No task variable present for clean up\n') |
151 | 148 | end |
|
155 | 152 | end %try/catch |
156 | 153 |
|
157 | 154 |
|
158 | | - function readAndPlotData(src,evnt) |
| 155 | + function readAndPlotData(src,~) |
159 | 156 | % Scaled sets the input to be represented as a voltage value |
160 | 157 | inData = readAnalogData(src, src.everyNSamples, 'Scaled'); |
161 | 158 | plot(inData) |
|
0 commit comments