一个困扰了我很久的关于vhdl位数的问题

作者&投稿:良蚀 (若有异议请与网页底部的电邮联系)
求助~一个困扰我很久的问题。~

您可以在命令提示符中输入ipconfig /all查询主机连接的DNS服务器地址,然后在设定一个主机的固定IP地址和DNS服务器地址试试。

可以参考 xilinx 的 application note "Serial Code Conversion between
BCD and Binary"
http://www.ingelec.uns.edu.ar/dclac2558/BCD2BIN.PDF

The basic idea is to shift data serially into a shift register. As each bit is shifted in, the accumulated sum is collected. Each shift effectively doubles the value of the binary number in the four bit shift register which is going to hold the converted BCD digit.
Each time a bit is shifted in, the value in the shift register is doubled. After four bits have been shifted in, if the original value is 0, 1, 2, 3, or 4, then the result is within the 0-9 range of a BCD digit and there is no action required.
If the value is 5, 6, 7, 8, or 9, then the doubled result is greater than 10, so a carry out (called ModOut in the code) is generated to represent the overflow into the tens column (i.e. into the next BCD digit). Here's a little table showing how to double each bit in BCD. All numbers shown are decimal.

input tens units result
0 0 0 0
1 0 2 2
2 0 4 4
3 0 6 6
4 0 8 8
5 1 0 10
6 1 2 12
7 1 4 14
8 1 6 16
9 1 8 18

The tens column thus represents an overflow into the next most significant BCD digit.
Does this all seems a bit baffling? There's a more thorough explanation in the application note referenced above.



The code is in three files:
digit.vhd
This contains a model for one four bit BCD digit, with carry in (ModIn) and carry out (ModOut). The digit has asynchronous reset, and an Init signal. The Init signal forces the carry out to zero at before a conversion starts.
bcdconv.vhd
This contains a generic N which allows you to specify the number of 4 bit BCD digits in the BCD converter. The generic is used to control a generate statement, which makes N instances of the Digit component described above.
bcdconvtb.vhd
This contains a testbench which applies a serial binary input representing a range of binary numbers, and then writes out the corresponding BCD equivalents
-----------------------------------------------------------------------------------------------------
library IEEE;
use IEEE.std_logic_1164.all;
use IEEE.numeric_std.all;
use STD.textio.all;

entity BCDConvTB is
end;

architecture Bench of BCDConvTB is

component BCDConv
generic (N : positive);
port (Clock : in std_logic;
Reset : in std_logic;
Init : in std_logic;
ModIn : in std_logic;
ModOut : out std_logic;
Q : out std_logic_vector(N*4-1 downto 0)
);
end component;

-- hold an array of BCD digits
type BCDVectorT is array (natural range ) of std_logic_vector(3 downto 0);

-- number of digits implemented in this test bench
constant N : positive := 5;

-- BCD array as a single std_logic_vector (packed in 4 bits at a
-- time)
subtype BcdT is std_logic_vector(N*4-1 downto 0);

signal Clock : std_logic;
signal Reset : std_logic;
signal Init : std_logic; -- Initialise BCD conversion
signal ModIn : std_logic; -- modulus in, if we wanted to
-- cascade lots of NDigits design entities
signal ModOut : std_logic; -- modulus out, same reason as ModIn
signal Q : BCDT; -- The outputs of the BCD conversion packed
-- into a std_logic_vector

-- Test bench control signal to ensure Clock stops when testing is over
signal StopClock : boolean;

-- Outputs of BCD conversion as an array of 4 bit digits.
signal BCDVec : BcdVectorT(1 to N);

-- Type to allow a table of test values
type TableT is array (natural range ) of Integer;

-- some interesting values to test
constant Table : TableT := (17,18,19,20,21,22,23,30,40,50,
60,70,80,90,91,92,93,94,95,96,
97,98,99,100,101,302,
555,707,9999,10100, 99999);

signal TestInteger : Integer;

begin

UUT: BCDConv
generic map (N => N)
port map (
Clock => Clock,
Reset => Reset,
Init => Init,
ModIn => ModIn,
ModOut => ModOut,
Q => Q);

-- 100 ns clock. Clock loop stops automatically when the
-- stimulus process has finished, using the boolean signal StopClock
ClockGen: process
begin
while not StopClock loop
Clock <= '0';
wait for 50 ns;
Clock <= '1';
wait for 50 ns;
end loop;
wait;
end process;


--
-- Generate a set of values to test the Binary to BCD converter
--
StimGen: process
variable TestVal : BCDT;
variable L : LINE;
begin
Reset <= '0';
ModIn <= '0';
Init <= '0';
wait until falling_edge(Clock);
Reset <= '1';
wait until falling_edge(Clock);
Reset <= '0';


