Spoken like a programmer, instead of a hardware designer. Why, and how is a SWITCH-CASE any different or any more readable than an IF-THEN construct?
With the switch-case construct, you can allow for fall-thru logic, which as far as I know (but always willing to learn something new) is not possible in an if-then-else construct without the use of the goto statement. If goto was bad enough for K&R dissuade programmers from using it, I'll heed their advice. Using goto for this purpose should be avoided in favor of switch-case (that isn't to say there isn't call to use goto in C, you just need to be aware when).
Logically (aside from fall-thru), they are identical. If you know for a fact that you'll never need (now or in the future) fall-thru logic, then usage of if-then-else is perfectly reasonable. I like to keep my options always open, though, so I tend to go for the construct that is more easily expanded upon, switch-case.
Since all the State Variables, Inputs and Outputs are global to ALL states, why bother with Functions?
Mainly to keep things readable; furthermore, none of the variables need to be global - in fact, you want to localize what you can, and globalize only what is needed. This is so you could do things like nested state machines (perhaps as part of one state, you transfer operation to another state machine). Keeping all of this in functions (or as method calls within object instances, if you are going with OOP) allows easier maintenance, as well as keeping readability high of the process being performed (self-documenting code - to an extent, but properly formed comments are still important).
Its all about making code reuse as simple and natural as possible, so you don't need to re-invent the wheel for each project, as well as be able to come back to a project five years down the line and understand it easily as if it were yesterday when you last touched it.
My code is written so that it mimics the State Transition Diagram, which I always draw first before starting to code. I use '***********' to enclose the States, so it is easy to go from code to diagram and vice versa...
Well, like I said, if you don't need the fall-thru logic, and your commenting things in sections, it probably sounds ok; maybe I was a bit harsh - can you show an example of the style (nothing real, just an example)? As I said, I'm always willing to learn something new.
And you are right about me being a software developer; going on 20 years professionally starting next February - almost 30 if you count all the time prior to that as a kid in school...
I do hardware stuff in my free time; currently building a UGV (unmanned ground vehicle) in my shop. I don't have the knowledge in this domain as some others do, but I keep from burning myself with a soldering iron, mostly. I just try to impart my knowledge of software to those involved in hardware, and I hope to learn something similar from those whose passion (to the point of a career) is hardware. A cross pollination of ideas and best-practices, so to speak. I think it could ultimately make both our jobs easier, in the long run.
