Variable in state Machine going Crazy (VHDL)

Discussion in 'Hardware' started by matrixofdynamism, Apr 8, 2010.

  1. matrixofdynamism

    matrixofdynamism

    Joined:
    Apr 8, 2010
    Messages:
    1
    OK here is the code for my state machine. I am using it to control a serial multiplier in my circuit/


    library ieee;
    use ieee.std_logic_1164.all;
    use ieee.std_logic_unsigned.all;

    entity seq_mult_stateMachine is
    port(clk, reset, start : in std_logic;
    load_multiplier, shift_multiplier, load_multiplicand : out std_logic;
    reset_product, load_product, shift_product : out std_logic;
    done : out std_logic;
    the_state : out std_logic_vector(1 downto 0); -- for debugging purpose only
    counter_out : out std_logic_vector(3 downto 0)
    );

    end entity seq_mult_stateMachine;

    architecture seq_mult_stateMachine_Architecture of seq_mult_stateMachine is
    type theStat is (S0, S1, S2, S3);
    signal present_state: theStat := S0;
    signal next_state: theStat;
    signal counter : std_logic_vector(3 downto 0);
    begin

    seq: process (clk) is
    begin
    if(rising_edge(clk)) then
    if(reset = '1') then
    present_state <= S0;
    elsif(reset = '0') then
    report "reached here";
    present_state <= next_state;
    end if;
    end if;
    end process seq;

    com: process(start, present_state) is

    begin
    load_multiplier <= '0';
    shift_multiplier <= '0';
    load_multiplicand <= '0';
    reset_product <= '0';
    load_product <= '0';
    shift_product <= '0';
    done <= '0';

    -- using signal the_state for debugging
    case present_state is
    when S0 => the_state <= "00";
    when S1 => the_state <= "01";
    when S2 => the_state <= "10";
    when S3 => the_state <= "11";
    end case;
    --

    case present_state is

    when S0 =>
    if(start = '1') then
    --Initializing
    load_multiplier <= '1';
    load_multiplicand <= '1';
    reset_product <= '1';
    counter <= "0000";
    next_state <= S1;
    else
    next_state <= S0;
    end if;

    when S1 =>
    load_product <= '1';
    counter <= counter + '1';
    next_state <= S2;

    when S2 =>
    shift_product <= '1';
    shift_multiplier <= '1';

    if(counter = "1111") then
    next_state <= S3;
    else
    next_state <= S1;
    end if;

    when S3 =>
    done <= '1';
    next_state <= S0;

    when others =>
    next_state <= S0;

    end case;
    counter_out <= counter;
    end process;

    end seq_mult_stateMachine_Architecture;

    When I implemented it, it did Not work correctly. Thus I was forced to put the_state and counter_out signals for debugging purpose. When I run the simulation in Quartus with the other blocks and put the Start input, the output is shown in the Attachment.

    Problem: My 'counter' variable goes crazy once the state S1 is entered, it keeps increasing regardless of the state being changed and finally I get the error of setup time violation. It should change ONLY when the state changes right? thats how I wrote the code.

    Please tell me why this is happening I have used I integer before but the same result.
     

    Attached Files:

    matrixofdynamism, Apr 8, 2010
    #1
    1. Advertising

  2. matrixofdynamism

    jettlee1

    Joined:
    Apr 22, 2010
    Messages:
    13
    it have error.
     
    jettlee1, Apr 27, 2010
    #2
    1. Advertising

  3. matrixofdynamism

    rvndrlt

    Joined:
    Oct 2, 2010
    Messages:
    1
    jettlee1 is clearly a brilliant person.
     
    rvndrlt, Oct 2, 2010
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. dr greg

    crazy browser go crazy

    dr greg, Jan 13, 2005, in forum: Computer Support
    Replies:
    7
    Views:
    1,156
    manno@norex.com.au
    Jan 14, 2005
  2. fotoobscura
    Replies:
    8
    Views:
    733
    fotoobscura
    Jan 12, 2008
  3. vinay.babu
    Replies:
    0
    Views:
    1,063
    vinay.babu
    Oct 16, 2008
  4. becool_nikks
    Replies:
    0
    Views:
    2,179
    becool_nikks
    Mar 6, 2009
  5. roseangamaly

    vhdl code for variable precision multiplication

    roseangamaly, Oct 4, 2010, in forum: General Computer Support
    Replies:
    0
    Views:
    1,625
    roseangamaly
    Oct 4, 2010
Loading...

Share This Page