B-Matt

VHDL - Number detection

Mar 26th, 2018
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VHDL 2.39 KB | None | 0 0
  1. --- Author: Matej Arlović, 2018.
  2. --- Ponašajni numdet_and1:
  3. library IEEE;
  4. use IEEE.STD_LOGIC_1164.ALL;
  5. use IEEE.STD_LOGIC_ARITH.ALL;
  6. use IEEE.STD_LOGIC_UNSIGNED.ALL;
  7.  
  8. entity numdet_and1 is
  9.     port(
  10.             A : in STD_LOGIC;
  11.             B : in STD_LOGIC;
  12.             C : in STD_LOGIC;
  13.             Y : out STD_LOGIC
  14.         );
  15. end numdet_and1;
  16.  
  17. architecture Behavioral of numdet_and1 is
  18.  
  19. begin
  20.     Y <= A and B and C;
  21. end Behavioral;
  22.  
  23. --- Ponašajni numdet_or1:
  24. library IEEE;
  25. use IEEE.STD_LOGIC_1164.ALL;
  26. use IEEE.STD_LOGIC_ARITH.ALL;
  27. use IEEE.STD_LOGIC_UNSIGNED.ALL;
  28.  
  29. entity numdet_or1 is
  30.     port(
  31.         A: in STD_LOGIC;
  32.         B: in STD_LOGIC;
  33.         C: in STD_LOGIC;
  34.         Y: out STD_LOGIC
  35.     );
  36. end numdet_or1;
  37.  
  38. architecture Behavioral of numdet_or1 is
  39.  
  40. begin
  41.     Y <= A or B or C;
  42. end Behavioral;
  43.  
  44. --- Strukturni numdet:
  45. library IEEE;
  46. use IEEE.STD_LOGIC_1164.ALL;
  47.  
  48. entity numdet is
  49.     port(
  50.         A, B, C: in STD_LOGIC;
  51.         Y: out STD_LOGIC
  52.     );
  53. end numdet;
  54.  
  55. architecture Strukturni of numdet is
  56.  
  57. signal E, F, G: STD_LOGIC;
  58.  
  59. begin
  60.     L1: entity work.numdet_and1 port map(A, not(B), C, E);
  61.     L2: entity work.numdet_and1 port map(A, B, not(C), F);
  62.     L3: entity work.numdet_and1 port map(A, B, C, G);
  63.     L4: entity work.numdet_or1 port map(A=>E, B=>F, C=>G, Y=>Y);
  64. end Strukturni;
  65.  
  66. --- Testbench:
  67. LIBRARY ieee;
  68. USE ieee.std_logic_1164.ALL;
  69.  
  70. ENTITY numdet_w IS
  71. END numdet_w;
  72.  
  73. ARCHITECTURE behavior OF numdet_w IS
  74.     COMPONENT numdet
  75.     PORT(
  76.          A : IN  std_logic;
  77.          B : IN  std_logic;
  78.          C : IN  std_logic;
  79.          Y : OUT  std_logic
  80.         );
  81.     END COMPONENT;
  82.  
  83.    --Inputs
  84.    signal A : std_logic := '0';
  85.    signal B : std_logic := '0';
  86.    signal C : std_logic := '0';
  87.  
  88.     --Outputs
  89.    signal Y : std_logic;
  90. BEGIN
  91.    uut: numdet PORT MAP (
  92.           A => A,
  93.           B => B,
  94.           C => C,
  95.           Y => Y
  96.         );
  97.          
  98.    -- Stimulus process
  99.    stim_proc: process
  100.    begin
  101.         A <= '0';
  102.         B <= '0';
  103.         C <= '0';
  104.       wait for 100 ns;
  105.         A <= '0';
  106.         B <= '0';
  107.         C <= '1';
  108.       wait for 100 ns;
  109.         A <= '0';
  110.         B <= '1';
  111.         C <= '0';
  112.       wait for 100 ns;
  113.         A <= '0';
  114.         B <= '1';
  115.         C <= '1';
  116.       wait for 100 ns;
  117.         A <= '1';
  118.         B <= '0';
  119.         C <= '0';
  120.       wait for 100 ns;
  121.         A <= '1';
  122.         B <= '0';
  123.         C <= '1';
  124.       wait for 100 ns;
  125.         A <= '1';
  126.         B <= '1';
  127.         C <= '0';
  128.       wait for 100 ns;
  129.         A <= '1';
  130.         B <= '1';
  131.         C <= '1';
  132.       wait;
  133.    end process;
  134. END;
Add Comment
Please, Sign In to add comment