Simulink 中的整数到二进制转换

发布于 2024-11-16 05:26:44 字数 211 浏览 5 评论 0原文

这可能看起来是我之前的问题的重复。但我认为并非如此。 我正在寻找一种将十进制格式的信号转换为二进制格式的技术。

我打算使用 Xilinx 库中的 Simulink 模块将十进制转换为二进制格式。

因此,如果输入为 3,则预期输出应为 11(2 个时钟周期)。我正在寻找串行获得的输出。

请建议我如何做,或者互联网上的任何指示都会有帮助。

谢谢

This might look a repetition to my earlier question. But I think its not.
I am looking for a technique to convert the signal in the Decimal format to binary format.

I intend to use the Simulink blocks in the Xilinx Library to convert decimal to binary format.

So if the input is 3, the expected output should in 11( 2 Clock Cycles). I am looking for the output to be obtained serially.

Please suggest me how to do it or any pointers in the internet would be helpful.

Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

孤云独去闲 2024-11-23 05:26:44

你是对的,你需要的是系统生成器的并行到串行块。
本文档对此进行了描述:

http://www.xilinx.com/ support/documentation/sw_manuals/xilinx13_1/sysgen_ref.pdf

该块是速率改变块。请查看这些文档中提及的并行转串行模块以获取更多说明:

http ://www.xilinx.com/support/documentation/sw_manuals/xilinx13_1/sysgen_gs.pdf

http://www.xilinx.com/support/documentation/sw_manuals/xilinx13_1/sysgen_user .pdf

You are correct, what you need is the parallel to serial block from system generator.
It is described in this document:

http://www.xilinx.com/support/documentation/sw_manuals/xilinx13_1/sysgen_ref.pdf

This block is a rate changing block. Check the mentions of the parallel to serial block in these documents for further descriptions:

http://www.xilinx.com/support/documentation/sw_manuals/xilinx13_1/sysgen_gs.pdf

http://www.xilinx.com/support/documentation/sw_manuals/xilinx13_1/sysgen_user.pdf

胡渣熟男 2024-11-23 05:26:44

使用一个带有Matlab变量的普通常量块,这已经给出了“普通”二进制的输出(假设您将其属性设置为无符号且二进制点为0。

然后您需要编写一个小的串行器块,它接受该输入,将其锁存到移位寄存器中,然后每个时钟周期将寄存器移位一次,其中“从末尾脱落”的位成为输出位,您可以使其首先出现MSB。 首先。

你必须 用普通寄存器构建移位寄存器,并在每个寄存器之前构建一个多路复用器,以选择是进行并行加载还是移位(这是 VHDL 中的几行代码,但在图形中是正确的。 )。

如果您必须提高串行速率,则需要使用更快的时钟对其进行计时 - 您可以使用 DCM 来生成它。

Use a normal constant block with a Matlab variable in it, this already gives the output in "normal" binary (assuming you set the properties on it to be unsigned and the binary point at 0.

Then you need to write a small serialiser block, which takes that input, latches it into a shift register and then shifts the register once per clock cycle with the bit that "falls off the end" becoming your output bit. Depending on which way your shift, you can make it come MSB first of LSB first.

You'll have to build the shift register out of ordinary registers and a mux before each one to select whether you are doing a parallel load or shifting. (This is the sort of thing which is a couple of lines of code in VHDL, but a right faff in graphics).

If you have to increase the serial rate, you need to clock it from a faster clock - you could use a DCM to generate this.

清醇 2024-11-23 05:26:44

Matlab 有一个 dec2bin 函数,可以将十进制数转换为二进制字符串。因此,例如 dec2bin(3) 将返回 11

还有一个相应的 bin2dec,它接受二进制字符串并转换为十进制数,因此 bin2dec('11') 将返回 3

如果您想将非整数十进制数转换为二进制字符串,您首先要确定要表示的最小二进制位是什么,然后进行一些预处理和后处理,结合起来使用 dec2bin 来获取您正在寻找的结果。因此,如果您想要的最小二进制位置是第 1/512 位(或 2^-9),那么您可以执行以下操作(其中 binPrecision 等于 1/512):

function result = myDec2Bin(decNum, binPrecision)

  isNegative=(decNum < 0);
  intPart=floor(abs(decNum));
  binaryIntPart=dec2bin(intPart);
  fracPart=abs(decNum)-intPart;
  scaledFracPart=round(fracPart / binPrecision);
  scaledBinRep=dec2bin(scaledFracPart);
  temp=num2str(10^log2(1/binPrecision)+str2num(scaledBinRep),'%d');                                                                                                                                                                        
  result=[binaryIntPart,'.',temp(2:end)];
  if isNegative
    result=['-',result];
  end
end

myDec2Bin(0.256, 1/ 512) 则为 0.010000011,结果为myDec2Bin(-0.984, 1/512) 将是 -0.111111000。 (请注意,输出是一个字符串。)

Matlab has a dec2bin function that will convert from a decimal number to a binary string. So, for example dec2bin(3) would return 11.

There's also a corresponding bin2dec which takes a binary string and converts to a decimal number, so that bin2dec('11') would return 3.

If you're wanting to convert a non-integer decimal number to a binary string, you'll first want to determine what's the smallest binary place you want to represent, and then do a little bit of pre- and post-processing, combined with dec2bin to get the results you're looking for. So, if the smallest binary place you want is the 1/512th place (or 2^-9), then you could do the following (where binPrecision equals 1/512):

function result = myDec2Bin(decNum, binPrecision)

  isNegative=(decNum < 0);
  intPart=floor(abs(decNum));
  binaryIntPart=dec2bin(intPart);
  fracPart=abs(decNum)-intPart;
  scaledFracPart=round(fracPart / binPrecision);
  scaledBinRep=dec2bin(scaledFracPart);
  temp=num2str(10^log2(1/binPrecision)+str2num(scaledBinRep),'%d');                                                                                                                                                                        
  result=[binaryIntPart,'.',temp(2:end)];
  if isNegative
    result=['-',result];
  end
end

The result of myDec2Bin(0.256, 1/512) would then be 0.010000011, and the result of myDec2Bin(-0.984, 1/512) would be -0.111111000. (Note that the output is a string.)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文