Skip main navigation

How to design a real-time computing system

In this step we will walk you through the creation of a real-time algorithm to trigger an alarm, and how to extrapolate this algorithm.

In this article, we will walk you through the creation of a real-time algorithm: an alarm-triggering algorithm for an automated greenhouse system.

How to craft an algorithm

All computer systems take input, process data, and output results. Algorithms are part of that middle step; they direct the processing a computer system performs to create meaningful data, for users or for other systems.

Real-time computing algorithms differ from other computing algorithms in two key ways: they are time-bound, and they are event-driven. The algorithm must be performed at a specific time, and it is triggered by an event rather than being run manually by a user.

When you create algorithms, you need to ask three key questions:

  1. What are the inputs?
  2. What conditions or processes need to be included?
  3. What output do you want if those conditions are met?

For a real-time computing algorithm, you should also ask:

  1. What will trigger the algorithm?

How to design an algorithm to trigger an alert

Going back to the earlier example, we will walk you through the creation of an algorithm to trigger the warning alarm in my automated greenhouse. The persona used in that design will want some way of knowing when there is a system fault or some other risk to their plants.

Let’s begin by answering those questions.

1. What are the inputs?

An input to an algorithm is different to an input to a computer system. Inputs to a computer system are manual or automatic actions linked to devices. Inputs to algorithms are instead pieces of data that already exist within the system, and that the algorithm will use for processing or comparisons.

This algorithm will have three inputs: the current temperature, a preset low value, and a preset high value.

The preset values will be set by the user, but for the purpose of this algorithm design, we will assume they already exist.

2. What conditions or processes need to be implemented?

The algorithm needs to perform two conditional checks, linked with an OR operator. It should check whether the current temperature is lower than the low value OR whether the current temperature is higher than the high value.

3. What output do you want if those conditions are met?

If either of the above conditions is True (all conditional operations return a Boolean value), the system should trigger the alarm. In general, an alarm should be perceptible to more than one sense. Just using light would require you to be in sight of the greenhouse, and just playing a sound risk that sound getting drowned out by other noise. This alarm should use both.

What will trigger the algorithm?

Event-driven systems use events generated by software and hardware to trigger logical operations. You should consider what event could be used to trigger this algorithm.

In the greenhouse, the temperature sensor will be taking readings regularly to monitor the environment; each reading is an event. The alarm algorithm could be triggered immediately after the reading has been captured. If the condition is met, the alarm will turn on.

You can now sketch out the algorithm using flow charts. In event-driven systems, the developer writes event handlers, which are subroutines that are called when an event occurs. This is what we will create now.

A flow chart for the alarm

We are going to start by declaring the inputs. When we implement this algorithm, it will need to access the registers that are storing these pieces of data. For the moment, we can just note down that the pieces of data will be input into the algorithm.

The initial flow chart for the alarm with the start symbol followed by the input symbol for variables current_temp, max_temp, and low_temp.

Next, we add two conditional statements, linked with an OR operator. This creates two branches in the algorithm: one where the conditions are True and the other where they are False.

The flow chart continues from the input symbol to a conditional symbol with the following conditional statement: "if current_temp is less than low_temp OR current_temp is greater than max_temp". The conditional symbol has a True and False branch which are currently not linked to anything.

If the condition is True, we want the LED to turn on and the buzzer alarm to trigger. Then the algorithm can stop.

The next stage of the flow chart follows the True branch from the conditional statement to a process symbol with the commands "turn LED on" and "turn buzzer on" followed by a stop symbol.

However, we should also think about how the alarm is reset. The current algorithm will turn the two components on, but it will never turn them back off. For this, we can use the other branch of the algorithm; if the condition is False, the greenhouse has returned to normal temperature levels, and the alarm can turn off.

The final flow chart for the greenhouse connects a process symbol from the False branch of the conditional symbol. The process symbol has two commands: "turn LED off" and "turn buzzer off".

Extrapolating this algorithm

Now that we have made one algorithm to trigger an alarm, you can use this same process to create an alarm feature for another system.

  • Using the same process shown above, create an algorithm that will trigger an alarm in a smartwatch
  • Upload an image of your flow chart to a service such as Imgur or a similar sharing platform. You will have to right-click to open in a new tab, or use the back button to return to the course.
  • Share a link to the flow chart and your answers to the key questions above with your fellow learners
This article is from the free online

Design and Prototype Embedded Computer Systems

Created by
FutureLearn - Learning For Life

Our purpose is to transform access to education.

We offer a diverse selection of courses from leading universities and cultural institutions from around the world. These are delivered one step at a time, and are accessible on mobile, tablet and desktop, so you can fit learning around your life.

We believe learning should be an enjoyable, social experience, so our courses offer the opportunity to discuss what you’re learning with others as you go, helping you make fresh discoveries and form new ideas.
You can unlock new opportunities with unlimited access to hundreds of online short courses for a year by subscribing to our Unlimited package. Build your knowledge with top universities and organisations.

Learn more about how FutureLearn is transforming access to education