Microcontrollers: Fundamentals and Applications

Overview

Various types of computers are tailored to specific functions. The computer inside your laptop, for instance, serves different purposes compared to the ones found in your phone or mouse. At the most basic level, there are computers designed to manage input from the physical world and regulate output devices. These are commonly referred to as microcontrollers.

The majority of modern electronic devices are centered around a microcontroller. These microcontrollers are fine-tuned to oversee physical input and output. Unlike the processors found in multimedia computers or servers, microcontrollers are generally less powerful in terms of computational ability. However, they consume less power and are better suited for interfacing with the physical world through input sensors and output actuators. Additionally, they can establish communication with other processors through a variety of communication interfaces.

Computer, microcontroller, processor? Which is which?

These terms are often used interchangeably in discussions about computers, both here and in other literature. “Computer” and “processor” are broad terms encompassing any device capable of executing a program. Conversely, “controller” or “microcontroller” typically refers to a simpler processor dedicated to a single task, such as monitoring sensors.

When discussing microcontrollers, it’s important to differentiate them from personal computers or servers, which house more robust processors capable of running an operating system.

Microcontrollers: Computers for the Physical World

When developing a system that translates physical world interactions into digital media control, microcontrollers are often employed to detect user actions. Subsequently, these actions are relayed to a multimedia processor, such as the one found in laptops. For instance, keyboards and computer mice contain microcontrollers that utilize the USB communications protocol to communicate with personal computers.

ATmega328
Figure 1. Atmel Atmega328P chip
Atmel Atmega328P chip
Figure 2. Atmel Atmega328P chip
SMD package of a microcontroller
Figure 3. SMD package of a microcontroller

Microcontrollers come in many different size packages as shown in Figure 1,  Figure 2 and Figure 3.

Similar to any other computer, a microcontroller must possess input ports to detect user actions and output ports to convey program results. These ports, manifested as metal pins or contact points on the microcontroller, serve as interfaces for connecting various devices such as sensors, motors, lights, and sound devices. This connectivity enables the microcontroller to sense its environment and execute tasks accordingly. Additionally, like conventional computers, a microcontroller necessitates power and communication connections.

In Figure 4, an Atmel microcontroller, now owned by Microchip, is depicted with its pins labeled. These pins encompass general-purpose input and output (GPIO), power and communication connections, and specialized functions, with analog input being the most common. For further insights into the typical functions of a microcontroller, refer to the Microcontroller Pin Functions page.

ATMEGA328 pin diagram
Figure 4. ATMEGA328 pin diagram

Various types of microcontrollers exist, ranging from the simplest with minimal program memory, just a couple of GPIO pins, and lacking specialty functions, to more sophisticated ones with expanded memory, numerous GPIO pins, and dedicated pins for specific communication protocols. The Atmega328 processor found in the Arduino Uno exemplifies this category, while its modern counterpart is the SAMD21 featured in the Nano 33 IoT. These microcontrollers are available for purchase in small quantities for just a few dollars each.

Moving up the hierarchy are microcontrollers with capabilities to interface with display screens, akin to those in mobile phones. These typically entail higher costs, ranging from several to tens of dollars, reflecting increased memory, processing power, and input/output ports.

In scenarios necessitating an operating system, the device might incorporate multiple controllers and processors. Microcontrollers usually handle tasks such as display controls, power management, and physical input/output, while the central processor executes the operating system, facilitating communication between various components.

As technology advances, the distinction between microcontrollers and operating system processors becomes less distinct. Understanding the types of programs running on different devices aids in discerning the disparity between them.

Programs for Microcontrollers and Other Processors

Software for various processors can be categorized into several classes: firmware, bootloaders, Basic Input-Output Systems (BIOS), and operating systems. Understanding their interrelationships provides insight into the connections between different processor classes.

Microcontrollers typically execute a single program continuously while powered, which is loaded onto the controller from a personal computer using a dedicated hardware programming device. This process involves shifting instructions onto the controller one bit at a time through specialized connections. Similarly, even powerful servers or multimedia processors require firmware to be loaded onto them initially using a hardware programmer.

Although microcontrollers typically do not run operating systems, they often utilize bootloaders. A bootloader, residing in a specific segment of the controller’s memory, facilitates reprogramming of the remaining memory. It enables programming directly from a personal computer or the internet without a separate hardware programmer. Phone firmware upgrades, for instance, utilize bootloaders. These enable processors to accept new programs through alternative channels, not just the dedicated programming port.

Processors running an operating system also utilize a BIOS, which can be loaded onto the processor through a bootloader. The BIOS operates before or instead of the operating system, managing attached display and storage devices, as well as input devices.

Bootloaders and BIOSes, residing in the processor’s flash memory, are often referred to as firmware. Conversely, other software resides on external storage devices like disk drives. Changing firmware or a microcontroller’s program involves stopping the current program, uploading the new one, and resetting the device.

