Path: news.mathworks.com!not-for-mail
From: "Benjamin " <benjaminst@gmail.com>
Newsgroups: comp.soft-sys.matlab
Subject: Time elapsed using serial fwrite and fread functions
Date: Tue, 11 Nov 2008 22:10:18 +0000 (UTC)
Organization: Universidad Polit&#233;cnica de catalu&#241;a
Lines: 27
Message-ID: <gfcvsa$dpv$1@fred.mathworks.com>
Reply-To: "Benjamin " <benjaminst@gmail.com>
NNTP-Posting-Host: webapp-05-blr.mathworks.com
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 8bit
X-Trace: fred.mathworks.com 1226441418 14143 172.30.248.35 (11 Nov 2008 22:10:18 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Tue, 11 Nov 2008 22:10:18 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 1190546
Xref: news.mathworks.com comp.soft-sys.matlab:500306


Hi all!

Currently I am working in my master thesis. It consists on implementing an arbitrary waveform generator using Matlab and a FPGA. So, I need to transfer signal samples (100Kbytes) from Matlab to a Altera Nios 2 processor(85MHz) using a serial protocol (UART 115Kbps). I have done the following code which I have tested and it works ok:

....
tic
for i=1:length(data_to_send) %length(data_to_send)=100e3
    tic
    fwrite(s,data_to_send(i),'uchar');
    time_write(i)=toc;
    tic
    if(fread(s,1,'uchar')~=0)
        Error('Unexpected error while reading UART');
    end
    time_read(i)=toc;
end
time_elapsed=toc;
fprintf (1,'Elapsed CPU time (min) = %f\n',time_elapsed/60);
...

The main problem is that it is too slow (the elapsed cpu time is more than 30minutes!). I can't understand it because the expected time a grosso modo would be 100Kbytes/115.2Kbits/s=6,94seconds. 

I'm sure that the problem is not from Nios 2 processor because the main function is just a infinite loop that reads from the uart and send 0 character.

Does anybody know if there is a manner to increase the perfomance of the serial transmision? Thanks in advance,

Ben