Zanuark

example code

Nov 8th, 2020
189
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.25 KB | None | 0 0
  1. library IEEE;
  2. use IEEE.STD_LOGIC_1164.ALL;
  3.  
  4. -- Uncomment the following library declaration if using
  5. -- arithmetic functions with Signed or Unsigned values
  6. --use IEEE.NUMERIC_STD.ALL;
  7.  
  8. -- Uncomment the following library declaration if instantiating
  9. -- any Xilinx leaf cells in this code.
  10. --library UNISIM;
  11. --use UNISIM.VComponents.all;
  12.  
  13. entity equation is
  14. Port ( A : in STD_LOGIC;
  15. B : in STD_LOGIC;
  16. C : in STD_LOGIC;
  17. F : out STD_LOGIC;
  18. G : out STD_LOGIC;
  19. H : out STD_LOGIC);
  20. end equation;
  21.  
  22. architecture Behavioral of equation is
  23.  
  24. begin
  25.  
  26. F <= ((A AND B) XNOR (NOT(A) AND C))
  27. OR
  28. (((A AND B) OR (NOT(A) AND C)) AND (A OR (B AND NOT(C))));
  29.  
  30. G <= A OR NOT(C);
  31.  
  32. H <= (NOT(A) AND NOT(B) AND NOT(C))
  33. OR (NOT(A) AND B AND NOT(C))
  34. OR(A AND NOT(B) AND NOT(C))
  35. OR(A AND B AND NOT(C))
  36. OR (A AND B AND C)
  37. OR (A AND NOT(B) AND C);
  38.  
  39. end Behavioral;
  40.  
  41.  
  42. ______________________________________________________________________
  43. ______________________________________________________________________
  44. library IEEE;
  45. use IEEE.STD_LOGIC_1164.ALL;
  46. use IEEE.NUMERIC_STD.ALL;
  47.  
  48. entity equation_tb is
  49. -- Port ( );
  50. end equation_tb;
  51.  
  52. architecture Behavioral of equation_tb is
  53. --import model, change entity to componenet
  54. component equation is
  55. Port ( A : in STD_LOGIC;
  56. B : in STD_LOGIC;
  57. C : in STD_LOGIC;
  58. F : out STD_LOGIC;
  59. G : out STD_LOGIC;
  60. H : out STD_LOGIC);
  61. end component;
  62. -- define connections to ports
  63. signal a, b, c, f, g, h : std_logic;
  64.  
  65.  
  66. begin
  67. -- have an instance of the model being tested
  68. uut: equation port map( a => a, b => b, c=> c, f=> f, g => g, h=> h);
  69.  
  70. process
  71. -- variables to help with automation
  72. variable counter : integer := 0;
  73. variable counterslv: std_logic_vector(2 downto 0);
  74. begin
  75. -- convert integer to std_logic_vector
  76. counterslv := std_logic_vector(to_unsigned(counter, 3));
  77. --increment counter
  78. counter := counter + 1;
  79. --extract each individual input
  80. a <= counterslv(2);
  81. b <= counterslv(1);
  82. c <= counterslv(0);
  83.  
  84. wait for 20ns;
  85. end process;
  86.  
  87. end Behavioral;
Advertisement
Add Comment
Please, Sign In to add comment