How can I keep the proportion between the data and the values of axis?

1 view (last 30 days)
Hello everyone. I am making a virtual oscilloscope in app designer, and I have troubles with plotting the right values. When in the default state, plotting shows the correct values of voltage on the X and Y-scale, but, when I turn the knob of the scope, the voltage is doubled when I decrease the vertical scale (a step on the Y-scale), otherwise the voltage is halved. I have attached the probe on the test voltage, which is squared, 5 volts. Does anyone know what could be the problem? I used the formulas for XData and YData from the code of scope's manufacturer. The same formulas were used for the other scopes. The images of my GUI are provided here: http://imgur.com/a/veKnf
if true
% code
% Value changed function: AcquireDataButton
function AcquireDataButtonValueChanged(app, event)
app.AcquireDataButton.Value = event.Value;
value = app.AcquireDataButton.Value;
instrreset;
visaAddress = 'USB::0x0699::0x03C6::C010224::INSTR';
myScope = visa('tek', visaAddress);
myScope.InputBufferSize = 4096;
fopen(myScope);
% Reset the oscilloscope to a known state
fprintf(myScope, '*RST');
fprintf(myScope, '*CLS');
% Turn headers off, this makes parsing easier
fprintf(myScope, 'HEADER OFF');
% Autoset the oscilloscope
fprintf(myScope, 'AUTOS EXECute');
%%Get record length value
recordLength = query(myScope, 'HOR:RECO?');
% Ensure that the start and stop values for CURVE query match the full
% record length
fprintf(myScope, ['DATA:START 1;DATA:STOP ' recordLength]);
% Horizontal interval
xIncr = query(myScope,'WFMOutpre:XINcr?');
xIncr = str2double(xIncr);
% Vertical offset
fprintf(myScope,'WFMOutpre:YZEro?');
vertOffset = fscanf(myScope);
vertOffset = str2double(vertOffset);
% Read YOFFSET to calculate the vertical values
yOffset = query(myScope, 'WFMO:YOFF?');
yOffset = str2double(yOffset);
% Read YMULT to calculate the vertical values
verticalScale = query(myScope,'WFMOUTPRE:YMULT?');
verticalScale = str2double(verticalScale);
% Request 8 bit binary data on the CURVE query
fprintf(myScope, 'DATA:ENCDG RIBINARY;WIDTH 1');
while value == true
fprintf(myScope, 'WAVFrm?');
waveform = binblockread(myScope,'int8');
YData = (waveform-yOffset).*verticalScale + vertOffset;
app.YDataEditField.Value = YData(100);
XData = (xIncr.*(1:length(YData))) - xIncr;
app.XDataEditField.Value = XData(100);
timeBase = str2double(query(myScope, 'HORizontal:SCAle?'));
app.XScaleEditField.Value = timeBase;
voltsPerDiv = str2double(query(myScope,'CH1:SCAle?'));
app.YScaleEditField.Value = voltsPerDiv;
xlim(app.UIAxes, [0 timeBase*15]);
ylim(app.UIAxes, [0 10*voltsPerDiv]);
plot(app.UIAxes, XData, YData);
app.UIAxes.XGrid = 'on';
app.UIAxes.YGrid = 'on';
drawnow
if value == false
break
end
end
plot(app.UIAxes, 0);
end
  2 Comments
Jan
Jan on 4 May 2017
Without seeing the code it is impossible to guess the source of problems.
miki90
miki90 on 4 May 2017
I've put a code now. Sorry for the long code, I don't know how to put a code to have a slider.

Sign in to comment.

Answers (0)

Community Treasure Hunt

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

Start Hunting!