Sections

VHDL: Johnson counter

-- ~~~~~~~~ ~~~~~~~~ ~~~~~~~~ ~~~~~~~~ ~~~~~~~~ ~~~~~~~~
-- ~ --
-- ~ Published by: www.asic-digital-design.com
-- ~ --
-- ~ Description: This is synchronous Johnson counter.
-- ~ --
-- ~~~~~~~~ ~~~~~~~~ ~~~~~~~~ ~~~~~~~~ ~~~~~~~~ ~~~~~~~~
library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_unsigned.all;
-- ~ --
entity cnt_john is
generic ( n : natural := 8 );
port (
dout : out std_logic_vector(n-1 downto 0);
clk, arst, srst, en : in std_logic );
end;
-- ~ --
architecture rtl of cnt_john is
-- declaration of signals inside this block
signal reg_john, nxt_john : std_logic_vector(n-1 downto 0);
begin

dff_john: process(arst, clk)
begin
if (arst = '1') then
reg_john <= (others => '0');
elsif (clk'event and clk = '1') then
if (srst = '1') then
reg_john <= (others => '0');
else
if (en = '1') then
reg_john <= nxt_john;
end if;
end if;
end if;
end process;

cmb_john: process(reg_john)
begin
nxt_john <= reg_john(n-2 downto 0) & NOT reg_john(n-1);
end process;

-- outputs --
dout <= reg_john;
-- ~ --
end rtl;

Sign in  |  Terms  |  Report Abuse  |  Print page  |  Powered by Google Sites