Chapter8 - VHDL - Sequential Circuits
Chapter8 - VHDL - Sequential Circuits
VHDL
Hardware Description Language
To satisfy the timing constraints of the FFs, the clock period must be
large enough to accommodate the propagation delay of the next-state
logic, the clock-to-q delay of the FFs and the setup time of the FFs.
);
end dlatch;
library ieee;
use ieee.std_logic_1164.all;
entity dff_en is
port(
clk: in std_logic;
reset: in std_logic;
en: in std_logic;
d: in std_logic;
q: out std_logic
);
end dff_en;
library ieee;
use ieee.std_logic_1164.all;
entity shift_register is
port(
clk, reset: in std_logic;
ctrl: in std_logic_vector(1 downto 0);
d: in std_logic_vector(3 downto 0);
q: out std_logic_vector(3 downto 0)
);
end shift_register;
architecture two_seg_arch of shift_register is
signal r_reg: std_logic_vector(3 downto 0);
signal r_next: std_logic_vector(3 downto 0);
Begin
-- next-state logic
with ctrl select
r_next <= r_reg when "00", --no op
r_reg(2 downto 0) & d(0) when "01", --shift left;
d(3) & r_reg(3 downto 1) when "10", --shift right;
d when others;
entity arbi_seq_counter4 is
port(
clk, reset: in std_logic;
q: out std_logic_vector(2 downto 0)
);
end arbi_seq_counter4;
entity binary_counter4_feature is
port(
clk, reset: in std_logic;
syn_clr, en, load: in std_logic;
d: in std_logic_vector(3 downto 0);
q: out std_logic_vector(3 downto 0)
);
end binary_counter4_feature;
architecture two_seg_arch of
binary_counter4_feature is
signal r_reg: unsigned(3 downto 0);
signal r_next: unsigned(3 downto 0);
begin
-- register
process(clk,reset)
begin
if (reset='1') then
-- next-state logic
r_reg <= (others=>'0');
r_next <= (others=>'0') when syn_clr='1’
elsif (clk'event and clk='1') then
else
r_reg <= r_next;
unsigned(d) when load='1' else
end if;
r_reg + 1 when en ='1' else
end process;
r_reg;
-- output logic
q <= std_logic_vector(r_reg);
end two_seg_arch;
The key to this design is the next_state logic. When the counter reaches 9, as indicated
by the condition r_reg=(TEN-1), the next value will be 0. Otherwise, the next value will
be incremented by 1.
When the counter reaches m - 1, the next state should be 0. Our first
design is based on this observation. The VHDL code is similar to the
decade counter except that we need to replace the r_reg=(TEN-1)
condition of the next-state logic with r_reg=(unsigned(m)-1).
ANY QUESTIONS??