-- test all the values in the table
write(L, STRING'("Expected:"), LEFT, 10);
write(L, STRING'("Actual:"), LEFT, 10);
writeline(OUTPUT,L);

for I in Table'RANGE loop

-- convert integer value to std_logic_vector
TestVal := std_logic_vector(to_unsigned(Table(I), N*4));

-- assign the test value to an integer signal - easy to
-- disply in the simulator
TestInteger <= Table(I);
write(L, Table(I), LEFT, 10);

-- Loop round all the bits in the input vector
for J in BCDT'RANGE loop

-- initialise conversion if shifting in the first bit
if J = BCDT'LEFT then
Init<= '1';
else
Init <= '0';
end if;

ModIn <= TestVal(J);

wait until falling_edge(Clock);
end loop;

-- pack the result from the converter into a single std_logic_vector
-- (and write them as we go to check against the originals).
for J in 1 to N loop
BCDVec(J) <= Q(J*4-1 downto J*4-4);
write(L, to_integer(unsigned(Q(J*4-1 downto J*4-4))));
end loop;

writeline(OUTPUT,L);

end loop;

StopClock <= TRUE; -- tell the clock generator to stop
wait;
end process;

end;

-- must have a configuration for synopsys vhdl simulator
use work.all;
configuration cfg_BCDConvTB of BCDConvTB is
for Bench
end for;
end;

-----------------------------------------------------------------------------------------------------
library IEEE;
use IEEE.std_logic_1164.all;

entity BCDConv is
generic (N : positive); -- number of digits
port (Clock : in std_logic;
Reset : in std_logic;
Init : in std_logic; -- initialise conversion
ModIn : in std_logic; -- carry in from outside
ModOut : out std_logic; -- carry out
Q : out std_logic_vector(4*N -1 downto 0) -- BCD result
);
end;

architecture RTL of BCDConv is

component Digit
port (Clock : in std_logic;
Reset : in std_logic;
Init : in std_logic;
ModIn : in std_logic;
ModOut : out std_logic;
Q : out std_logic_vector(3 downto 0)
);
end component;

signal ModVec : std_logic_vector(1 to N+1);

begin

-- The magic of generate!
g1 : for i in 1 to N generate
c1: Digit
port map
(Clock => Clock,
Reset => Reset,
Init => Init,
ModIn => ModVec(I+1),
ModOut => ModVec(I),
Q => Q(I*4-1 downto I*4-4));
end generate;

ModOut <= ModVec(1);
ModVec(N+1) <= ModIn;

end;
-----------------------------------------------------------------------------------------------------
library IEEE;
use IEEE.std_logic_1164.all;

entity Digit is
port (Clock : in std_logic;
Reset : in std_logic; -- clear registers asynchronously
Init : in std_logic; -- initialise the BCD conversion
ModIn : in std_logic; -- modulus in from less significant digit
ModOut : out std_logic; -- modulus out to more significant digit
Q : out std_logic_vector(3 downto 0) -- BCD output
);
end;

architecture RTL of Digit is
signal Q_int : std_logic_vector(3 downto 0);
signal NextQ_int : std_logic_vector(2 downto 0);
signal NextModOut : std_logic;
begin

ShiftReg : process(Clock)
begin
if Rising_Edge(Clock) then
if reset = '1' then
Q_int '0');
else
if Init = '1' then
Q_int '0');
Q_int(0) <= ModIn; -- set LSB initialisation
else
Q_int <= NextQ_int & ModIn; -- shift left
end if;
end if;
end if;
end process;


-- Calculate the shift in the BCD register. Numbers between
-- 0 and 4 inclusive are doubled, by shifting by 1.
-- Numbers from 5 to 9 inclusive get mapped to 10, 12, 14,
-- 16, 18. This gives an modout of 1 (i.e. a carry to the
-- next digit), and the values 0, 2, 4, 6, 8.
BCDdoubler : process(Q_int)
begin
case Q_int is
when "0000" => -- Input 10s Units Result
NextQ_int <= "000"; -- 0 0 0 0
when "0001" =>
NextQ_int <= "001"; -- 1 0 2 2
when "0010" =>
NextQ_int <= "010"; -- 2 0 4 4
when "0011" =>
NextQ_int <= "011"; -- 3 0 6 6
when "0100" =>
NextQ_int <= "100"; -- 4 0 8 8
when "0101" =>
NextQ_int <= "000"; -- 5 1 0 10
when "0110" =>
NextQ_int <= "001"; -- 6 1 2 12
when "0111" =>
NextQ_int <= "010"; -- 7 1 4 14
when "1000" =>
NextQ_int <= "011"; -- 8 1 6 16
when "1001" =>
NextQ_int <= "100"; -- 9 1 8 18
when others =>
NextQ_int '-');
end case;
end process;

