This website uses cookies. By using this site, you consent to the use of cookies. For more information, please take a look at our Privacy Policy.
Home > FPGA Technical Tutorials > Design Recipes for FPGAs Using Verilog and VHDL > Finite State Machines in VHDL and Verilog > Implementing Finite State Machines in VHDL

TABLE OF CONTENTS

Xilinx FPGA FPGA Forum

Implementing Finite State Machines in VHDL

FONT SIZE : AAA

This transition diagram can be implemented using a case statement in a process using the following VHDL:

library ieee;

use ieee.std_logic_1164.all;

entity fsm is

port(

Hardware state machine structurepng

Figure 22.1 Hardware state machine structure.

State transition diagrampng

Figure 22.2 State transition diagram.

clk, rst, choice : in std_logic;

count : out std_logic

);

end entity fsm;

architecture simple of fsm1 is

type state_type is ( s0, s1, s2, s3 );

signal current, next_state : state_type;

begin

process ( clk )

begin

if ( clk = 1 ) then

current <= next_state;

end if;

end process;

process ( current )

begin

case current is

when s0 =>

out <= 0;

if ( rst = 1) then

next <= s1;

else

next <= s0;

end if;

when s1=>

out <= 1;

if ( choice = 1) then

next <= s3;

else

next <= s2;

end if;

when s2=>

out <= 2;

next <= s0;

when s3=>

out <= 3;

next <= s0;

end case;

end process;

end;

It must be noted that not all state machines will neatly have a number of states exactly falling to a power of 2, and so unused states must also be managed using the “when-others” approach described elsewhere in this book.

It is also the case that the two processes can be combined into a single process, which can reduce the risk of glitches being introduced by the synthesis tools, especially from incorrect assignments. It can also make debugging simpler.


  • XC2V2000-5BFG957C

    Manufacturer:Xilinx

  • FPGA Virtex-II Family 2M Gates 24192 Cells 750MHz 0.15um Technology 1.5V 957-Pin FCBGA
  • Product Categories:

    Lifecycle:Obsolete -

    RoHS:

  • XC2V2000-5FF896I

    Manufacturer:Xilinx

  • FPGA Virtex-II Family 2M Gates 24192 Cells 750MHz 0.15um Technology 1.5V 896-Pin FCBGA
  • Product Categories: FPGAs

    Lifecycle:Obsolete -

    RoHS: No RoHS

  • XC4003E-4VQ100C

    Manufacturer:Xilinx

  • FPGA XC4000E Family 3K Gates 238 Cells 0.35um Technology 5V 100-Pin VTQFP
  • Product Categories: FPGAs (Field Programmable Gate Array)

    Lifecycle:Obsolete -

    RoHS: No RoHS

  • XC5VLX110T-1FFG1136CS1

    Manufacturer:Xilinx

  • FPGA Virtex-5 LXT Family 110592 Cells 65nm Technology 1V 1136-Pin FCBGA
  • Product Categories:

    Lifecycle:Obsolete -

    RoHS:

  • XC5VLX110T-2FF1738C

    Manufacturer:Xilinx

  • FPGA Virtex-5 LXT Family 110592 Cells 65nm Technology 1V 1738-Pin FCBGA
  • Product Categories: FPGAs (Field Programmable Gate Array)

    Lifecycle:Active Active

    RoHS: No RoHS

Need Help?

Support

If you have any questions about the product and related issues, Please contact us.