Safe Microcontroller Programming Practices

The Internet of Things (IoT) will eventually connect all of the electronic devices in our lives, providing situation-specific support in day-to-day life.

Ambient Assisted Living (AAL) research aims to develop technologies for comfortable living and life in old age. These technologies are designed to improve older people’s quality of life and help them continue to lead independent lives. The care of the elderly is already a serious cost factor for national economies today and it will be even more so in the future. AAL research can make a critical contribution to controlling these costs and providing older people with a better quality of life.

At konplan Systemhaus, the company has been working on medical devices at various levels for a number of years. In ongoing projects, konplan is exploring application scenarios and solutions for the meaningful use of networked devices. It contribute to these research projects through an intelligent building Luzern iHomeLab, which is controlled entirely through IoT.

Design consideration of safety is one of the critical factors to ensuring a system is robust in design, able to operate flawlessly in diverse environments, and does not interfere with other devices. This article focuses on design tips for using microcontrollers in such applications with extended safety requirements.

Defensive software design is a set of techniques to address the issues caused by improper software responses. The following specific software techniques are recommended for good defensive software design:

Enable the WatchDog function

A WatchDog function forces a system reset when the application software fails to execute as expected. It is important to make sure that the device will not stop operating even if the software begins operating incorrectly. Allowing the microcontroller to remain in an undefined state is very dangerous and unacceptable, especially for applications with safety requirements.

Fill unused memory

Unused memory should be filled with suitable content such that the microcontroller does not execute any unexpected instructions when the normal execution flow is disturbed. The execution of these special instructions will force the processor to go through the fault routine and take the appropriate action to recover.

Define all Interrupt Vectors

Defining the interrupt vectors for each unused interrupt function ensures that the microcontroller will jump into a predefined interrupt routine when any particular unused interrupt flag is falsely triggered. The microcontroller is then able to resume correctly after the interrupt function.

Reconfirm edge-triggered interrupts

Confirmation of edge-triggered interrupts is an essential technique to verify that input events are valid and driven by the correct sources. Checking within the interrupt service routine that the input signal was actually generated by the intended source will enable detection of noise on the input. If this is happening regularly in a design then the conclusion should be to provide filtering in hardware but a professional software engineer expects the worst case in any situation.

Enable Slew Rate Control

Slew rate control should be enabled for output port pins, where available. When enabled, slew rate control limits the rate at which an output can change state. This reduces the output rise and fall times, helping to minimize radiated emissions generated on output port switching and reducing interference with other susceptible devices.


Good software design can improve performance and operating stability in noisy environments. In general, the software design cannot control the physical media which injects noise into the system, or reduce the absolute magnitude of noise generated from external sources. However, software can provide intelligent corrective actions in fault conditions and implement precautionary features for system protection.

More About This Company

LTCC Substrates

LTCC (Low-Temperature Co-fired Ceramic) is a multilayer capable substrate technology offering excellent RF and microwave...