0

I am currently writing my first FSM and am unsure of if I have the logic correct. I am tasked with creating a state diagram for the following logic:

A = 00
B = 01
C = 10
D = 11

Output is 1 when:

BDA
BAA
BAD

So I created the following vhdl code to accomplish this:

So every time I get it to output 1 I send it back to B and make count + 1. This is supposed to display on the LED as the number of times it is found in an 18 bit sequence.

Did I approach this in the correct way? I am confused on how I move it through the 18 bit sequence. I am supposed to us the swtiches on the board as my 18 bits which is represented as SW. Would I replace data_in with SW(17 downto 0)?

2
  • State diagram appears to have a different meaning for some or are you simply not showing us yours? There are no character literals '00', '11', or '10'. Note that data is a single element std_logic. There is no "+" operator available based on your context clause and additional use clause. You're asking for a critique on an execution environment (e.g. testbench) that isn't in evidence from your non functional source code. Your VHDL design description doesn't convey sufficient information for what you are asking.
    – user1155120
    Mar 9, 2014 at 21:51
  • @David Koontz Okay, Is there a way to make the 18 bits into 9 - 2 bit entries that I can test to make it correct? Maybe using a shift register? Also what would I make count then to have it be a count? Mar 9, 2014 at 22:06

1 Answer 1

0

This is a comment not an answer I putting it in answer as I am not eligible to comment yet.

I think you have some problem in FSM concepts. Also as in the comment said data_in is std_logic not a vector. you are taking input serially one bit at a time so accordingly write the processes. you can write code to detect the sequences BDA, BAA, BAD that is sequences "011100","010000" and "010011". I would write a simple FSM code so that you can clear you concepts then you can try.

library ieee;
use IEEE.std_logic_1164.all;

entity mealy is
port (clk : in std_logic;
      reset : in std_logic;
      input : in std_logic;
      output : out std_logic
  );
end mealy;

architecture behavioral of mealy is

type state_type is (s0,s1,s2,s3);  --type of state machine.
signal current_s,next_s: state_type;  --current and next state declaration.

begin

process (clk,reset)
begin
 if (reset='1') then
  current_s <= s0;  --default state on reset.
elsif (rising_edge(clk)) then
  current_s <= next_s;   --state change.
end if;
end process;

--state machine process.
process (current_s,input)
begin
  case current_s is
     when s0 =>        --when current state is "s0"
     if(input ='0') then
      output <= '0';
      next_s <= s1;
    else
      output <= '1';
      next_s <= s2;
     end if;   

     when s1 =>;        --when current state is "s1"
    if(input ='0') then
      output <= '0';
      next_s <= s3;
    else
      output <= '0';
      next_s <= s1;
    end if;

    when s2 =>       --when current state is "s2"
    if(input ='0') then
      output <= '1';
      next_s <= s2;
    else
      output <= '0';
      next_s <= s3;
    end if;


  when s3 =>         --when current state is "s3"
    if(input ='0') then
      output <= '1';
      next_s <= s3;
    else
      output <= '1';
      next_s <= s0;
    end if;
  end case;
end process;

end behavioral;

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.