Bu yazımda 32 bit adder(Toplayıcı) VHDL dilini kullanarak nasıl tasarlanacağını yazımda bahsedeceğim.32 Bit Adder tasarlarken Ripple-Carry Adder kullandım.
Öncelikle tam toplayıcının nasıl tasarlandığına dair linki incelemelisiniz.
Öncelikle ISE Design Suite simgesine tıklayarak açıyoruz.
Ise design’de new source(yeni kaynak) oluşturmamız gereklidir.
New Source Wizard’da dosyamızın ismini girmeliyiz. Burada öncelikle 32 Bit toplayıcımız için lazım olan tam toplaycımızı oluşturacağız. Çünkü 32 bit toplayıcı, toplamda 32 tane tam toplayıcıdan oluşmaktadır.
New Source Wizard’da Tam Toplayıcımızın Giriş ve çıkışlarının neler olacağını belirledik.
Bundan sonra gelen ekranda finish’e tıklıyoruz.
Tam Toplayıcının lojik kapılarla tasarlanmış hali. Tam Toplayıcının doğruluk tablosu.
Full Adder(Tam Toplayıcı) için VHDL dilindeki kodu
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
library IEEE; use IEEE.STD_LOGIC_1164.ALL; entity FullAdder is Port ( x : in STD_LOGIC; y : in STD_LOGIC; cin : in STD_LOGIC; cout : out STD_LOGIC; sum : out STD_LOGIC); end FullAdder; architecture Behavioral of FullAdder is begin sum <= x xor cin xor y; cout <= (x and y) or (y and cin) or (x and cin); end Behavioral; |
Tam toplayıcımız için kodumuzu yazdıktan sonra Save tıklayarak projemizi kaydedelim.
Şimdi 32 bit adder’ımızı tasarlamak için yeni kaynak (new source) oluşturmalıyız.
32 bit toplayacımız(adder) için new source wizard’da VHDL module seçelim ve dosyamızın adını kaydedelim.
32 bit toplayıcımızın giriş ve çıkışlarını belirlememiz gereklidir. Bu her bir giriş ve çıkışın kaçar bit olduğunu burada belirtmeliyiz.
32 Bit Toplayacının genel yapısı, toplamda 32 tane tam toplayıcıdan oluşmaktadır.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
library IEEE; use IEEE.STD_LOGIC_1164.ALL; entity Adder_32_bits is Port ( A : in STD_LOGIC_VECTOR (31 downto 0); B : in STD_LOGIC_VECTOR (31 downto 0); Ci : in STD_LOGIC; S : out STD_LOGIC_VECTOR (31 downto 0); Co : out STD_LOGIC); end Adder_32_bits; architecture Behavioral_artch of Adder_32_bits is component FullAdder is Port ( x : in STD_LOGIC; y : in STD_LOGIC; cin : in STD_LOGIC; cout : out STD_LOGIC; sum : out STD_LOGIC); end FullAdder; begin signal C : std_logic_vector ( 31 downto 1); FA0 : FullAdder port map ( A(0),B(0),Ci,C(1),S(0) ); FA1 : FullAdder port map ( A(1),B(1),C(1),C(2),S(1) ); FA2 : FullAdder port map ( A(2),B(2),C(2),C(3),S(2) ); FA3 : FullAdder port map ( A(3),B(3),C(3),C(4),S(3) ); FA4 : FullAdder port map ( A(4),B(4),C(4),C(5),S(4) ); FA5 : FullAdder port map ( A(5),B(5),C(5),C(6),S(5) ); FA6 : FullAdder port map ( A(6),B(6),C(6),C(7),S(6) ); FA7 : FullAdder port map ( A(7),B(7),C(7),C(8),S(7) ); FA8 : FullAdder port map ( A(8),B(8),C(8),C(9),S(8) ); FA9 : FullAdder port map ( A(9),B(9),C(9),C(10),S(9) ); FA10 : FullAdder port map ( A(10),B(10),C(10),C(11),S(10) ); FA11 : FullAdder port map ( A(11),B(11),C(11),C(12),S(11) ); FA12 : FullAdder port map ( A(12),B(12),C(12),C(13),S(12) ); FA13 : FullAdder port map ( A(13),B(13),C(13),C(14),S(13) ); FA14 : FullAdder port map ( A(14),B(14),C(14),C(15),S(14) ); FA15 : FullAdder port map ( A(15),B(15),C(15),C(16),S(15) ); FA16 : FullAdder port map ( A(16),B(16),C(16),C(17),S(16) ); FA17 : FullAdder port map ( A(17),B(17),C(17),C(18),S(17) ); FA18 : FullAdder port map ( A(18),B(18),C(18),C(19),S(18) ); FA19 : FullAdder port map ( A(19),B(19),C(19),C(20),S(19) ); FA20 : FullAdder port map ( A(20),B(20),C(20),C(21),S(20) ); FA21 : FullAdder port map ( A(21),B(21),C(21),C(22),S(21) ); FA22 : FullAdder port map ( A(22),B(22),C(22),C(23),S(22) ); FA23 : FullAdder port map ( A(23),B(23),C(23),C(24),S(23) ); FA24 : FullAdder port map ( A(24),B(24),C(24),C(25),S(24) ); FA25 : FullAdder port map ( A(25),B(25),C(25),C(26),S(25) ); FA26 : FullAdder port map ( A(26),B(26),C(26),C(27),S(26) ); FA27 : FullAdder port map ( A(27),B(27),C(27),C(28),S(27) ); FA28 : FullAdder port map ( A(28),B(28),C(28),C(29),S(28) ); FA29 : FullAdder port map ( A(29),B(29),C(29),C(30),S(29) ); FA30 : FullAdder port map ( A(30),B(30),C(30),C(31),S(30) ); FA31 : FullAdder port map ( A(31),B(31),C(31),Co,S(31) ); end Behavioral_artch; |
32 bit toplayacı için yazdığımız kodumuz kaydetmeliyiz.
Dosyamızı kaydettikten sonra kodumuzu derlemeliyiz.
Şimdi kodumuz doğru olduğuna göre sıra geldi kodumuzu simülasyon aracılığıyla doğru olup olmadığını denetleyeceğiz.
VHDL Test Bench ile kodumuzun çalışabilirliğini denetleyeceğiz.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 |
-------------------------------------------------------------------------------- -- Company: -- Engineer: -- -- Create Date: 19:26:55 12/24/2014 -- Design Name: -- Module Name: D:/fpga calismalari/addersubractor/adder_32_bit_adder.vhd -- Project Name: addersubractor -- Target Device: -- Tool versions: -- Description: -- -- VHDL Test Bench Created by ISE for module: Adder_32_bits -- -- Dependencies: -- -- Revision: -- Revision 0.01 - File Created -- Additional Comments: -- -- Notes: -- This testbench has been automatically generated using types std_logic and -- std_logic_vector for the ports of the unit under test. Xilinx recommends -- that these types always be used for the top-level I/O of a design in order -- to guarantee that the testbench will bind correctly to the post-implementation -- simulation model. -------------------------------------------------------------------------------- LIBRARY ieee; USE ieee.std_logic_1164.ALL; -- Uncomment the following library declaration if using -- arithmetic functions with Signed or Unsigned values --USE ieee.numeric_std.ALL; ENTITY adder_32_bit_adder IS END adder_32_bit_adder; ARCHITECTURE behavior OF adder_32_bit_adder IS -- Component Declaration for the Unit Under Test (UUT) COMPONENT Adder_32_bits PORT( A : IN std_logic_vector(31 downto 0); B : IN std_logic_vector(31 downto 0); Ci : IN std_logic; S : OUT std_logic_vector(31 downto 0); Co : OUT std_logic ); END COMPONENT; --Inputs signal A : std_logic_vector(31 downto 0) := (others => '0'); signal B : std_logic_vector(31 downto 0) := (others => '0'); signal Ci : std_logic := '0'; --Outputs signal S : std_logic_vector(31 downto 0); signal Co : std_logic; -- No clocks detected in port list. Replace <clock> below with -- appropriate port name constant period : time := 10 ns; BEGIN -- Instantiate the Unit Under Test (UUT) uut: Adder_32_bits PORT MAP ( A => A, B => B, Ci => Ci, S => S, Co => Co ); -- Stimulus process stim_proc: process begin A <= "10101001101010101010001010101011"; B <= "10101001101010101010001010101010"; Ci <= '0'; wait; end process; END; |
Sonuç simülasyonunda A ve B’yi elle toplarsak sonucun doğru olduğunu gözlemleriz.