An introduction to microcontrollers

This article begins with a general introduction to microcontrollers, what they are and how we might use them and their challenges.

author avatar

26 Dec, 2024. 4 min read

Microcontrollers have become ubiquitous in modern life, we find them in a multitude of places and applications including. 

  • Consumer Electronics: Home appliances, battery management systems, and chargers.
  • Automotive Industry: Engine control units, anti-lock braking systems, airbags, and collision protection systems.
  • Industrial Automation: Motor controllers and process control systems.
  • Medical Devices: Infusion pumps and wearable health monitoring devices.
  • Internet of Things (IoT): Smart home devices and environmental monitoring systems.

While a range of applications deploy microcontrollers and present different challenges, consumer and IoT sectors require low-cost and good supporting development environments with several libraries to ease integration and development. In contrast automotive, medical, and industrial automation applications often require the microcontroller to operate in power-constrained and harsh environments where failure could result in loss of life or environmental damage. Therefore, robust design and reliable operation in these applications are paramount - this something we will come back to discuss in detail in a later article. 

Overview of microcontroller architectures

Before diving into development methodologies and techniques, it's essential to understand common architectural features of microcontrollers. While traditionally 8- and 16-bit microcontrollers have been very popular (for example I learned about microcontrollers with 8-bit PICS at university), we have seen a shift to more capable 32-bit processors. 

At the heart of a microcontroller is the processor core, typically 32-bitin modern designs. This could be an ARM Cortex-M series processor or a RISC-V RV32 core. The application program executed by the microcontroller is stored in non-volatile memory (such as Flash memory), and the microcontroller also includes volatile memory (SRAM) for application execution, data storage and manipulation.

To help reduce system integration challenges and bill-of-materials costs, most microcontrollers integrate both non-volatile and volatile memories internally, reducing the need for external components and simplifying the overall system design.

Some microcontrollers feature multiple processor cores, which can enhance processing capabilities. However, without an operating system, such as Linux to manage and allocate tasks across cores, developers are presented with several challenges to effectively leverage the dual cores. Notably, even affordable microcontrollers like the Raspberry Pi Pico (RP2040) offer dual-core processing.

Having multiple cores can increase the performance of the system, however, there are considerations and drawback of these multiprocessor systems when we are working with bare metal or RTOS, including: 

  • Resource Constraints: Microcontrollers have limited memory and processing power. Parallel programming in such environments requires management of these system resources to prevent bottlenecks or conflicts. 
  • Inter-Core Communication: Coordinating tasks between cores necessitates reliable communication mechanisms. Implementing these can be non-trivial due to the hardware limitations and the need for low-latency interactions.
  • Synchronization Issues: Without proper synchronization, parallel tasks can lead to race conditions, deadlocks, or data corruption. Ensuring thread-safe operations requires additional complexity in code design.
  • Debugging Challenges: Debugging concurrent code on microcontrollers is more difficult due to limited tooling and visibility into the system's state during execution.

Peripherals and interfaces

To interact with the external world, microcontrollers include a variety of peripherals connected to the processor core. Commonly provided peripherals include:

  • Standard Communication Interfaces: UART, SPI, I²C, and Ethernet.
  • GPIO: General-Purpose Input/Output pins for interfacing with sensors, actuators, and other devices.
  • Timers and Watchdogs: For timing operations and system reliability.
  • Real-Time Clocks (RTC): For timekeeping functions.
  • Specialized Interfaces: Depending on the application, microcontrollers may include interfaces like CAN or CAN FD for automotive applications, or 1553B and SpaceWire for aerospace and space applications.

Many microcontrollers also provide mixed-signal capabilities, such as analogue-to-digital Converters (ADCs). These typically have sampling frequencies between 100 kHz and 1 MHz, suitable for control applications like measuring voltages, currents, and temperatures. For example, they can easily sample sensors like Platinum Resistance Thermometers (PRTs) and Negative Temperature Coefficient (NTC) thermistors. Again, this helps reduce the system bill of material cost and enables a smaller overall solution, critical for many constrained applications.

Depending on the peripherals required for the applications and the available internal memory resources, we may need to consider using external memories if libraries are used to support more complex peripherals such as the lightweight IP stack supporting the Ethernet communications.

Sadly, our applications do not always work first time, so an essential aspect of working with microcontrollers is the ability to program and debug them using standard interfaces like JTAG or Serial Wire Debug (SWD). These interfaces allow developers to download software to the microcontroller and perform in-depth debugging of their applications, performing tasks such as break pointing, inspecting variable values, and observing registers within the processor to ensure they are configured correctly. 

One of the most challenging aspects of working with a microcontroller in your application is choosing the most appropriate one. There are several aspects which can be considered to help identify the correct processor: 

  • Performance: Processing speed and capabilities needed for the application.
  • Memory Resources: Adequate onboard Flash and SRAM for the application code and data.
  • Peripheral Availability: Necessary interfaces and peripherals for the application.
  • Environmental Conditions: Operating temperature ranges, such as industrial or automotive standards.
  • Power Consumption: Especially important in battery-powered or energy-harvesting applications.
  • Development Ecosystem: Availability of development tools, libraries, and community support.

Another aspect which helps us understand the processor’s processing capabilities and supports our identification of a suitable processor is the performance benchmarking. Benchmarks enable us to compare the processing power of several different microcontrollers despite having differing clock speeds or number of cores. One common benchmark is Dhrystone MIPS (Millions of Instructions Per Second). While it has limitations, Dhrystone is widely used, and many processors provide a DMIPS/MHz rating, indicating the performance per MHz of clock frequency. This allows developers to estimate performance at different operating frequencies. 

There is a range of microcontrollers available from many different vendors; over this series we will look at several of these. However, one of the most popular microcontroller entry-level platforms of recent years is Arduino. Arduino provides developers with a range of development boards based on simple microcontrollers, supported by an extensive development ecosystem that includes an integrated development environment (IDE), libraries, and programming tools. The vibrant Arduino community offers a wealth of resources, from project tutorials to blogs and forums. Since its introduction, Arduino has played a significant role in popularizing embedded microcontrollers and low-level programming, especially among young people considering careers in engineering and software development.

Next Steps

This introduction provides a foundational understanding of microcontrollers and their role in embedded systems. In subsequent articles, we will explore various development methodologies, techniques, and best practices for designing and implementing microcontroller-based applications.