-- if the numbers are greater than 5, we should generate a
-- carry out (modulus out) to the next digit.
ModOutGen : process(Q_int)
begin
case Q_int is
when "0101" | "0110" | "0111" | "1000" | "1001" =>
NextModOut <= '1';
when others =>
NextModOut <= '0';
end case;
end process;

-- When Init is high, we force ModOut to 0
ModOut <= NextModOut and (not Init);
Q <= Q_int;

end;

首先,“ ‘o721 //9位八进制数 ’hAF //8位十六进制数 ”这种表述方式就不符合VHDL语法,应当是Verilog HDL的描述方式。
其次,书中欲表达的位数,是指二进制位。由于1位8进制数可以用3位二进制数来表示,所以3位八进制数721是一个9位二进制数,因为在硬件中只能存储二进制数,没法直接存储八进制数;十六进制数也同理。


一个困扰我很长时间的有关电学的问题
摩擦起电是指外部的游离电子的移动而造成的,氧化还原反应呢?是原子内部的电子发生了转移,所以摩擦起电所需要的能量比氧化还原反应要小的多,这是一种区别。还有,摩擦起电并没有形成新的化合物,只是令物体带上了电,而氧化还原反应,生成了新的物质,并且,在整个反应的过程中,物质都是显电中性的。

一个困扰我很久的关于冰糖雪梨问题 求大神解答
扭开瓶盖 一瓶盖一瓶盖喝!

困扰了我很久的问题。我想开始,却又不知道从哪里开始 从何做起。_百度...
我的建议是,还是找个信得过的女朋友吧, 找个和你差不多一样的女朋友,纯一点的,至少,得传染病的几率会小很多,而且还有可能发展成为恋人,甚至结婚。有些方面不要自卑,都是些正常现象,女孩子不一定那么难找的,只要你会交流,对她们好一些,人和人之间的感情,不光是肉体上的,只有从感情方面...

两个困扰了我很久的问题 希望大家赐教
事不过三就是说给的机会不能超过三次 但是第三次犯错的时候对方就应该有所表示 如果没有明显的改变或者诚恳的道歉 你就不必再相信他 给他第四次机会 因为你无法从他的态度中确定他是否醒悟 如果是孩子的话第三次就应该给他教训 ——让他承担所犯过错的后果 当然这些错误都是指小错误 如果是原则...

我是高中女生,我有一个困扰我很久的问题,希望可以得到帮助?
为什么不提倡早恋?因为青春期期的你们还没有完全形成自己的逻辑思维,喜欢凭着感觉走,缺少判断能力,情绪又反复,容易影响学习和身体健康。希望你早点走出来,稳定自己的情绪,反过来你也许会觉得现在的自己真是笨,会为这么一个人伤心难过。最后也希望你以后能找到一个喜欢你又能包容你的男生。

高考零分作文:红孩儿的老爸到底是不是牛魔王
看了上面这段材料,我不得不由衷地说一句,“幻想真是人类最伟大的发明和发现。”既然是伟大的东西,就要跟大家一块分享,这里谈到了孙悟空,使我不得不联想到一个困扰了我很久的问题:“红孩儿的老爸到底是不是牛魔王?”这不是脑筋急转弯,你不必煞费苦心地掐算、摆家谱,这只是我天马行空的幻想...

有个困扰了我很久的问题,gay可能会被掰直吗
很难,特别是先天性的gay,几乎是没有希望被掰直的。如果,先天的性取向是异性恋,由于后天的种种原因,迫使造成的gay,只要其本人同意,有可能会再回归到异性恋上,但是,这也是一个非常不容易的事情。大致如此。

困扰了我很久的问题。。。
不知道楼主是想要翻译还是想寻求一个合理的答案。先翻译一下楼主的句子。1. My cam does't work.2. I don't have a cam.3. Do you still wanna see me as I told you that I'm a male?4. 对不起,我怀孕了,所以我不想让你看。5. 我前男友在这,跟你视频很危险!6. I don't ...

我问一件难受困扰我很久很久的事 我这人很好胜,就是很在乎输赢,我问的...
参加,你可以趁这几个月每天训练一下,成绩会提高很多.你需要走出初二时不好体验带来的心理阴影,重拾自信,不是为了战胜想象中的对手,而是战胜自己,不能永远只跟不如自己的人比呀!紧张的时候给自己心理暗示:我要战胜自己对失败的恐惧,退缩必败无疑,我要比从前的自己更好!

