|
State machine encoding (Gray, Binary and One-hot) |
|
|
|
Page 4 of 4
State Machine - One-hot encoding
library IEEE;
use IEEE.std_logic_1164.all;
use IEEE.std_logic_unsigned.all;
entity onehot is
port ( clk : in std_logic;
reset : in std_logic;
control : in std_logic;
z : out std_logic);
end onehot;
architecture BEHV of onehot is
type state is (S0,S1,S2,S3);
attribute ENUM_ENCODING :string;
attribute ENUM_ENCODING of state: type is "0001 0010 0100 1000";
signal CS,NS: state;
begin
process (clk,reset)
begin
if (reset = '1') then
CS <= S1;
elsif (clk'event and clk = '1')then
CS <= NS;
end if;
end process;
process (CS,control)
begin
NS <= S0;
z <= '0';
case CS is
when S0 =>
if (control = '1') then
NS <= S1;
z <= '0';
else
NS <= S0;
end if;
when S1 =>
if (control = '1') then
NS <= S2;
z <= '0';
else
NS <= S1;
end if;
when S2 =>
if (control = '1') then
NS <= S3;
z <= '0';
else
NS <= S2;
end if;
when S3 =>
if (control = '1') then
NS <= S0;
z <= '1';
else
NS <= S3;
end if;
when others =>
NS <= S0;
end case;
end process;
end BEHV;
Simulation output  One-hot edcoding simulation output
Synthesis output  One-hot edcoding synthesis output
<< Start < Prev 1 2 3 4 Next > End >> |