An operating system acts as a program manager, scheduling tasks, managing communication, interacting with display processors, and more. Programs are compiled into binary instructions using compilers, which are just one type of application an operating system might run. These applications typically reside on external storage devices, like disk drives.

Firmware Stored On Detail
Single Program Processor’s program memory Is the only program running; must be loaded by hardware programmer
Bootloader Processor’s program memory Must be loaded by hardware programmer; Takes small amount of program memory; can load another program into the rest of program memory
BIOS Processor’s program memory Usually loaded by bootloader; can load operating system into RAM memory
Table 1. Types of firmware that are stored directly on a microprocessor

 

Software Stored on Details
Operating System External mass storage Runs other programs; loaded into RAM by BIOS; unloaded from RAM on reset
Drivers External mass storage Controls access to other processors, like disk drivers, keyboards, mice, screens, speakers, printers, etc. These are usually loaded into RAM on startup of the OS, and controlled by the OS, not the user.
Applications External mass storage Loaded into RAM by operating system and unloaded as needed
Table 2. Types of software on an operating system processor, and where they are stored.
Typically, a microcontroller denotes a processor that solely executes firmware, while a processor running an operating system from external storage is termed an embedded processor. If the device contains numerous processors, it’s referred to as a central processor. For instance, the Arduino exemplifies a microcontroller, while devices like the Raspberry Pi and BeagleBone Black are categorized as embedded processors. Conversely, laptops are multi-processor devices housing a central processor, a graphics processor, a sound processor, and potentially other processors.

Microcontroller Development Boards and Activity Boards

Regardless of whether it’s a microcontroller or a multimedia processor, a processor cannot function independently; it requires additional supporting components. For a microcontroller, essential components include a voltage regulator and typically an external clock, commonly referred to as a crystal. Additional circuitry may be incorporated to safeguard against incorrect power supply or inappropriate voltage and current inputs to the I/O pins. Communication interfaces may also be included. The presence of this supplementary circuitry determines the foundational cost of development boards such as the Arduino or the Raspberry Pi.

Development boards typically comprise:

  • The processor itself
  • Power regulation circuitry
  • Connector for hardware programmer
  • Circuitry for communication interfaces
  • Basic indicator LEDs
An Arduino Uno.
Figure 5. An Arduino Uno.

 

A Raspberry Pi
Figure 6. A Raspberry Pi

Advanced development boards may feature multiple communication interface circuits, including wireless options, along with pre-attached sensors to some GPIO pins, a mass storage connector like an SD card, and video or audio circuitry if supported by the processor. The cost of a board increases with the number of features it offers.

While a development board facilitates programming of the controller’s firmware and software, an activity board may not. Activity boards come with a pre-programmed microcontroller, sensors, actuators, a communication interface, and a communications protocol. This setup enables interfacing with software on a personal computer. Activity boards like the MaKey MaKey or the now-retired PicoBoard generally require connection to a personal computer to function, unlike development boards, which can operate independently.

A Makey Makey Board
Figure 7. A Makey Makey Board
A Sparkfun Picoboard
Figure 8. A Sparkfun Picoboard

Do I really need a development board?

It’s possible to purchase and program microcontrollers independently, without relying on a development board or activity board, but additional components are necessary. Initially, you’ll need to design your own supporting circuitry, including a programmer interface and a power supply. In most cases, acquiring a hardware programmer is also essential. Moreover, you’ll either need to procure breakout boards or learn to create compact surface-mount circuits since fewer microcontrollers are now available in the large dual inline package (DIP) suitable for solderless breadboards. Generally, for those less experienced with electronics and circuit fabrication, starting with an activity board or development board is advisable.

Toolchains and Development Environments

The two primary languages utilized for microcontrollers are the assembly language specific to each processor and the C programming language. Recently, there has been a trend toward the development of microcontrollers using Python as well. A toolchain encompasses the compilers and linkers necessary to convert your written instructions into a binary file that the microcontroller can interpret as its commands, along with the programmer software required to upload this file into the processor. Each manufacturer and processor family has its own assembly language, which serves as the foundation of the toolchain.

However, nearly every microcontroller available on the market has a C compiler. Additionally, a toolchain may incorporate a compiler or firmware to translate a higher-level language into the controller’s assembly language. In the case of scripted languages like Python, the microcontroller’s firmware might include a Python interpreter that remains resident on the controller while various scripts are developed and swapped.

While a toolchain handles the conversion of your code, an integrated development environment (IDE) is necessary to connect you, the programmer, to the toolchain. Typically, an IDE comprises a text editor with user interface components for transmitting your code to the toolchain and uploading the resultant binary to the processor. IDEs also feature displays for presenting error messages related to your code and monitors to visualize the behavior of your code during execution on the processor.

