|
133 | 133 |
|
134 | 134 | %% Create Buffers |
135 | 135 |
|
136 | | -bufferA = zeros(totalSamples, 1, 'int16'); |
137 | | - |
138 | 136 | maxBuffers = 10; |
139 | 137 |
|
| 138 | +bufferA = zeros(totalSamples, 1,'int16'); |
| 139 | + |
140 | 140 | for i =(1:maxBuffers) |
141 | 141 | pBufferA(i,1) =libpointer('int16Ptr', bufferA); |
142 | 142 | end |
|
150 | 150 |
|
151 | 151 |
|
152 | 152 | [status.setBufferA] = invoke(ps6000aDeviceObj, 'ps6000aSetDataBuffer', channelA, pBufferA(1,1), ... |
153 | | - totalSamples, dataType, waveform, downSampleRatioMode, actionA); |
| 153 | + totalSamples, dataType, waveform, downSampleRatioMode, actionB); |
154 | 154 |
|
155 | 155 |
|
156 | 156 | %% Run Block Capture |
157 | 157 |
|
158 | 158 | sampleInterval = 1; |
159 | 159 | sampleIntervalTimeUnits = ps6000aEnumInfo.enPicoTimeUnits.PICO_US; |
160 | | -autoStop = 1; |
| 160 | +autoStop = 0; |
161 | 161 | downSampleRatio = 1; |
162 | 162 |
|
163 | 163 | disp('Streaming starting...') |
|
169 | 169 | streamData = ps6000aStructs.tPicoStreamingDataInfo.members; |
170 | 170 |
|
171 | 171 | streamData.bufferIndex_ = 0; |
172 | | -streamData.channel_ = ps6000aEnumInfo.enPicoChannel.PICO_CHANNEL_A; |
173 | | -streamData.mode_ = ps6000aEnumInfo.enPicoRatioMode.PICO_RATIO_MODE_AVERAGE; |
| 172 | +streamData.channel_ = channelA; |
| 173 | +streamData.mode_ = downSampleRatio; |
174 | 174 | streamData.noOfSamples_ = 0; |
175 | 175 | streamData.overflow_ = 0; |
176 | 176 | streamData.startIndex_ = 0; |
177 | | -streamData.type_ = ps6000aEnumInfo.enPicoDataType.PICO_INT16_T; |
| 177 | +streamData.type_ = dataType; |
178 | 178 |
|
179 | 179 | pStreamData = libpointer('tPicoStreamingDataInfoPtr',streamData); |
180 | 180 |
|
|
186 | 186 | pStreamTrigger = libpointer('tPicoStreamingDataTriggerInfoPtr',streamTrigger); |
187 | 187 | %% |
188 | 188 | i=1 |
189 | | -while i < maxBuffers |
| 189 | + |
| 190 | +needBufferStatus = hex2dec('197'); |
| 191 | + |
| 192 | +while i <= maxBuffers |
190 | 193 |
|
191 | | - pause(0.25) |
| 194 | + pause(1) |
192 | 195 |
|
193 | 196 | [status.getStreamingLatestValues] = invoke(ps6000aDeviceObj, 'ps6000aGetStreamingLatestValues', pStreamData, 1, pStreamTrigger); |
194 | 197 |
|
195 | | - if status.getStreamingLatestValues ~= 0 |
| 198 | + if status.getStreamingLatestValues ~= PicoStatus.PICO_OK |
196 | 199 | bufferA(:,i) = pBufferA(i,1).Value; |
197 | | - i=i+1 |
| 200 | + i=i+1; |
| 201 | + if i <= maxBuffers |
198 | 202 | [status.setBufferA] = invoke(ps6000aDeviceObj, 'ps6000aSetDataBuffer', channelA, pBufferA(i,1), ... |
199 | 203 | totalSamples, dataType, waveform, downSampleRatioMode, actionB); |
| 204 | + i |
| 205 | + end |
200 | 206 | end |
201 | 207 |
|
202 | 208 | end |
|
215 | 221 |
|
216 | 222 | voltageRange = 5000; %mV |
217 | 223 |
|
218 | | -bufferA = pBufferA.Value; |
219 | | - |
220 | 224 | bufferA = adc2mv(bufferA,voltageRange,double(maxValue)); |
221 | 225 |
|
222 | 226 | disp('Data converted to mV') |
223 | 227 |
|
224 | 228 | %% Plot Collected Data |
225 | 229 |
|
226 | 230 | samplesCollected=length(bufferA(:,1)); |
227 | | -maxTime = (double(samplesCollected) * sampleInterval); |
228 | | -timeUS = linspace(0,maxTime,samplesCollected); |
| 231 | +maxBufferTime = (double(samplesCollected) * sampleInterval); |
| 232 | +bufferTimeUS = linspace(0,maxBufferTime,samplesCollected); |
229 | 233 |
|
230 | 234 | figure(1) |
231 | | -plot(timeUS,bufferA(:,1)); |
| 235 | + |
232 | 236 | hold on |
| 237 | +for i = 1:maxBuffers |
| 238 | + plot(bufferTimeUS, bufferA(:,i)); |
| 239 | +end |
| 240 | + |
233 | 241 | ylabel('Voltage (mV)'); |
234 | 242 | xlabel('Time (us)'); |
235 | 243 | hold off |
236 | 244 |
|
| 245 | +totalBuffers = []; |
| 246 | +for i = 1:maxBuffers |
| 247 | + totalBuffers = vertcat(totalBuffers,bufferA(:,i)); |
| 248 | +end |
| 249 | + |
| 250 | +totalSamplesCollected = length(totalBuffers(:,1)); |
| 251 | +maxTime = (double(totalSamplesCollected) * sampleInterval); |
| 252 | +totalTimeUS = linspace(0,maxTime,totalSamplesCollected); |
| 253 | + |
| 254 | +figure(2) |
| 255 | + |
| 256 | +plot(totalTimeUS,totalBuffers); |
| 257 | +ylabel('Voltage (mV)'); |
| 258 | +xlabel('Time (us)'); |
| 259 | + |
237 | 260 | %% Disconnect scope |
238 | 261 |
|
239 | 262 | disconnect(ps6000aDeviceObj); |
|
0 commit comments