Send Serial Communication data to FPGA

11 ビュー (過去 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?

タグ

製品


リリース

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by