Measuring Voltage from digital multimeter with USB (spci)

13 Ansichten (letzte 30 Tage)
Evgeniy Levitcky
Evgeniy Levitcky am 26 Mär. 2020
Greeting!
I am quite new to matlab language and all those details and features involved into measuring data with scpi+matlab so i want to ask few questions:
I have a B7-78/1 digital multimeter that i can connect to my computer with USB and talk to it using SPCI (Standard Commands for Programmable Instruments).
I need to measure voltage with most possible accuracy like 2-3 digits after the point (something like 3.245v) and each sample should be within 15ms range or less for around 20 secs after trigger signal.
In short the main question is that i want to be sure that i can trust data received with code below. And if there is something wrong what should i change/improve
I found example how to measure and plot live data and i modify it to my needs, here what i came up with after several days of searching/testing/reading:
some notes:
-it works fine (i belive^^) and i want you to see if i did something wrong that can affect accyracy of measurement (credibility of data i received). i scroll trhough it using "data cursor"
-all those fancy settings for graph i took from example, and they dont really needed, as i understand i can remove them and just use
figure;
plot(voltage,time);
-i tried to use external trigger all the time since it can measure up to 50 000 values after one trigger, but did not succeed and i think that switching from "TRIGger:SOURce EXT" to "immediate" is instant and dont affect anything
-i did some testing with time measurement and find out that fastest was tic/toc combination. Also datenum was fine. Datetime() was theslowest method geting time samples.
-in the original code graph was plotted live with this in the while loop:
set(figureHandle,'Visible','on');
datetick('x','ss');
pause(0.005);
but it was too slow , each dot was 30-50ms away from other dots.
-also using pause(some_pause_value) makes everything too slow and actually not needed since we dont plot live,
i belive that "slowest" thing in cycle is waiting for the answer from multimeter(its like some kind of pause(x) in that cycle while we are waiting):
voltage(count) = fscanf(obj1,'%f'); %#getting answer %f - floating point
-i dont want to use osciloscope, i need to get data with multimeter
Thanks in advance and have a nice day ;)
Here is the code(+i attached example graph that i received with it, just in case):
%%ADD DEVICE AS OBJ:
if exist('obj1')==0;
obj1 = visa('ni','USB0::0x164E::0x0DAD::TW00017024::0::INSTR'); %add obj
end
%re open connection
fclose(obj1);
fopen(obj1);
fprintf(obj1,'SYSTEM:REMOTE'); %set device in remote mode
%% Set up the figure window
figureHandle = figure('NumberTitle','off',...
'Name','Voltage Characteristics',...
'Color',[0 0 0],'Visible','off');
%%for GRAPH
% Set axes
axesHandle = axes('Parent',figureHandle,...
'YGrid','on',...
'YColor',[0.9725 0.9725 0.9725],...
'XGrid','on',...
'XColor',[0.9725 0.9725 0.9725],...
'Color',[0 0 0]);
hold on;
plotHandle = plot(axesHandle,time,voltage,'Marker','.','LineWidth',1,'Color',[0 1 0]);
xlim(axesHandle,[min(time) max(time+0.005)]);
% Create xlabel
xlabel('Time(X)','FontWeight','bold','FontSize',14,'Color',[1 1 0]);
% Create ylabel
ylabel('Voltage in V(Y)','FontWeight','bold','FontSize',14,'Color',[1 1 0]);
% Create title
title('Voltage Characteristics','FontSize',15,'Color',[1 1 0]);
%end for graph
%% SET VARIABLES:
time = now;
voltage = 0;
%pre allocate to speed things up
time = nan(9999,1);
voltage = nan(9999,1);
%%set up variables
n= 19; %time in seconds for how long to measure
timeInterval = 0.001; %not used
count = 1;
stopTimeNew = datetime('now')+seconds(21); %for how long measure
%datetime
stopTime = datetime('now','Format','mm:ssss.SSS');%(DATE TIME FORMAT) %for testing
timenow = datetime('now','Format','mm:ss.SSS');%(DATE TIME FORMAT)pre create it to make faster; %for testing
starttime = datetime('now','Format','ss.SSS');%(DATE TIME FORMAT) %for testing
%datenum
starttimedaetnum = now; %(DATE SERIAL FORMAT) %for testing
%%Configure device for measurements:
fprintf(obj1,'*RST'); %reset config
fprintf(obj1,'*CLS'); %clear all errors etc
%trigger settings
fprintf(obj1,'TRIGger:SOURce EXT'); %set external trigger mode
fprintf(obj1,'TRIGger:DELay min'); %set delay to 0
fprintf(obj1,'SAMP:COUNt 1'); %number of samples
%voltage settings
fprintf(obj1,'CONF:VOLT:DC 10, 0.01'); %set config
fprintf(obj1,'sense:voltage:NPLC 0.02'); %fastest measurement with those settings 0.02 - faster;1/02./10/10/100 100 - slowest
%waiting for trigger:
voltss = query(obj1,'Read?'); %waiting for trigger signal
fprintf(obj1,'TRIGger:SOURce IMM'); %set device in live measurement
tic %set starting time
while datetime('now','Format','mm:ss.SSS') <= stopTimeNew
%timenow = datetime('now','Format','mm:ss.SSS'); %(DATE TIME FORMAT) 7ms %for testing
%time(count) = seconds(timenow-stopTime); %(DATE TIME FORMAT) 7ms %for testing
%timedif = now - starttimedaetnum; %getting difference (DATE SERIAL FORMAT) 5ms %for testing
%time(count) = timedif*24*3600; %convert to seconds (DATE SERIAL FORMAT) 5ms %for testing
fprintf(obj1,'INIT'); %asking
fprintf(obj1,'FETC?'); %asking
time(count) = toc; %(TOC/TIC) 5ms
voltage(count) = fscanf(obj1,'%f'); %#getting answer %f - floating point
set(plotHandle,'YData',voltage,'XData',time);
%pause(timeInterval); %USED FOR LIVE DATA PLOTTING TO UPDATE THINGS
count = count +1;
end
%show what we ended up with:
set(figureHandle,'Visible','on');
datetick('x','ss');
%% Put the instrument in local mode
fprintf(obj1,'SYSTEM:LOCAL');
%delete(obj1);
%clear all;

Antworten (0)

Kategorien

Mehr zu Time Series Events finden Sie in Help Center und File Exchange

Produkte


Version

R2015b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by