簡體   English   中英

vhdl比較向量輸出

[英]vhdl comparing vector output

我有一個向量A,它的長度為64位,我希望輸出B等於3,而A為30-35,在其他地方為零。 我無法弄清楚測試台如何循環通過向量A。 我嘗試了幾種不同的方法,但只得到數組的1/5來提供所有輸出。 據我所知,這沒有語法/編譯錯誤。

主要代號

library IEEE;
use IEEE.STD_LOGIC_1164.all;     
use IEEE.NUMERIC_STD.ALL;

entity ent is
port(A:in std_logic_vector(5 downto 0);
     B:out std_logic_vector(3 downto 0));
end ent;

architecture arch_ent of ent is
begin               
with A select
B <= "0011" when "011110",
      "0011" when "011111", 
      "0011" when "100000",
      "0011" when "100001",
      "0011" when "100010",
      "0011" when "100011",
      "0000" when others;       
end arch_ent;

試驗台

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

entity tb is
end tb;

architecture arch_tb of tb is

component ent 
port(A:in std_logic_vector(5 downto 0);
B:out std_logic_vector(3 downto 0));
end component;

signal A_tb: std_logic_vector(5 downto 0);
signal B_tb: std_logic_vector(3 downto 0);

begin
uut: entity ent port map(A=>A_tb, B=>B_tb);
tb: process 
constant period: time := 20ns;
begin
for i in A_tb'range loop
    A_tb <= std_logic_vector(to_unsigned(i,6));
    wait for period;
    assert (B_tb = "0011") 
    report "test failed" severity error; 
end loop;   
wait;
end process;  
end arch_tb;

最后,我試圖繪制這樣的波形: http : //i10.photobucket.com/albums/a142/blargonblop/wave.png

其中A會轉到63,並且每個輸出都是30-35之間的正確值,而其他位置為0

用於指定“測試”數量的循環參數是A_tb'范圍,恰好是5到0,或6個測試,i依次被分配為5,4,3,2,1和0。

您想要i in 0 to 2**A-tb'length-1指定i in 0 to 2**A-tb'length-1i in 0 to 63指定i in 0 to 2**A-tb'length-1以獲取所有64個可能的A_tb'binary'值。

(A_tb'length = 6,2 ** 6-1 = 63,其中**是冪運算符,2等於6的冪減去1等於63)

我在測試台中發現了兩個語法錯誤,即20ns,其中標准要求20到ns之間的空格:

    constant period: time := 20 ns;

而實體ent應該只是ent(您有一個組件聲明ent)或實體work.ent,而無需組件聲明:

uut: ent port map(A=>A_tb, B=>B_tb);

要么

uut: entity work.ent port map(A=>A_tb, B=>B_tb);

而且,與羅素的答案保持一致,除了通過綜合(通過並行化邏輯(復制)解開循環迭代)的合成之外,循環中沒有隱含的邏輯復制。 並非所有循環語句都旨在用作綜合目標。

測試台通常不進行合成,而是用於編寫可能用作合成目標的VHDL模型的測試(如您的情況)。

您確實不應該為此使用for循環。 VHDL中的for循環用於REPLICATE LOGIC,而不是多次執行操作。 在測試台上嘗試以下操作:

signal r_CLOCK : std_logic := '0';
signal r_INDEX : unsigned(5 downto 0) := (others => '0');

begin

  r_CLOCK <= not r_CLOCK after period/2;

  process (r_CLOCK)
  begin
    if rising_edge(r_CLOCK) then
      r_INDEX <= r_INDEX + 1;
    end if;
  end process;

現在,只需將r_INDEX轉換為std_logic_vector並將其傳遞給您的ent組件。

首先,循環在測試平台中是正常的並且很常見。 @Russell的注釋適用於RTL代碼。 您可以采用他的方法來解決此問題並使之起作用。 您將需要使用64作為前哨(結束)值,然后結束測試。 請記住,盡管您要做的最重要的事情是代碼的可讀性。 測試用例通常一次從流程的頂部到底部運行。

除了@DavidKoontz提供的建議之外,您的循環還有一些問題。 特別,

  • 當您期望B為0時,不應檢查您的斷言。
  • 使用numeric_std_unsigned(需要VHDL-2008編譯開關)將簡化轉換。
  • 保持錯誤計數,以便最后報告通過或失敗。
  • 將常量保持在體系結構或程序包中

因此,修改后的代碼為:

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

entity tb is
end tb;

architecture arch_tb of tb is
  constant period: time := 20 ns;
...
begin
...

tb: process 
  variable ErrorCount : 
begin
  for i in i in 0 to 2**A-tb'length-1
    A_tb <= to_slv(i,6);
    wait for period;
    if i >= 30 and i <= 35 then 
      if B_tb /= 3 then 
        ErrorCount := Error Count + 1 ; 
        report "B_tb = " & to_string(B_tb) & "  Expecting: 0011" severity ERROR ; 
      end if; 
    else 
      if B_tb /= 0 then 
        ErrorCount := Error Count + 1 ; 
        report "B_tb = " & to_string(B_tb) & "  Expecting: 0000" severity ERROR ; 
      end if; 
  end loop;   
  if ErrorCount = 0 then 
    report "Test Passed" severity NOTE ; 
  else
    report "Test FAILED.  There were " & to_string(ErrorCount) & " Errors " severity NOTE; 
  end if; 
  std.env.stop(0) ; -- testbench stops here
end process; 

請注意,有關使用(或禁止使用)numeric_std_unsigned的規則不適用於測試平台。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM