Skip to content

Statecharts, one tick at a time

SCCharts is a statechart language for reactive systems, such as the controllers inside embedded devices: you write states and transitions, and the chart reacts to its inputs in discrete ticks, the same way every time.

This guide teaches it with charts you can run right here in the page.

ToggleLive chart

Diagram

Diagram of ToggleStates: Off (initial), On. Transitions: Off to On: button / light = true; On to Off: button / light = false.Toggleinput boolbuttonoutput boollight = falseOffOnbutton/ light = truebutton/ light = false

Code

scchart Toggle {
input bool button
output bool light = false
initial state Off
if button do light = true go to On
state On
if button do light = false go to Off
}
Tick 7
Inputs for tick 8 Boolean input: true while on. It keeps its value until you change it.
Timing diagram of Toggle
Tickinput bool buttonoutput bool lightActive state of the chart
Tick 1falsefalseOff
Tick 2truetrueOn
Tick 3falsetrueOn
Tick 4falsetrueOn
Tick 5truefalseOff
Tick 6falsefalseOff
Tick 7, showntruetrueOn
Click a tick to show it, or use the Left and Right arrow keys to go back and step.

button is true again: Off to On fires and light is true.

Your turn: switch button on or off, then press Step. An input keeps its value until you change it.

What you’ll learn

Twelve chapters, read in order. Each one introduces a construct with a chart you can run, states the rule exactly, shows the mistakes beginners make, and ends with exercises.

After that, Going further covers the rest of the language and Patterns works through complete charts.

  1. Chapter 1: Thinking in ticksA chart runs in ticks: it reads its inputs, reacts in no time at all, and writes its outputs, the same way every time.
  2. Chapter 2: Your first SCChartWrite a complete chart from an empty file, read its diagram, run it, and recognise the first compiler errors you will meet.
  3. Chapter 3: Triggers, effects and priorityWhen a transition fires, what it does on the way, and which one wins when several could fire at once.
  4. Chapter 4: Delayed and immediate transitionsWhen a transition is checked, how several transitions can fire in one tick, and how a chart finishes.
  5. Chapter 5: Variables, types and expressionsBooleans, integers, floats and strings; inputs, outputs and locals; initial values, operators, assignments and arrays.
  6. Chapter 6: SignalsPure and valued signals: present or absent in each tick, emitting and testing them, and combining values.
  7. Chapter 7: SuperstatesPut a state machine inside a state: nesting, the scope of declarations, and finishing with a termination transition.
  8. Chapter 8: Concurrent regionsSeveral state machines side by side in one chart: they react in the same tick, talk to each other within it, and can finish together.
  9. Chapter 9: AbortsCutting a superstate short: weak and strong aborts, immediate aborts, priorities, and what the inside may still do in the tick it is left.
  10. Chapter 10: Entry, during and exit actionsEffects that belong to a state rather than a transition: they run when the state is entered, while it stays active, and when it is left, however that happens.
  11. Chapter 11: The previous tickWith pre(x), the value x had one tick ago, a chart can react to changes instead of levels: detect edges, fire one-tick pulses and count.
  12. Chapter 12: Why the compiler says noWhat KIELER checks before it runs a chart with concurrent regions, why it refuses a causality cycle, what its error messages mean, and how to change the chart.

Ways in

Credits

SCCharts was created by the Real-Time and Embedded Systems group at Kiel University as part of the KIELER project. It builds on Harel’s statecharts and on synchronous languages such as Esterel. The PLDI 2014 paper introduced it, and the KIELER wiki is its reference documentation.

This guide is an independent project, not part of KIELER or Kiel University. Its examples are checked against KIELER’s own compiler, tick for tick, so they behave here as they do in KIELER; where KIELER has a bug the guide does not copy, the example says so (how this guide is checked).

Report a mistake on this page