In short. A state machine describes a control sequence as a set of states and the exact conditions for moving between them. That makes behaviour predictable, including what happens on a timeout, a fault or a controller restart. Sequences written as loose rungs of logic often hide dead ends and conflicting outputs that only appear in a real emergency.
Who this page is for: For control engineers and programmers writing generator, transfer, shedding and restoration sequences.
Key facts
- Elements: states, transitions, guards, actions and timeouts.
- Every state has at least one exit, including a fault exit.
- Every waiting state has a timeout.
- Only one state is active at a time in a given sequence.
- Define the state after a controller restart; never resume blindly.
- Draw the diagram first; it becomes the test plan.
Elements
| Element | Meaning |
|---|---|
| State | A defined condition, such as Standby, Starting, On load, Fault |
| Transition | A move from one state to another |
| Guard | The condition that must be true for the transition |
| Action | What the controller does on entry, during or on exit |
| Timeout | Maximum time allowed in a state |
Worked example: a dead end found in review (illustrative)
A generator start sequence written as ladder rungs had these paths:
| State | Exit as written | Missing | Added |
|---|---|---|---|
| Starting | Running signal received | No exit if the engine never fires | After 3 failed crank attempts, each with a crank-time limit, to Fault (fail to start), with alarm |
| Waiting for breaker close | Breaker closed feedback | No exit if the breaker fails to close | 5 s timeout to Fault; open command issued |
| Any state | Behaviour after controller restart | Restart reads breaker and engine status and enters the matching state |
Before the change, a breaker that failed to close left the sequence waiting forever, with no alarm and the load dead. The state diagram showed the gap in minutes. See ATS and AMF logic.
Do not write a waiting state without a timeout and a fault exit. In a real outage, a sequence stuck waiting for a signal that never comes looks exactly like a dead plant.
Design rules
- Every state has at least one exit, including a fault exit.
- Every waiting state has a timeout.
- Outputs depend on the state, so conflicting commands cannot coexist.
- Faults latch until reset by a person.
- Restart behaviour is defined from actual plant status.
- States are visible on the HMI.
Link each transition to the cause-and-effect matrix.
State table
The island sequence for the same spinning mill, at plant level. The example above is one set’s own start sequence and the dead ends found in it; this is the sequence above that one, which starts four sets, forms an island on two buses, holds it and gives it back — a different machine with different states, and the place where a plant-level dead end hides. Eight states. Every one has a fault exit or is deliberately terminal, and every waiting state has a timeout.
| State | Entry action | Exit conditions | Timeout | Fault exit |
|---|---|---|---|---|
| 1. Grid parallel | Both incomers closed, all four sets stopped, shedding armed but idle | Either bus below 62 V for 500 ms, to Island forming | None. This is the steady state | None needed. Nothing is being waited for |
| 2. Island forming | Open Q1 and Q2. Start G1 to G4. Arm dead-bus priority on both buses. Inhibit the underfrequency shed | First set closed on each bus, to Building capacity | 20 s | No set on load within 20 s, to Blackout hold, with an alarm and Q5 blocked |
| 3. Building capacity | Synchronise the remaining sets one at a time. Count capacity as each breaker closes | Capacity at or above the present load, to Island stable | 90 s | Capacity still below the must-keep 380 kW at 90 s, to Shedding active with an alarm |
| 4. Island stable | Release the underfrequency shed to automatic. Report capacity, loading and which stages are off | Utility healthy on both incomers for 5 min, to Return preparation | None. This is the island steady state | Frequency below 48.5 Hz, to Shedding active |
| 5. Shedding active | Shed the next stage in order. Wait 10 s before assessing again | Frequency above 49.5 Hz held for 10 s, to Island stable | 60 s | Stage 4 shed and frequency still below 48.5 Hz, to Blackout hold |
| 6. Return preparation | Request operator confirmation. Re-check both buses and the utility on each poll | Operator confirms, to Returning | 30 min, then back to Island stable | Utility fails again at any point, to Island stable |
| 7. Returning | Open all four set breakers, let both buses go dead, close Q1 and Q2 to the dead buses, then restore shed stages in reverse order with 20 s between each | All stages restored and all four sets stopped, to Grid parallel | 10 min | Any stage fails to restore, hold there with an alarm; later stages stay off |
| 8. Blackout hold | Everything open except the must-keep contactors. Every automatic close blocked. Alarm latched | Operator reset only | None, deliberately. It waits until a person attends | Terminal. There is nowhere worse to go |
Read the two right-hand columns together and the table answers the question a state diagram exists to answer: for every state, what happens if the thing it is waiting for never arrives. Three of the eight have no timeout, and each says why in the cell — two are steady states that are not waiting for anything, and the third is waiting for a person on purpose.
A blank in either of those columns is the dead end the example above found in a single set’s sequence, and at plant level it is worse, because the sequence can be sitting in Building capacity with two sets running, the mill dark and no alarm anywhere.
State 5 is where most of the engineering went. It is entered from Island stable on underfrequency and also from Building capacity when the sets simply have not arrived in time, which means the same shedding code serves two quite different situations.
Its 10-second assessment gap is there so that one stage is given a chance to work before the next is taken — without it, a single deep dip sheds every stage in a few hundred milliseconds and the mill ends up at 380 kW when 1160 kW was supportable. The exit back to Island stable requires 49.5 Hz held for 10 seconds, deliberately above the 48.5 Hz that triggered the shed, because an exit at the same threshold is how a scheme ends up shedding and restoring in a loop.
State 7 carries the open transition that the closing permissives require, and it is the state that most often gets written as a single step. Opening the set breakers, allowing the buses to go dead and then closing the incomers is three actions with a real interruption in the middle, and the restoration of the shed stages afterwards needs 20 seconds between stages for the same reason the shedding needed 10 — 420 kW of ring frames restarting together asks for several times its running current.
A failure part way through holds where it is rather than continuing, because a sequence that presses on through a failed step is how a mill ends up half restored with nobody certain which half.
One rule is not in the table because it belongs to every row: on a controller restart the sequence reads every breaker position and every set state before it asserts a single output, and enters the state that matches what it finds. The entry actions above are written so that this is possible — each one is an instruction that can be checked against reality rather than assumed from history.
Worked example: the worst-case time through a sequence (illustrative)
Adding up the timeouts along the longest path through a state machine gives the longest time the sequence can take before it declares a fault. For a generator start and close sequence:
| State | Timeout | Running total |
|---|---|---|
| Starting: 3 cranking attempts of 10 s with 10 s rests | 3 × (10 + 10) = 60 s | 60 s |
| Running up to voltage and frequency | 15 s | 75 s |
| Synchronising | 60 s | 135 s |
| Waiting for breaker close feedback | 5 s | 140 s |
Two minutes and twenty seconds is the longest the plant can wait before this set is declared failed and the next one is called. Compare it with the UPS runtime, the shedding plan and the time the critical loads can stand. If the total is too long, the timeouts, not the hardware, are usually what needs changing: a second set can be called after the first failed crank rather than after the third.
Where the sequence goes after a controller restart
| Plant status read on restart | State entered |
|---|---|
| Engine stopped, breaker open | Standby |
| Engine running, breaker open | Running unloaded; resynchronise if required, otherwise cool down |
| Engine running, breaker closed | On load |
| Engine stopped, breaker closed | Fault: inconsistent status, open the breaker, alarm |
| Breaker position unknown | Fault: alarm and wait for a person |
The rule is to rebuild the state from what the plant is actually doing, never from what the controller remembers, because the plant may have changed while the controller was down.
The diagram is the test plan
Every transition on the diagram is a test case, and so is every timeout. A machine with eight states and fourteen transitions, six of which are timeouts, needs at least fourteen tests, each forcing one transition and checking the actions on entry and exit, plus a restart test from each state. Counting them from the diagram gives a complete plan; writing tests from memory almost always misses the fault exits, which are exactly the paths that matter in an emergency.
Make the state visible
Number and name every state, and show the active one on the HMI and in the event log, for example “G2 state 4: synchronising, 23 s of 60”. An operator who can see where each sequence is, and how long it has been there, can tell at once whether a set is slow or stuck, and an engineer reading the log after an event can follow the sequence step by step without reading the program.
Splitting large sequences
When a diagram no longer fits on one page, split it: a plant-level machine that calls each set’s own start machine, a shedding machine and a restoration machine, each with a clear interface of requests and results. Each smaller machine can be tested on its own, and the plant machine then only has to handle each sub-machine’s success, failure or timeout.
Common mistakes
- Waiting states with no timeout.
- No defined restart behaviour.
- Outputs driven from several rungs that can conflict.
- States hidden from operators.
What to send us
Send the sequence description or program and the control drawings. WhatsApp 98852 01608 or use the application engineering enquiry.
Evidence note. The example is illustrative.
Questions engineers ask
How long can a generator start sequence take in the worst case?
Add the timeouts along the longest path. Three cranking attempts of 10 s with 10 s rests is 60 s, run-up 15 s, synchronising 60 s and breaker close 5 s: 140 s before the set is declared failed. Compare this with UPS runtime and critical load tolerance, and shorten it by calling the next set after the first failed crank.
How many tests does a state machine need?
At least one for every transition on the diagram, including every timeout and fault exit, plus a restart test from each state. A machine with eight states and fourteen transitions needs at least fourteen transition tests and eight restart tests. Counting tests from the diagram gives a complete plan; tests written from memory usually miss the fault exits.
Why not simple ladder logic?
Ladder logic works well for small, independent tasks, but long sequences written as rungs hide their states, so dead ends, conflicting outputs and missing timeouts only appear in a real event. A state machine names every state and transition explicitly, which makes behaviour predictable and gives a test plan directly from the diagram.
Can a state machine be drawn from existing logic?
Yes, and it is one of the most useful reviews of an existing system. Tracing the conditions that set and reset each output usually reveals hidden states, waits without timeouts and paths with no fault exit. Draw the diagram from the logic, review it with operators, then correct and retest the gaps it shows.
How many states are too many?
If the diagram cannot be understood on one page, it is too large. Split it into sub-machines, for example a plant machine that calls each set start machine, a shedding machine and a restoration machine, each with a clear interface of requests, results and timeouts. Each can then be tested on its own.
Do generator controllers use state machines?
Yes, internally: standby, starting, warm-up, on load, cool-down and fault are states in almost every controller. When a plant controller integrates them, it needs to know those states and their timeouts, read them over the interface, and handle each controller failing or restarting, rather than assuming a start command always succeeds.
This guide gives general principles. Confirm with a project design.
Technical content reviewed by D. Srinivas Reddy, Managing Partner and Service Engineer, Reddy Generators. Last updated 8 November 2026.