Demo entry 6354610

   

Submitted by anonymous on Apr 09, 2017 at 18:20
Language: vhdl. Code size: 2.1 kB.

library IEEE;
use IEEE.STD_LOGIC_1164.ALL;

-- Uncomment the following library declaration if using
-- arithmetic functions with Signed or Unsigned values
--use IEEE.NUMERIC_STD.ALL;

-- Uncomment the following library declaration if instantiating
-- any Xilinx leaf cells in this code.
--library UNISIM;
--use UNISIM.VComponents.all;

entity C is
    Port ( clk : in STD_LOGIC;
           start : in STD_LOGIC;
           M : in STD_LOGIC;
           
           load : out STD_LOGIC;
           shift : out STD_LOGIC;
           add : out STD_LOGIC;
           done : out STD_LOGIC);
end C;

architecture Behavioral of C is

type state is (s0,s1,s2,s3,s4);
signal currentstate,nextstate:state;

begin

process(clk)
begin
    currentstate<=s0;
    if (clk'event =true and clk='1') then
        currentstate<=nextstate;
    end if;
end process;

process(currentstate,start,M)
variable count:integer:=0;
begin
    case currentstate is
        when s0 =>
            if start='1' then
                load<='1';
                shift<='0';
                add<='0';
                done<='0';
                nextstate<=s1;
            end if;
        when s1 =>
            if M='1' then
                nextstate<=s2;
            else
                nextstate<=s3;    
            end if;
        when s2 =>
            add<='1';
            load<='0';
            shift<='0';
            nextstate<=s3;
        when s3 =>
            count:=count+1;
            add<='0';
            load<='0';
            shift<='1';
            if count<4 then
                if M='1' then
                    nextstate<=s2;
                else
                    nextstate<=s3;
                end if;
            else
                nextstate<=s4;
                count:=0;
            end if;
        when s4 =>
            done<='1';
            shift<='0';
            add<='0';
            load<='0';
            nextstate<=s0;
            
    end case;
end process;

end Behavioral;

This snippet took 0.01 seconds to highlight.

Back to the Entry List or Home.

Delete this entry (admin only).