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 > Programming FPGAs Getting Started with Verilog > Timer Example > State Machines

State Machines

FONT SIZE : AAA

State machines have their roots in mathematics and, therefore, like many things in  math, sound really clever but are actually pretty simple when it comes down to it.  You will also find state machines and drawings of state machines being called  finite state machines (FSMs) and state transition diagrams (somewhat unfortunately STDs).

The basic concept is that a system stays in a stable state until some trigger causes  it to transition to another state. This transition might cause some actions to occur  during the transition. States are drawn on a diagram as boxes or bubbles and transitions as lines with arrows that go either from one box to another or from one box back to itself. The transition lines are drawn with a two-part label on them. The top  part of the label is the condition for the transition to occur (say, a button being  pressed), and then there is a horizontal line, and under the line appear any actions  that need to take place during the transition (say, turn a LED on).

There are, of course, other ways of drawing state machines, but this is probably  the most common. Figure 6-1 shows the state machine for a fictional coffee maker.  It is assumed that the coffee maker has two heating elements, a boiling element  and a warming element, with the warming element keeping a hotplate and the  coffee warm.

The dot and first transition line indicate the starting state for the machine  when it is first turned on, in this case the “Idle” state. The coffee maker will stay in  this state until the “Start” button is pressed, at which point the boiling and warming elements will be turned on, and the machine will be in the “Brewing” state  until the water reservoir is empty, at which point the power to the heating element  will be turned off and the state of the machine will be in the “Keeping Warm”  state. At any point, the user can press the “Cancel” button, which will turn off the  heating elements and return the machine to its “Idle” state.

This example is very straightforward, and by following the transitions around  the diagram, you can get a good feel for how the system will operate in practice.  You could also think up other scenarios that could be dealt with—perhaps an  “Error” state that is entered if the water reservoir is empty before “Start” is  pressed. The condition for such a transition might be “Start pressed AND water  reservoir empty.”

The state machine for a coffee makerpng

Drawing State Machines

I find that hand drawing a state machine on the traditional “back of an  envelope” or even a whiteboard is easier than using software, although  if you find that you might be returning to the design in the future, you  may want to scan or photograph the state machine and save it in the  project folder for future reference.

  • XC3S400-5TQ144I

    Manufacturer:Xilinx

  • Xilinx QFP-144
  • Product Categories:

    Lifecycle:Any -

    RoHS: -

  • XC2S50-6FGG256C

    Manufacturer:Xilinx

  • FPGA Spartan-II Family 50K Gates 1728 Cells 263MHz 0.18um Technology 2.5V 256-Pin FBGA
  • Product Categories: FPGAs

    Lifecycle:Active Active

    RoHS:

  • XCR5128-10PC84C

    Manufacturer:Xilinx

  • CPLD CoolRunner Family 4K Gates 128 Macro Cells 0.5um Technology 5V 84-Pin PLCC
  • Product Categories: Industrial components

    Lifecycle:Obsolete -

    RoHS: No RoHS

  • XC5206-3PQ160C

    Manufacturer:Xilinx

  • FPGA XC5200 Family 10K Gates 784 Cells 83MHz 0.5um Technology 5V 160-Pin PQFP
  • Product Categories:

    Lifecycle:Obsolete -

    RoHS: No RoHS

  • XC2C256-6PQ208C

    Manufacturer:Xilinx

  • CPLD CoolRunner -II Family 6K Gates 256 Macro Cells 256MHz 0.18um Technology 1.8V 208-Pin PQFP
  • Product Categories: CPLDs

    Lifecycle:Active Active

    RoHS: No RoHS

Need Help?

Support

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