entity CONV is
port (
ia, ib, ic, id, ie: in Bit;
oa, ob, oc, od, oe: out Bit
);
end CONV;
architecture BEH of CONV is
signal t: bit_vector(0 to 4);
subtype fivebit is bit_vector(0 to 4);
begin
EVALUATE:
process (ia, ib, ic, id, ie)
begin
case fivebit(ia & ib & ic & id & ie) is
when "00010" => t <= "00011";
when "00101" => t <= "00101";
when "01000" => t <= "00110";
when "01011" => t <= "01001";
when "01110" => t <= "01010";
when "10001" => t <= "01100";
when "10100" => t <= "10001";
when "10111" => t <= "10010";
when "11010" => t <= "10100";
when "11101" => t <= "11000";
when others => t <= "00000";
end case;
end process;
OUTPUT:
(oa , ob , oc , od , oe) <= t;
end architecture BEH;
表達在case語句被評估必須是以下之一:與本地靜態亞型的對象的名稱(羅素的vector_in),索引名患有局部靜態索引,一個切片名稱與本地靜態範圍,返回本地靜態子類型的函數調用,或帶有本地靜態類型標記(顯示)的限定表達式或類型轉換。
想法是分析器(本地靜態意味着分析時間)可以確定表達式中元素的數量及其類型以確定案例覆蓋率。
併發信號分配的合計目標分別將聚合元素(oa,ob,oc,od,oe)與t右側的元素(Bits)相關聯。每個元素關聯只能出現一次。
case語句包含在進程(併發語句)中,因爲它是一個順序語句。爲了防止混淆,有順序和併發信號分配語句。 VHDL使用併發語句來提供並行性。
隨着測試平臺:
entity conv_test is
end entity;
architecture test of conv_test is
signal ia, ib, ic, id, ie: bit;
signal oa, ob, oc, od, oe: bit;
signal t: bit_vector (0 to 4);
signal input: bit_vector (0 to 4);
begin
DUT:
entity work.CONV
port map (
ia => ia, ib => ib, ic => ic, id => id, ie => ie,
oa => oa, ob => ob, oc => oc, od => od, oe => oe
)
;
TEST:
process
begin
wait for 10 ns; -- bit defaults to '0', others case
(ia, ib, ic, id, ie) <= bit_vector'("00010"); -- first case
wait for 10 ns;
(ia, ib, ic, id, ie) <= bit_vector'("00101");
wait for 10 ns;
(ia, ib, ic, id, ie) <= bit_vector'("01000");
wait for 10 ns;
(ia, ib, ic, id, ie) <= bit_vector'("01011");
wait for 10 ns;
(ia, ib, ic, id, ie) <= bit_vector'("01110");
wait for 10 ns;
(ia, ib, ic, id, ie) <= bit_vector'("10001");
wait for 10 ns;
(ia, ib, ic, id, ie) <= bit_vector'("10100");
wait for 10 ns;
(ia, ib, ic, id, ie) <= bit_vector'("10111");
wait for 10 ns;
(ia, ib, ic, id, ie) <= bit_vector'("11010");
wait for 10 ns;
(ia, ib, ic, id, ie) <= bit_vector'("11101");
wait for 10 ns;
(ia, ib, ic, id, ie) <= bit_vector'("11111"); -- others case
wait for 10 ns;
wait; -- one time only
end process;
SIM_INPUT:
input <= (ia & ib & ic & id & ie); -- for ease of viewing in waveform display
RESULT:
t <= (oa & ob & oc & od & oe);
end architecture;
您可以測試CONV:
注意,測試過程可以重新編寫簡單得多分配給輸入,而不是總( ia,ib,ic,id,ie),通過使用
(ia , ib , ic , id , ie) <= input;
在SIM_INPUT聲明:
TEST:
process
begin
wait for 10 ns; -- bit defaults to '0', others case
input <= "00010"; -- first case
wait for 10 ns;
input <= "00101";
wait for 10 ns;
input <= "01000";
wait for 10 ns;
input <= "01011";
wait for 10 ns;
input <= "01110";
wait for 10 ns;
input <= "10001";
wait for 10 ns;
input <= "10100";
wait for 10 ns;
input <= "10111";
wait for 10 ns;
input <= "11010";
wait for 10 ns;
input <= "11101";
wait for 10 ns;
input <= "11111"; -- others case
wait for 10 ns;
wait; -- one time only
end process;
SIM_INPUT:
(ia, ib, ic, id, ie) <= input; -- for ease of viewing in waveform display
並獲得相同的波形顯示