VHDL Design: Full Adders, Half Subtractors, Multiplexers, Flip-Flops, Exercises of Engineering

VHDL code for designing digital logic circuits, including full adders, half subtractors, multiplexers, and various types of flip-flops (D, JK, T, and SR). The circuits are designed using the IEEE std_logic_1164 library.

Typology: Exercises

2018/2019

Uploaded on 10/25/2021

thuthuthu77
thuthuthu77 🇻🇳

2 documents

1 / 5

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
+ Bộ cộng 1bit
library ieee;
use ieee.std_logic_1164.all;
entity fulladder is
port(
a,b,cin : in std_logic;
sum,cout : out std_logic
);
end fulladder ;
architecture C of fulladder is
Begin
sum <= a xor b xor cin;
cout <= ( a and b ) or ( b and cin) or ( a and cin) ;
End C ;
+ Bộ cộng 4bit
library ieee;
use ieee.std_logic_1164.all;
entity fulladder4bit is
port(
A,B : in std_logic_vector(3 downto 0);
Cin : in std_logic;
Sum,Cout : out std_logic_vector(3 downto 0)
);
end fulladder4bit ;
architecture B of fulladder4bit is
component fulladder is
port(
a,b,cin : in std_logic;
sum,cout : out std_logic);
end component;
signal C: std_logic_vector(3 downto 0);
Begin
bit0: fulladder port map(A(0),B(0),Cin,Sum(0),C(0));
bit1: fulladder port map(A(1),B(1),C(0),Sum(1),C(1));
bit2: fulladder port map(A(2),B(2),C(1),Sum(2),C(2));
bit3: fulladder port map(A(3),B(3),C(2),Sum(3),C(3));
Cout <= C;
End B ;
+ Bộ trừ 1bit
+ Bộ trừ 4bit: làm giống bộ cộng
+ Mux2to1
library ieee;
use ieee.std_logic_1164.all;
pf3
pf4
pf5

Partial preview of the text

Download VHDL Design: Full Adders, Half Subtractors, Multiplexers, Flip-Flops and more Exercises Engineering in PDF only on Docsity!

+ Bộ cộng 1bit library ieee; use ieee.std_logic_1164.all; entity fulladder is port( a,b,cin : in std_logic; sum,cout : out std_logic ); end fulladder ; architecture C of fulladder is Begin sum <= a xor b xor cin; cout <= ( a and b ) or ( b and cin) or ( a and cin) ; End C ; + Bộ cộng 4bit library ieee; use ieee.std_logic_1164.all; entity fulladder4bit is port( A,B : in std_logic_vector(3 downto 0); Cin : in std_logic; Sum,Cout : out std_logic_vector(3 downto 0) ); end fulladder4bit ; architecture B of fulladder4bit is component fulladder is port( a,b,cin : in std_logic; sum,cout : out std_logic); end component; signal C: std_logic_vector(3 downto 0); Begin bit0: fulladder port map(A(0),B(0),Cin,Sum(0),C(0)); bit1: fulladder port map(A(1),B(1),C(0),Sum(1),C(1)); bit2: fulladder port map(A(2),B(2),C(1),Sum(2),C(2)); bit3: fulladder port map(A(3),B(3),C(2),Sum(3),C(3)); Cout <= C; End B ; **+ Bộ trừ 1bit

  • Bộ trừ 4bit: làm giống bộ cộng
  • Mux2to** library ieee; use ieee.std_logic_1164.all;

entity mux2to1 is port( a,b: in std_logic; s: in std_logic; f : out std_logic ); end mux2to1 ; architecture E of mux2to1 is Begin f <= (a and not(s)) or (b and s); End E ; + FF D library ieee; use ieee. std_logic_1164.all; entity dflipflop is PORT( clk,d: in std_logic; q: out std_logic); end dflipflop; architecture behavioral of dflipflop is begin process(clk) begin if(clk='1' and clk'EVENT) then Q <= D; end if; end process; end behavioral; + FF D nối tiếp 8bit

+ FF JK

library ieee; use ieee. std_logic_1164.all; entity JK_FF is PORT( J,K,CLOCK: in std_logic; Q, QB: out std_logic); end JK_FF; Architecture behavioral of JK_FF is signal TMP: std_logic; begin PROCESS(CLOCK) begin if(CLOCK='1' and CLOCK'EVENT) then if(J='0' and K='0')then TMP<=TMP; elsif(J='1' and K='1')then TMP<= not TMP; elsif(J='0' and K='1')then TMP<='0'; else TMP<='1'; end if; end if; Q<=TMP; QB <=not TMP; end PROCESS; end behavioral; + FF T library IEEE; use IEEE.STD_LOGIC_1164.ALL; entity tff is port ( T,Reset,CLOCK: in std_logic; Q: out std_logic); end tff; architecture A of tff is signal temp: std_logic; begin process (Reset,CLK) begin if Reset='0' then temp <= '0'; elsif(CLOCK='1' and CLOCK'EVENT) then temp <= T xor temp; end if; end if; end process; Q <= temp; end A; + FF SR

S R Qn-1 Q 0 0 0 0 0 0 1 1 0 1 0 0 0 1 1 0 1 0 0 1 1 0 1 1 1 1 0 X 1 1 1 x Q=(not(R) and S) or (Qn-1 and not(R)) library IEEE; use ieee.std_logic_1164.all; entity srff is port ( S,R: in std_logic; Q: out std_logic); end srff; architecture A of srff is signal temp: std_logic; begin temp <=(not(R) and S) or (temp and not(R)) Q <= temp; end A;