Lothar M. wrote:
> That testbench will be not much longer than 20 lines of VHDL code.
Ok, skipping some blank lines...
1 | LIBRARY ieee;
|
2 | USE ieee.std_logic_1164.ALL;
|
3 |
|
4 | ENTITY tb_decoder IS
|
5 | END tb_decoder;
|
6 |
|
7 | ARCHITECTURE behavior OF tb_decoder IS
|
8 |
|
9 | COMPONENT Decoder
|
10 | PORT( a : IN std_logic_vector(2 downto 0);
|
11 | en : IN std_logic;
|
12 | f : OUT std_logic_vector(7 downto 0));
|
13 | END COMPONENT;
|
14 |
|
15 | signal a : std_logic_vector(2 downto 0) := (others => '0');
|
16 | signal en : std_logic := '1';
|
17 | signal f : std_logic_vector(7 downto 0);
|
18 |
|
19 | BEGIN
|
20 | uut: Decoder PORT MAP ( a => a, en => en, f => f);
|
21 |
|
22 | a <= "000" after 0ns, "001" after 10ns, "010" after 20ns, "011" after 30ns,
|
23 | "100" after 40ns, "101" after 50ns, "110" after 60ns, "111" after 70ns;
|
24 |
|
25 | END;
|
Simulation result: your decoder looks fine.
See the attached WF_decoder_1.png
BUT...
there are latches in the desgign: when en='0' then the last result is
stored (WF_decoder_2.png). Thats not the usual behaviour for such a
device. I would change the code in a way that the result is "00000000"
when en='0'.
1 | architecture bhv of Decoder is
|
2 | begin
|
3 | process (en,a)
|
4 | begin
|
5 | if en = '1' then
|
6 | if a="000" then f<="10000000" after 1 ps;
|
7 | elsif a="001" then f<="01000000" after 1 ps;
|
8 | elsif a="010" then f<="00100000" after 1 ps;
|
9 | elsif a="011" then f<="00010000" after 1 ps;
|
10 | elsif a="100" then f<="00001000" after 1 ps;
|
11 | elsif a="101" then f<="00000100" after 1 ps;
|
12 | elsif a="110" then f<="00000010" after 1 ps;
|
13 | else f<="00000001" after 1 ps;
|
14 | end if;
|
15 | else
|
16 | f<="00000000";
|
17 | end if;
|
18 | end process;
|
19 | end bhv;
|
The result can be seen in WF_decoder_2.png
The test bench for tha last two waveforms looks like this:
1 | :
|
2 | :
|
3 | en <= '0' after 85 ns, '1' after 115ns, '0' after 135ns, '1' after 145ns;
|
4 |
|
5 | a <= "000" after 0ns, "001" after 10ns, "010" after 20ns, "011" after 30ns,
|
6 | "100" after 40ns, "101" after 50ns, "110" after 60ns, "111" after 70ns,
|
7 | "000" after 80ns, "001" after 90ns, "010" after 100ns, "011" after 110ns,
|
8 | "100" after 120ns, "101" after 130ns, "110" after 140ns, "111" after 150ns;
|
9 | END;
|