PRODUCT HOW-TO: State machine design is as easy as telling the timeTI's innovative eZ430 Chronos watch evaluation kit is based on a traditional sports watch design incorporating pulse monitoring, 3-axis accelerometer and pressure sensor all enclosed in an attractive housing.
With its wireless functionality, not only can the watch (Figure 1 below) be used as a comprehensive sports watch, but it can also act as, for example, a wireless mouse, or wireless control of slideshow presentations.
|Figure 1. Texas Instruments eZ430 Chronos watch evaluation kit|
If you look at a typical sports watch at an abstract level it is a very good example of an event-driven system, which at a given time operates in one of several distinct modes or sub-modes.
We can, for example, quickly list a number of abstract events that can be interesting to an application built on this platform:
Button presses: the watch has 5 buttons. The original firmware reacts to all of these and also assigns meaning to a long (2 seconds) press on two of these buttons. It can also detect and generate repeating, i.e. continuous button pressing that generates a series of button events.
Timer events: A number of timers can be running and generate periodic events. A stopwatch, for example, probably needs accurate timer events at a rather high speed to keep the display updated.
The heart rate is polled periodically as well, at least on the application level— exactly how the communication with the chest strap works is buried in a set of proprietary libraries.
The expiry of user-defined alarms or the crossing of user-defined thresholds for heart rate etc. can be viewed as abstract events that should have an impact on the application behavior.
The watch has a number of different modes, or states, where the events mentioned above can take on a different meaning. For example:
1) Stop watch mode
2) Set time and date mode
3) Activated radio mode for heart rate monitoring
4) Wake-up alarm mode
5) Different display modes to chose what to view on the display
6) Exercise energy estimation
An application like this, for a relatively resource-constrained MCU, is often based on the "fat interrupt routine" idiom, where most of the application logic is spread out over a number of interrupt functions.
For example, the main timer interrupt function for the eZ430-Chronos original firmware is close to 180 lines, including single-line comments and blank lines; the function drives quite a lot of the application functionality by way of function calls and manipulation of global data.
This way of working has a lot of advantages. It is, for example, very easy in this particular case to control the different low-power modes of the watch's MSP430 MCU, because the only thing the main loop has to take care of is to do some low-priority processing and then go back to the appropriate low-power mode.
However, the potential drawback is that the application logic is spread out over a number of different modules and it can thus be difficult to trace how different functionality interacts during a debug session or when new functionality is to be added.