Tips and Tricks – 7 Tips for Meeting Real-time Deadlines

Embedded systems must meet their real-time deadlines in order to function efficiently and as expected. No one likes to press a button and wait thirty seconds before the system finally responds. More importantly, safety critical systems need to meet their deadlines or else very bad things could happen, such as injury or death. There are many ways to ensure that an embedded system can meet its deadlines but here are seven tips to help developers make sure that their deadlines are being met as expected.

Tip #1 – Aim for ~30% Idle Time

Everyone wants to get their full money’s worth out of every component selected for a product. Running a microcontroller at anything less than 100% just feels like the product is being over designed. The truth, however, is that in order to meet real-time requirements and deadlines, developers should really be targeted their system to have a CPU idle time around 30%. Why so high? Developers who perform a theoretical RMA (rate monotonic analysis) will find that the theoretical maximum CPU load to meat real-time requirements, run the scheduler and handle interrupts is 69.3% CPU load. Pushing the processor any harder means that the chances greatly increase that during the worst case scenario the real-time system requirements will not be met.

Tip #2 – Use Trace Tools for Accurate Measurements

A few years ago, developers would map out what would theoretically happen in their system, implement it and then cross their fingers that what happened in the microcontroller was what they thought was happening. Since those days, new tools such as SWD, ETM and other trace protocols have come into existence that allow developers to monitor the very instructions that are being executed in their microcontrollers with minimal impact to real-time performance. Developers will often make assumptions about how their system will execute code but using trace tools such as Percepio’s Tracealyzer or Seggers SystemView can allow not only assumptions to be tested but provide developers with min, max and average execution times that allow them to tweak and verify their real-time models. Use these tools to improve and understand assumptions and realize what the system is doing.

Tip #3 – Select RTOS Priorities Carefully

I encounter quite a few developers who don’t know how to select an RTOS priority. When forced to select a priority, they simply do a quick mental comparison to the other tasks in the system and then select what they think it should be. Very little engineering is put into the decision, its more guesswork than anything else. An RTOS priority should only be selected after careful analysis has been performed to see how the tasks could interact with each other and it is determined that all tasks will meet their deadlines under all circumstances.

Tip #4 – Perform an RMA Analysis

Rate Monotonic Analysis (RMA) is a technique that developers can use to analyze their periodic tasks and make sure that the priorities are set such that all deadlines will be met. RMA is a great starting point for developers to use to make sure that the integrity of their system is on solid ground.

Tip #5 – Pick the Right Microcontroller for the Job

Selecting a microcontroller that has too much little horsepower for the job at hand results in a nightmare solution of constantly optimizing, cutting and fighting with the source code at every turn. Picking the right microcontroller can be challenging. A good rule of thumb is to start out with a higher end part from the microcontroller family that is of interest, prototype the system and start to get a feel for the code, how it executes and the overall performance of the system. If the microcontroller has too much power, scale back to a lesser capable microcontroller. Don’t forget though that in many cases products tend to just add more and more features over time so selecting a microcontroller that has more than is needed can keep the system functioning properly even as feature creep does its work.

Tip #6 – Create a Software Architecture

Design the system up front, model it and create a software architecture. An architecture will help developers understand the major software components, what their input and outputs are and how they interact with each other. Understanding these major pieces can identify areas that are not well understood, which can then lead engineers to areas to research and comprehend better before writing the production code. A well-architectured code base will result in code that is understandable and meets its deadlines.

Tip #7 – Test Continuously

Software changes. Features are added, enhanced and sometimes even removed. Changes to the code base will inevitably affect the real-time system performance and might result in changes to priorities being necessary to keep the system running as expected. The only way to ensure that the system continues to behave is to continuously test, measure and evaluate how the system is behaving. Build testing and measuring into the embedded software development process.

Conclusions

Managing time and meeting deadlines are the most important factor to consider when developing a real-time embedded system. Following these tips can start to help developers towards a path of understanding how their systems work and making sure that they will meet all the system deadlines that are thrown at them.

Leave a Reply

Your email address will not be published. Required fields are marked *