Lecture 5
Lecture 5
circuit
design using
VHDL
Dr. Fatma ElFouly
Latch
Latch
A latch is a level sensitive memory cell that is transparent to signals passing
from the D input to Q output when enabled and holds the value of D on Q at
the time when it becomes disabled.
din
dout
latch
load
load
din
dout
• library ieee;
• use ieee.std_logic_1164.all;
• use ieee.std_logic_arith.all;
• entity d_latch is
• port (din, load: in std_logic;
• dout: out std_logic);
• end entity d_latch;
• architecture rtl of d_latch is
latch • begin
• process (din, load)
• begin
• if (load = ‘1’) then
• dout <= din;
• end if;
• end process;
• end architecture rtl;
D-Type Flip Flop
D-FF rst
din
D_FF q
clk
reset
reset
Synchronous
reset
rst
D-FF Asynchronous
reset rst
din
clk
D_FF q
din clk
q
library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_arith.all;
entity d_flip_flop is
port (din, clk, rst: in std_logic;
q: out std_logic);
end entity d_flip_flop;
architecture first of d_flip_flop is
D-FF
begin
process (rst, clk)
begin
if (rst = ‘1’) then
q <= ‘0’;
elsif (rising_edge(clk)) then
q <= din;
end if;
end process;
end architecture first;
rst
D-FF Synchronous
reset rst
din
clk
D_FF q
din clk
q
library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_arith.all;
entity d_flip_flop is
port (din, clk, rst: in std_logic;
q: out std_logic);
end entity d_flip_flop;
process (clk)
begin
if (rising_edge(clk)) then
if (rst = ‘1’) then
D-FF
q <= ‘0’;
else
q <= din;
end if;
end if;
end process;
end architecture second;
Parallel Register
library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_arith.all;
entity P_reg is
port (din : in std_logic_vector(7 downto 0);
clk, rst: in std_logic;
q: out std_logic_vector(7 downto 0));
end entity P_reg;
architecture first of P_reg is
begin
process (rst, clk)
begin
P-reg
if (rst = ‘1’) then
q <= (others=>’0’);
elsif (rising_edge(clk)) then
q <= din;
end if;
end process;
end architecture first;
rst
y x q
Solved din q
y
Problem DFF
Variable clk
z
• entity circuit_1 is
• port (x,y,clk,rst: in std_logic;
• q: out std_logic);
• end entity circuit_1;
• architecture rtl of circuit_1 is
• Signal din :std_logic;
• begin
• process (clk,rst)
• begin
• if (rst =’1’)then
Variable • q <= ‘0’;
• elsif (rising_edge(clk)) then
• din <= x XOR y;
• q <= din;
• End if;
• End process;
• End rtl;
Variable
rst rst
x y
din q q
din q
dout
y
DFF DFF
clk clkclk
z
Variable
architecture rtl of circuit_1 is
begin
process (clk,rst)
variable din :std_logic;
begin
if (rst =’1’)then
q <= ‘0’;
elsif (rising_edge(clk)) then
din := x XOR y;
q <= din;
End if;
End process;
End rtl;