Smart Trains 1

ST 3 A Showcase of Concurrent Hierarchical State Machines

This G-scale 3D-printed hobby train is equipped with two 320×240 LCD modules, one on each side of the powered unit. They display itinerary information as well as a scrolling banner for some self-promotion!

The display behaviors are managed by three concurrent hierarchical state machines (HSMs) running on top of an enhanced statechart framework based on Quantum Platform (QP).

The high-level Graphics Manager HSM is integrated with the emWin graphical library by Segger. It coordinates UI behaviors such as scrolling, pop-up windows, etc. and writes to an internal frame buffer. The mid-level Display Buffer HSM serializes frame buffer updates and prepares the DMA buffer for each update request. The low-level Display Driver HSM handles SPI and DMA transfers to the ILI9341 LCD controller.

Why are state machines useful here? The fundamental reason is the need to wait – waiting for a scrolling timer to expire, or a DMA operation to complete. A lot of bugs in embedded systems are caused by a system not properly waiting for operations to complete, making assumptions and not realizing many different things may happen while it is waiting, eventually getting confused when the wait is done.