2013-04-10 33 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";