CrazyEngineers
  • using matlab for serial port - smth's weird

    felure

    Member

    Updated: Oct 26, 2024
    Views: 1.0K
    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
    0
    Replies
Howdy guest!
Dear guest, you must be logged-in to participate on CrazyEngineers. We would love to have you as a member of our community. Consider creating an account or login.
Replies
  • felure

    MemberMar 27, 2012

    maybe more convenient, the data from the file...sequence.jpg
    Are you sure? This action cannot be undone.
    Cancel
  • Donagh

    MemberMar 28, 2012

    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
    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
    Are you sure? This action cannot be undone.
    Cancel
Home Channels Search Login Register