using matlab for serial port - smth's weird
Hi everybody, I would need some help on that one.
A magneto-meter is connected via a serial port to matlab and actually everything works fine, EXCEPT that, if the data is read in continuous mode it shows some unreasonable jumps in between the physical smooth signal.
here's the code:
close all;
s = serial('COM3');
set(s, 'Terminator', 'CR') %is the proper terminator for the device
s.InputBufferSize = 30000;
s.BaudRate = 19200;
fopen(s)
fprintf(s, '*99C') %starting measurement
pause(5)
if(s.BytesAvailable > 0)
s.BytesAvailable
out = fread(s,s.BytesAvailable,'uint8');
fprintf(s,'ESC') %stopping measurement
...out gets processed further to convert the binary data to decimal in way that is of no concern here, but is certainly correct
fclose(s)
delete(s)
clear s
now what the weird part is, is the received data which is attached in the 'testo' file
there seems to be, for what ever reason, a wrong signal at around 0.25 and sometimes at 0.00 for the respective axes that is physically not there.
I guess the sensor basically works fine, and also, physical perturbations of the magnetic field that would correspond to the received data can be ruled out.
If anybody has any hint i really would appreciate it, I spent already too much time on looking at various different reasons for the thing.
thanks in advance. f
A magneto-meter is connected via a serial port to matlab and actually everything works fine, EXCEPT that, if the data is read in continuous mode it shows some unreasonable jumps in between the physical smooth signal.
here's the code:
close all;
s = serial('COM3');
set(s, 'Terminator', 'CR') %is the proper terminator for the device
s.InputBufferSize = 30000;
s.BaudRate = 19200;
fopen(s)
fprintf(s, '*99C') %starting measurement
pause(5)
if(s.BytesAvailable > 0)
s.BytesAvailable
out = fread(s,s.BytesAvailable,'uint8');
fprintf(s,'ESC') %stopping measurement
...out gets processed further to convert the binary data to decimal in way that is of no concern here, but is certainly correct
fclose(s)
delete(s)
clear s
now what the weird part is, is the received data which is attached in the 'testo' file
there seems to be, for what ever reason, a wrong signal at around 0.25 and sometimes at 0.00 for the respective axes that is physically not there.
I guess the sensor basically works fine, and also, physical perturbations of the magnetic field that would correspond to the received data can be ruled out.
If anybody has any hint i really would appreciate it, I spent already too much time on looking at various different reasons for the thing.
thanks in advance. f
Replies
-
feluremaybe more convenient, the data from the file...
-
DonaghI was doing something quite similar recently, here is my acquisition code.
Maybe this will give you some more ideas.
% Function: STRINGGET
%
% Description: code for capturing a string trtminated by 'w'
% String Description: <-...,w,w,w,w,w,w,R0444,G0444,.......,t20,W,w,w,w,w,...->
% Trigger: 'S'
% Serial Port Terminator: 'w'
% BaudRate : 19200
% Input Buffer Size: 4500 CHAR
% Timeout: 60 seconds
% Inputs: ADuC842 UART serial string
% Outputs: serial string
s = serial('COM1'); %create serial port object on COM1
set(s,'BaudRate',19200, 'Parity','none', 'Terminator', 'w', 'InputBufferSize', 4500, 'Timeout', 60);
% set serial port object peramiters
fopen(s);
fprintf(s, 'S'); % send 'S' CHAR to ADuC842
str = fgetl(s); % read string from input buffer of serial port object
k = str % move string into k for opperations
fclose(s);
delete(s) % object must be closed, deleted and removed from the workspace
clear s
You are reading an archived discussion.
Related Posts
I've just started on this new line of action and thought it well to fill everyone in.
Android is growing immensely and I must say, we need to be at...
If you are thinking of purchasing the Adobe Photoshop CS6, make sure that you don't have 32 bit version of the Mac. Adobe has made it clear that their latest...
Microsoft and Nokia have teamed up to beat the Apples and the Samsungs of the world. While Windows phone clearly benefits from the hardware knowhow of the Finnish Nokia; the...
what is bus fault current?
How the no load losses of the transformer can be minimized ?