I am a newbie in VHDL. I am currently working on an FSM and I want my state machine to change states only when my input changes. What changes should I make in the following code?
entity fsm is
Port ( clk : in STD_LOGIC;
reset : in STD_LOGIC;
x_in : in STD_LOGIC; -- input Bitstream
y_out : out STD_LOGIC_VECTOR (1 downto 0)); -- Encoded output
end fsm;
-----------------------------------------------------
architecture Behavioral of fsm is
-- Building an Enumerated type for the state machine
type state_type is (s_idle,s1,s2,s3,s4); -- constraint length = 3, Hence number of Regs = 2 therefore Number of states = 4
signal state, next_state: state_type ; -- Registers to hold the Present and next states
begin
-----------------------------------------------------
process1: process (reset, clk) -- Sequential Logic Selection process:
begin
if (reset ='1') then
state <=s_idle;
elsif (clk='1' and x_in'Event) then
state <= next_state;
end if;
-----------------------------------------------------
end process process1;
Assuming that you want to make the FSM change state when -->
clk
is highX_in
changesAlso, I'll assume that your
next_state
variable is some combinational function ofstate
which you haven't mentioned. Just one change will suffice, addX_in
to your process sensitivity list.