FSM(Finite state machine) help

This is a discussion on FSM(Finite state machine) help within the C++ Programming forums, part of the General Programming Boards category; hi, I have not used FSM before and need to learn it asap. there are many tutorials which give concepts ...

  1. #1
    Registered User
    Join Date
    May 2011
    Posts
    44

    FSM(Finite state machine) help

    hi,
    I have not used FSM before and need to learn it asap. there are many tutorials which give concepts or give vhdl code. can anyone suggest
    me 2,3 examples/links which not only explain theory but also give C++/C code(simple code). I really need help.


    thanks
    sedy

  2. #2
    Registered User
    Join Date
    Apr 2006
    Posts
    2,050
    Well you need to understand the concept, which means looking at and understanding state graphs.

    As to how to code them, that's up to you. There are many ways to represent state in C++ you can get really fancy and write functions that returns function pointers, use polymorphic objects that return the next state, or just have an integer represent the state, and use a big switch statement inside a loop. There are pros and cons to those approaches, and to others.

    VHDL procedural state machines are essentially a big switch (or a bunch of if elsif). However, there there is always a performance priority and a compiler can be relied on to optimize the logic. It's not always the same situation in C++, though switches are relatively fast, if that's your benchmark.
    It is too clear and so it is hard to see.
    A dunce once searched for fire with a lighted lantern.
    Had he known what fire was,
    He could have cooked his rice much sooner.

  3. #3
    Registered User
    Join Date
    May 2011
    Posts
    44
    hi mir,
    so would u suggest any web source or book?

    sedy

  4. #4
    Registered User
    Join Date
    Apr 2006
    Posts
    2,050
    No. As you say there are plenty of web sources that explain the concept of an FSM. There is no universally preferred way to implement them in C++. There are tutorials on switches and function pointers if you can determine which of those is appropriate to a particular situation. How many states you have and how similar those states are can help determine that, since usually you want to minimize code repetition.

    Understanding FSMs and programming them are separate problems. You should understand FSMs and understand C++. Then put the two together.

    The vhdl tutorials aren't useless either; you can treat vhdl like pseudocode. A vhdl process isn't very different from a procedural code block in C++. Although a massive if elsif chain is generally not a good solution in C++.
    Last edited by King Mir; 11-07-2011 at 03:25 PM.
    It is too clear and so it is hard to see.
    A dunce once searched for fire with a lighted lantern.
    Had he known what fire was,
    He could have cooked his rice much sooner.

  5. #5
    Registered User
    Join Date
    May 2011
    Posts
    44
    thanks

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 6
    Last Post: 04-24-2011, 11:56 AM
  2. Main loop of the Finite State Machine
    By makonikor in forum C Programming
    Replies: 3
    Last Post: 11-18-2010, 10:54 PM
  3. spell checker using finite state machine
    By DurellP in forum C++ Programming
    Replies: 5
    Last Post: 03-13-2010, 01:00 AM
  4. Finite State Machine
    By ArlexBee-871RBO in forum C++ Programming
    Replies: 8
    Last Post: 07-14-2008, 11:59 AM
  5. Finite State Machine Project Help
    By ryanbradley in forum C++ Programming
    Replies: 4
    Last Post: 03-06-2004, 09:23 AM

Tags for this Thread


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21