一个困扰了我许久的问题,一个关于浊化的问题,非常感激各位大侠们...
],它前面有一个[s],所以被浊化为浊辅音[d],其他类似的单词也是一样,比如school[sku:l],字母组合ch应该发[k],但是它前面有一个[s],所以实际读的时候要发[g],所以虽然音标还是要写成[sku:l],但是school这个词要读成[sgu:l]其他的例如:score,space,stage,straw等,s后面的c,p,t和字母...

弋江区15025789445: 小白求教 vhdl 取整怎么写 譬如一个两位数a 怎么得到它的十位数 -
池质派得: 不太明白你说的什么意思 是要用vhdl把浮点数转换为整形么?如果是的话,举个例子,一个数据整数部分有4位,小数部分有3位 那么直接取整数部分的4位赋给一个新的寄存器就达到取整的目的了

弋江区15025789445: VHDL怎样把8位数扩展到10位数 -
池质派得: signal a : std_logic_vector(7 downto 0); signal b : std_logic_vector(9 downto 0); a<="00001111"; b<="10"&a; 使用&并置运算符 b最后等于”1000001111“

弋江区15025789445: 如果是用VHDL语言要怎么写呢?我要用VHDL语言写一个将27位的二进制转换为BCD码的程序.这个问题困扰了我好 -
池质派得: 可以参考 xilinx 的application note "Serial Code Conversion betweenBCD and Binary"http://ww...

弋江区15025789445: vhdl如何输入一个超过32位的数 -
池质派得: 我建议把大于32位的数分成2个或几个小于32位的数相加,即把大于32位的数分成2个或几个数分别存储,用到时也是分别处理,处理后的结果如果小于32位,可考虑合并,如果仍大于32位则仍分开存储. 就像把16分成10和6,要计算16/2时,分别计算10/2和6/2,结果为5和3,仍可以很好的表示8 如果是要显示,比如要显示16,可以分别显示1和6 总之多动脑筋,问题总可以解决的. 希望我能帮助到你.——Medied.Lee

弋江区15025789445: vhdl语言中如何拆分 一个三位数,要具体的程序!如 shu=123.a=1,b=2,c=3. -
池质派得: 给你个除以10的程序,只要把该三位数两次除以10,就可以拆分了!! library ieee; use ieee.std_logic_1164.all; use ieee.std_logic_unsigned.all; entity mod_10 is port(a:in std_logic_vector(7 downto 0);----输入,,,b:out std_logic_vector(4 ...

弋江区15025789445: VHDL四位共阳数码管,位选这样不对吗?我这显示每个数码管里面都有1234,求指点! -
池质派得: 看着上述的进程描述像是共阴极LED的位选.

弋江区15025789445: 用vhdl语言中如何拆分 一个三位数,要具体的程序!例如A=123,拆分为bw=1,sh=2,ge=3. -
池质派得: library ieee; use ieee.std_logic_1164.all; use ieee.std_logic_arith.all; use ieee.std_logic_unsigned.all; entity yanzhen isport (a0,a1,a2,a3: out integer range 0 to 15 ); end entity; architecture one of yanzhen isbegina0<= 1234 rem 10;a1<= (1234...

弋江区15025789445: 用VHDL语言(VerilogHDL也可)编程,实现三个8位数的比较器 -
池质派得: module ( input [7:0] in1, in2, in3,output [7:0] out1); wire [7:0] w; assign w = in1 > in2 ? in2 : in1; assign out1 = w endmodule

弋江区15025789445: VHDL的一段代码大家帮我看看什么意思,这段代码是一个32位计数器的,想知道计数器的工作原理. -
池质派得: 计数器就是数时钟上升沿的数目,0,1,10,11,100,101,110,111,1000……到32后再回到0.要改变对应引脚的频率的话,换成其它位数的计数器,比如33位的,34位的,最高的位的频率会变慢.

弋江区15025789445: vhdl发送16位数据串口程序 -
池质派得: 您好,对串行通信来说,一次发送8位还是16位数据,其实对效率影响不大,因为所有的位都是一次一位地通过介质传输的,这正是串行通信对应于并行通信的本质区别.此外串行通信需要两端使用相同的“协议”,例如规定传输速率、数据位的个数、校验方式、连续1之间的停止位长度等、流控协议等,而标准协议只支持了7位或8位数据位的传输方式,因此你希望一次传输16位数据,即没有提升性能的实际意义,实现起来也很困难.

本站内容来自于网友发表,不代表本站立场,仅表示其个人看法,不对其真实性、正确性、有效性作任何的担保
相关事宜请发邮件给我们
© 星空见康网