Things to consider when picking a microcontroller:

Here’s a guide to picking a microcontroller for this class. What follows are the economic considerations for picking a microcontroller more generally.

COSTS

What’s my budget? The greater the range of features and flexibility, the higher the price tag. However, if it minimizes the time required from setup to expression, the additional expenditure might be worthwhile.

TIME

How much work do I want to do?

Opting for an activity board or an advanced development board typically reduces the effort needed to construct your interface to the external world. Conversely, lower-level development boards or crafting your own boards require more preliminary work before achieving functionality. It’s advisable to refrain from building your own boards unless absolutely necessary. Many promising projects face delays because creators intended to use the project as an opportunity to learn circuit fabrication.

What programming languages/communications protocols/electronics do I already know?

All other things being equal, pick a system whose components you know something about.

What’s the knowledge base like?

Many microcontrollers have dedicated websites and mailing lists focused on their usage and programming, with some of the most valuable resources often linked directly from the manufacturer’s or distributor’s site. It’s essential to explore these resources, examine code samples, and review application notes. Delve into discussion threads and conduct web searches related to the microcontroller environment you’re evaluating. Assess the availability of comprehensible, collected knowledge – this is a significant aspect to consider. While a particular processor may appear exceptional, if it lacks a community of users, you may encounter difficulties in learning and troubleshooting.

EXPANDABILITY/COMPATIBILITY

What other components is the microcontroller compatible with?

Are expansion modules compatible with your microcontroller? For instance, do motor controllers, display controllers, or sensor modules work with it? While these modules can be pricey, they typically integrate seamlessly without the need for custom circuitry. If your time is valuable, investing in these modules can be advantageous. Even if you possess the expertise to construct a solution using a lower-level controller, opting for a higher-level system may be justified by the time saved on construction and upkeep.

What do I have to connect to?

Are you interfacing with a MIDI synthesizer, a DMX-512 lighting board, a desktop computer, the phone system, or the internet? Microcontrollers vary in their interface capabilities, so ensure compatibility for all your connections. Occasionally, achieving this may necessitate inventive combinations of controllers, particularly if no single controller can communicate with all the desired devices.

PHYSICAL AND ELECTRICAL CHARACTERISTICS

How many inputs and outputs are required? Each system has specific input and output demands. Ideally, determine the number of sensors or control points needed before selecting your controller.

What types of inputs and outputs are necessary? Are analog inputs and outputs needed for monitoring changing values, or are digital inputs and outputs sufficient for determining on/off states? It’s important to note that most embedded Linux boards, such as the Raspberry Pi, lack analog inputs.

What power options are available? Is battery power necessary? Does the voltage need to match that of another device? Does it need to consume minimal amperage?

What processing speed is required? Lower-level processors typically offer higher processing speeds.

How much memory is needed? For complex data processing or logging tasks, a microprocessor with ample memory or the ability to interface with external memory may be necessary.

What size constraints exist? Lower-level controllers often enable custom circuitry design, facilitating hardware size reduction.

The Economics of Microcontroller Development

So, what’s the best choice for hobbyists or beginners venturing into microcontrollers?

Opting for mid-level microcontrollers entails relatively low upfront costs in terms of peripherals. The essential components for a typical project, including the controller, typically amount to around $75 – $100. Starter kits are advisable for those new to microcontrollers, as they provide a foundation in the basics. Alternatively, if you’re comfortable with circuits, beginning with just a development board is viable. This approach allows for the retention of the project’s integrity, with the microcontroller available for future endeavors. By doing so, you save time by bypassing the need to learn the intricacies of hardware programmers, selecting compilers, or configuring them. For beginners seeking immediate results, mid-level microcontrollers are the way to go. The only drawback is that additional development boards may be required for subsequent projects.

In contrast, using controllers on their own entails more initial hassle. You must possess knowledge of building basic support and communication circuits, using hardware programmers, and setting up a toolchain. Initially, you may encounter frustration and regret, wishing you had opted for a development board. However, the advantage becomes apparent once everything is set up. Over time, you’ll save money on development boards and have the freedom to customize them as desired. The benefits amplify with each microcontroller project undertaken. Therefore, it’s advisable to start with development or activity boards and progress as your needs and knowledge expand.

Follow this link for complete project: Microcontrollers: Fundamentals and Applications


About The Author

Ibrar Ayyub

I am an experienced technical writer holding a Master's degree in computer science from BZU Multan, Pakistan University. With a background spanning various industries, particularly in home automation and engineering, I have honed my skills in crafting clear and concise content. Proficient in leveraging infographics and diagrams, I strive to simplify complex concepts for readers. My strength lies in thorough research and presenting information in a structured and logical format.

Follow Us:
LinkedinTwitter

Leave a Comment

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.