2013-04-10 244 views
3
library ieee; 
use ieee.std_logic_1164.all; 
use ieee.std_logic_unsigned.all; 
use ieee.std_logic_arith.all; 
use ieee.numeric_std.all; 

- 实体部分包含R代表注册VHDL - 如何将1添加到STD_LOGIC_VECTOR?

的输出
entity register_16 is 
    port( input: in std_logic_vector(15 downto 0); 
     ld, inc, clk, clr: in std_logic; 
     R: buffer std_logic_vector(15 downto 0)); 
end register_16 ; 

- 它必须平行处理在该步骤

inc_R: process (inc) 
begin 
    R <= R+'1'; 
end process inc_R; 


end behavioral ; 

architecture behavioral of register_16 is 
begin 


reg: process (input, ld, clk, clr) 
    variable R_temp : std_logic_vector(15 downto 0); 
begin 
    if (clr='1') then 
     R_temp := b"0000000000000000"; 
    elsif (clk'event and clk='1') then 
     if (ld='1') then 
      R_temp := input; 
     end if; 
    end if; 
    R <= R_temp; 
end process reg; 

- 我的错误 - 主进程(reg)正常工作 - 但其他进程有加载错误g 1.

回答

4

遗憾地说,但也有相当多的事情你的代码错误...

  1. 您在混合组合和顺序代码同样的过程,这是糟糕的编码风格。如果编码正确,那么确实不需要变量R_temp。
  2. 灵敏度列表只是一个模拟辅助工具,但您试图将它用作条件(当inc变化时,将增量R)。这在硬件中不起作用。当开始使用VHDL时,我的建议是使用VHDL_2008并始终使用process(all)作为灵敏度列表。这避免了初学者的错误,因为它反映了合成的作用。
  3. 您正在第二个过程中创建组合循环。由于上述2.这不会在模拟中显示,但会导致合成中的错误。
  4. 正如baldyHDL已经提到的,您正在将R分配给多个进程。
  5. 在处理数字时,首选无符号到std_logic_vector。通常,您不应该包含std_logic_arith,也不要包含std_logic_unsigned,只需包含std_logic_1164和numeric_std。
  6. 添加std_logic值(如'1')不是标准的,或者至少不被所有工具支持。只需用不是整数:R <= R + 1;

通过你的代码,据我了解,你试图写有增量,载入和清零信号的计数器。我不只是想给你的代码(这将毁了你的学习经历),但尽量将整个柜台融入一个单一的过程中,使用以下模板:

process(clk) begin 
    if(rising_edge(clk)) then 
     -- Your code here vvv 
     if(clr = '1') then 

     elsif(ld = '1') then 

     elsif(inc = '1') then 

     end if; 
     -- Your code here ^^^ 
    end if; 
end process; 
+0

从#6开始,“使用整数来代替”一个更好的选择是经常使用来自ieee.numeric_std的'unsigned'。这可以让你保留'std_logic'语义,并且可以让你使用'unsigned(127 downto 0)''这样的大数值,你不能用整数。 – wjl 2014-02-21 18:04:04

+1

@wjl我的意思是整数1,而不是R.OP是试图添加一个std_logic_vector和一个std_logic,这是不允许的。给定5.,可以将整数1加到R. – zennehoy 2014-02-23 16:37:45

+0

我同意这很有道理! – wjl 2014-02-23 16:51:33

0

你在你的两个进程中写入R.这导致无法综合的多驾​​驶员情况。要解决这个问题,结合过程,例如:

reg: process (clk, clr) 
    variable R_temp : std_logic_vector(15 downto 0); 
begin 
    if (clr='1') then 
     R_temp := b"0000000000000000"; 
    elsif (clk'event and clk='1') then 
     if (ld='1') then 
      R_temp := input; 
     elsif (inc='1') then 
      R_temp := R_temp + '1'; 
     end if; 
    end if; 
    R <= R_temp; 
end process reg; 
+3

我也想用'numeric_std',使'R_temp'和''R' unsigned'向量 – 2013-04-10 09:18:36

+0

我不认为R_temp和'1'之间允许加入。 – Khanh 2013-04-11 03:52:24

+0

这里不需要R_temp。它只是使过程更复杂,并导致错误。如果可能的话避免变量(并且在开始使用HDL时无条件地避免它们),因为变量会导致连续的编码思维方式,这正是HDL所不具备的。 – zennehoy 2013-04-11 08:05:25

8

你将不得不向量转换为整数再次回来,这里有一个例子:

library ieee; 
use ieee.std_logic_1164.all; 
use ieee.numeric_std.all; 

signal in : std_logic_vector(7 downto 0); 
signal out : std_logic_vector(7 downto 0); 

out <= std_logic_vector(to_unsigned(to_integer(unsigned(in)) + 1, 8)); 

有关类型转换好的图片看看这里:

http://www.bitweenie.com/listings/vhdl-type-conversion/

0

你应该能够添加包含值1,因为这一个载体,如您使用的是numeric_std库:

R <= R + x"0001";