필터 지우기
필터 지우기

Send Serial Communication data to FPGA

조회 수: 12 (최근 30일)
Hugo Pontes
Hugo Pontes 2020년 6월 16일
답변: Phan Phat 2020년 9월 2일
Hello. I am trying to test the communication between MATLAB on my computer and an FPGA I programmed. What I'm attempting to do is to send a number and have the FPGA return that number times 2. I am using an 8bit fixed point representation with 4 integer bits and 4 fractional bits.
My code is the following:
int=4;
frac=4;
data = 3.25
fixdata = dec2fix(data,int,frac);
senddata = bin2dec(fixdata);
s = serial('COM5','BaudRate',9600,'TimeOut',0.1,'Terminator','LF');
fopen(s);
fwrite(s,senddata,'uint8');
a=fix2dec(dec2bin(fread(s),int+frac),int,frac)
fclose(s)
delete(s)
fix2dec and dec2fix are custom made functions that transform decimal numbers into their closest fixed number representation and vice versa.
So supposedly the data (3.25) will be input, then its fixed point equivalent will be calculated, which will be 0011.0100 then it is converted back to a decimal considering a uint8 format (00110100 = 52). Am I right to assume that if I send that decimal (senddata = 52) the laptop tx pin will output 00110100? Do I need to send a start bit before?
As it stands, I always get 11111111 as an output, except for when data is 3.5 which for some reason which yields 11111110.
According to FPGA simulations, if the matlab tx output was 0 (start bit) + 00110100(data bits) +1(stop bits), the output should be the correct fixed point represenation of 6.5 = 01101000
What is wrong here? If nothing is I suppose the problem is in the FPGA
  댓글 수: 2
Andrey Smolyakov
Andrey Smolyakov 2020년 6월 16일
If I understand documentation correctly (here, section 'StopBits'), you are right, and MATLAB will send start bit, 8 bits of your data, and stop bit. So I guess that nothing is wrong here, and the problem is on the FPGA side.
Hugo Pontes
Hugo Pontes 2020년 6월 17일
I've been getting readings from an oscilloscope and I've checked that this is true, MATLAB outputs a three in binary but the timing of the FPGA is wrong and doesn't decipher it correctly

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

답변 (1개)

Phan Phat
Phan Phat 2020년 9월 2일
Hi Hugo Pontes,
What kind of FPGA and connector are you using?

카테고리

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

태그

제품


릴리스

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by