Branch Unspecified
29 Mar 2012

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;


fprintf(s, '*99C') %starting measurement

if(s.BytesAvailable > 0)
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

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


Branch Unspecified
6 years ago
maybe more convenient, the data from the file...sequence.jpg


Branch Unspecified
6 years ago
I 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

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
delete(s) % object must be closed, deleted and removed from the workspace
clear s

Share this content on your social channels -

Only logged in users can reply.