about Tx-Matlab

Create new topics, add your comment, remark, bugs...
Post Reply
Magic
Posts: 7
Joined: Thu Jan 15, 2009 10:06 am
Location: Taiwan

about Tx-Matlab

Post by Magic » Mon Mar 16, 2009 9:31 am

Hello Lubin,

I have a question about Tx-Matlab

My baud rate is 115200 and max 23 Bytes/0.002s

I send 3 Datas every 0.002s.
But I found the time interval is about 0.01s or 0.02s(sometime 0.03s) in t_R & t_Rn in workspace.
time1.JPG
Is the UART wrong? or some configuration I do not set?

Magic
Attachments
MC710_ID2.mdl
Send the QEI Position every 0.002s
(37.43 KiB) Downloaded 611 times

LubinKerhuel
Site Admin - Expert
Posts: 616
Joined: Wed Mar 07, 2007 11:23 pm
Location: Bayonne- France
Contact:

Re: about Tx-Matlab

Post by LubinKerhuel » Tue Mar 17, 2009 1:26 am

Hi Magic,

Thanks for this interresting question.
I tried to complete the doc of theInterface_Tx-Matlab page. I added that :

Code: Select all

T_R is an approximation of time only, and shoudl be used for vewing purpose only. If you need precise data time stapm, follow the following procedure :

    * On the simulink model, make sure to not overload the UART. Check that you are sending less data than max allowed by the UART bauds. To count the number of bytes used, when using the Tx-Labview-Matlab block, add one byte for each data sent. For example sending one uint8 data takes 2 bytes, uint16 data takes 3 bytes and uint32 data takes 5 bytes.
    * Reconstruct a vector timing corresponding to the simulink's UART timing. 

T_R (and T_Rn) approximate the time using the computer clock. Each time Matlab read an UART sequence, time is read. Then, the first byte of the sequence is assigned to the time of the previous clock read, and the last byte of the sequence is assigned with current time. Any bytes in between is assigned to a time using a linear approximation (with time of sequenc start and time of sequence stop). Thus, the time received of the first trame may be much longer if no data is send at the beginning of the logging process. 
I am not very happy of this explanation, but I hope anyway to make it clear enough !
Let me know...

Lubin

Magic
Posts: 7
Joined: Thu Jan 15, 2009 10:06 am
Location: Taiwan

Re: about Tx-Matlab

Post by Magic » Tue Mar 17, 2009 3:33 am

Hello Lubin,

Thank you for this explanation. I understand now!

Thus,after computer received the data,the time interval would be about the sampling time(0.002s).
received data.JPG
Thanks again.

Magic

LubinKerhuel
Site Admin - Expert
Posts: 616
Joined: Wed Mar 07, 2007 11:23 pm
Location: Bayonne- France
Contact:

Re: about Tx-Matlab

Post by LubinKerhuel » Tue Mar 17, 2009 3:34 pm

Hi Magic,
Magic wrote:after computer received the data,the time interval would be about the sampling time(0.002s)
That true, but you should really recompute a time vector of exactly 0.002s as the dsPIC quartz is much better than the bad approximation that is done with the RS232GUI.
If you do not overload the UART (It seems not to be overloaded here) the sampling time of the three data is exactly 0.002s !

for example :

Code: Select all

R = padr(R,1);

t_Rreconstructed = 0:.002:((length(R)-1)*.002);

%% if you want to generate a file to feed a simulink model : 
SimIn = [0:.002:(length(R)-1)*.002 ; R'];
save SimIn SimIn
Lubin

Post Reply

Who is online

Users browsing this forum: No registered users and 43 guests