maldini
Newbie level 4
i been trying to do a Manchester Encoder using vhdl, As MOORE STate, This is my code and for a reason i am not getting it right. i suppose to get an output a 01 for input of '0' and output of 10 for input of '1'.
library ieee ;
use ieee.std_logic_1164.all;
entity SM is
port( input: in std_logic;
clock: in std_logic;
reset: in std_logic;
output : out std_logic);
end SM;
architecture Behavioral of SM is
signal next_state, current_state: std_logic_vector (2 downto 0);
begin
process(Reset,current_state)
begin
if reset = '1' then
next_state <= "000";
elsif current_state="000" then
if (input='0') then
next_state<="001"; -- output should be 01
else
next_state<="010";-- output should be 10
end if;
elsif current_state="001" then -- in=0 out 01
output<='0';
next_state<="011";
elsif current_state="011" then
output<='1';
next_state<="000";
elsif current_state="010" then -- in 1 out 10
output<='1';
next_state<="100";
elsif current_state="100" then
output<='0';
next_state<="000";
end if;
end process;
process(clock, next_state) -- update current state
begin
if (clock'event and clock = '1') then
current_state <= next_state;
end if;
end process;
end behavioral ;
library ieee ;
use ieee.std_logic_1164.all;
entity SM is
port( input: in std_logic;
clock: in std_logic;
reset: in std_logic;
output : out std_logic);
end SM;
architecture Behavioral of SM is
signal next_state, current_state: std_logic_vector (2 downto 0);
begin
process(Reset,current_state)
begin
if reset = '1' then
next_state <= "000";
elsif current_state="000" then
if (input='0') then
next_state<="001"; -- output should be 01
else
next_state<="010";-- output should be 10
end if;
elsif current_state="001" then -- in=0 out 01
output<='0';
next_state<="011";
elsif current_state="011" then
output<='1';
next_state<="000";
elsif current_state="010" then -- in 1 out 10
output<='1';
next_state<="100";
elsif current_state="100" then
output<='0';
next_state<="000";
end if;
end process;
process(clock, next_state) -- update current state
begin
if (clock'event and clock = '1') then
current_state <= next_state;
end if;
end process;
end behavioral ;