A state machine is any object that behaves different based on its history and current inputs.  Many embedded systems consist of a collection of state machines at various levels of the electronics or software.

Barr Group CTO and software expert Michael Barr gives a brief introduction on the concept of state machines for embedded systems.

Related Articles

Introduction to Hierarchical State Machines (HSMs)

How to Code a State Machine in C or C++

Related Courses

Reliable Multithreaded Programming

Event Driven Programming and State Machines

Hardware-Software Partitioning in Embedded Systems (Webinar)


Andrew Girson: Hi everyone. I'm Andrew Girson, Barr Group CEO and I'm here today with Michael Barr our co-founder and CTO. We're here today to talk about state machines.

So Mike, I've talked to a lot of our training and consulting customers and quite often the concept of state machines comes up.  So, what exactly are state machines?

Michael Barr: Well, state machines are in a nutshell just portions of a system that behave differently depending on the things that have happened in the past.

An example that like is of a soda machine. When you go up to the soda machine, it's not yet willing to take your order for a particular brand of soda. You've got to put money in first--you got to change its internal state so that it'll behave differently and give you a soda.

If one day you were to walk up to a soda machine and the person in front of you put money in, but they hadn't gotten a soda out, it would still be waiting for an order and it might reject your money it might confuse you because you would expect it to be a different behavior. So that's an example of the state machine.

Andrew: Okay. And why are state machines important in embedded systems design?

Michael: Well, as embedded developers both developers of electronics as well as software, state machines are a part and parcel of the job.

Sometimes they're just a small, you know, maybe tracking with some global variables or some local variables, a state of information about what's going on in the system or a part of the system. But sometimes it's very complicated hierarchical state machines that where the whole system is interacting as a group of state machines that are all interacting with each other.

And the reason it's important is because embedded developers should know that there are good best practices for implementing state machines and there are also really complicated ways that will screw you up. One of the ways you can find out about those best practices is in articles on our website that talk about state machines.

Andrew: Okay. Thanks.

Michael: Thank you.