Problem with serial port communication

조회 수: 1 (최근 30일)
Swarnava Pramanik
Swarnava Pramanik 2016년 6월 15일
댓글: Swarnava Pramanik 2016년 6월 26일
Hi,
I'm interfacing ALtera MAX10 fpga development kit with Matlab and trying to acquire data continuously. I can send command to the fpga board through Matlab regarding how many samples of data I want to capture (Also I'm increasing the buffer size according to the number of samples to be captured). Till 30000 samples I am getting the data correctly. Whenever I'm increasing the sample count to 50000, Matlab is throwing an error that the buffer size cannot be increased to this amount. I want to acquire data continuously say for 5 minutes ( corresponding to 300,000 samples ). Can anyone please kindly help me resolve this issue ? Note that baud rate is set to 115200 bps.
Thanks, Swarnava Pramanik

채택된 답변

Walter Roberson
Walter Roberson 2016년 6월 15일
Use a BytesAvailableFcn callback to save the data from time to time.
  댓글 수: 14
Swarnava Pramanik
Swarnava Pramanik 2016년 6월 18일
Hi Walter,
Could you please kindly help me in another problem. I'm able to continuously get the data from my fpga board and at the same time I'm processing my data. It's happening so that my board is sending suppose 12000 samples but I'm only able to receive 11770 samples (losing around 300 samples corresponding to 0.3 seconds of data ). I'm attaching my code also
function store_plot_data(serialObject,event,chunk)
strRecv = fscanf(serialObject, '%s', chunk);
if( strcmp(strRecv(end), ',') == 1)
data_draw = [ data_draw dataStringTail strRecv ];
dataStringTail = [];
elseif( ( isempty(dataStringTail) == 0 ) && ( strcmp(strRecv(end), ',') == 0))
lastCommaIndex = max(strfind(strRecv,','));
% dataStringTail = strRecv(lastCommaIndex : end);
data_draw = [data_draw dataStringTail strRecv];
dataStringTail = [];
else
lastCommaIndex = max(strfind(strRecv,','));
dataStringTail = strRecv(lastCommaIndex : end);
data_draw = [data_draw strRecv(1 : lastCommaIndex - 1)];
end
end
Please note that "data_draw", "dataStringTail" are global variables.
Thanks,
Swarnava Pramanik
Swarnava Pramanik 2016년 6월 26일
Hi Walter,
The callback function to the BytesAvailableFcn occurs only when the number of bytes specified by the BytesAvailableFcnCount is available in the input buffer. Suppose if the input buffer doesn't have the number of bytes specified by the BytesAvailableFcnCount property then the callback function is not executed. This is why I'm loosing some sample. Is there anyway to get around this ?
Thanks,

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 MATLAB에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by