How Do Microcontrollers Work?

Sam Sattel Sam Sattel June 12, 2017

10 min read

A Computer in the Palm of Your Hand – Microcontrollers Explained

Microcontrollers. Look around you for a moment, beyond your PC screen. Do you have a remote control laying nearby? Maybe a TV in the corner of your room? A microwave in your kitchen, and a car parked outside? While you might not realize it, all of these objects, which look nothing like the computer that you are reading this blog post from, have a computer inside. Your interaction with computers no longer starts and stops between the time you sit down at your desk for the day, and when you leave for home. Nearly every interaction you have with this world, from driving on your daily commute to how you cook your dinner uses a computer that can fit in the palm of your hand.

Honey, I Shrunk the Computer!

So what is this super small computer? It’s a microcontroller, also called an MCU, and it’s exactly like the computer you are using right now, with a few subtle details of difference. The computer that you know is a general computer. It can do an unlimited number of tasks, depending on the use. However, a microcontroller is what we call a specialized computer. It’s used to do one task really, really well without worrying about anything else.

big-picture
Microcontrollers don’t need to worry about the bigger picture; they focus on a very particular task.

Take for example your car sitting outside. There’s likely a microcontroller inside of it that will read inputs from the oxygen and knock sensors when your car is running, which will then control things like the mixture of your fuel and the timing of your spark plugs. Or what about the microcontroller inside your television? It’s waiting for inputs from your remote control, and then showing you various outputs in the form of different television channels and volume adjustments.

These two examples are just a few of the unlimited number of uses for microcontrollers. The list can be exhaustive, and basically, anything that needs to have some kind of digital input and output is likely using a microcontroller behind the scenes.

Microcontrollers and Computers

We’ve said that a microcontroller is exactly like the computer you’re using right now, only smaller. But what exactly does that mean? On the surface computers, all look different, with varying sizes of monitors, keyboards, and even internal specifications. But it’s the hardware running on the inside of a computer that shows us just how much it has in common with a microcontroller, including:

Of course, the size of all of these different pieces of hardware is much smaller than a traditional computer. I can open up the case on my desktop computer and pull out the RAM and CPU, but in a microcontroller, everything is nestled together into one small black box. And it’s because of this size that you’ll find microcontrollers being embedded in larger devices.

arduino-uno
See the black rectangular box on this Arduino? That’s an ATmega 328 microcontroller. (Image source)

Take something like a washing machine as an example. There’s a ton of mechanical parts that make up the physical structure of this device, and embedded within this mechanical world is a microcontroller handling all of the digital work. In this instance, the embedded microcontroller will allow you to control specific features and actions of the washing machine.

For example, my washing machine has a feature that automatically senses the needed water level based on how many clothes are inside of it. This process likely uses a microcontroller to sense the depth of the clothes, and also the depth of the water as it’s being added to the tank. When the water level reaches the level of the clothes, the microcontroller will tell the motor controller to turn off the flow of water and begin the washing cycle.

Small Size, Small Costs

There are some benefits for opting to use a microcontroller in specific applications like my washing machine instead of a traditional computer system, and it namely boils down to:

We also can’t forget that many of these microcontrollers are designed to work in what can sometimes be rather hostile environments. For example, the microcontroller at work in your car likely has to deal with temperatures anywhere from -30°F in a winter in Alaska to something as scorching hot at 134°F over in Death Valley in the peak of summer.

16-bit-microcontroller-die
A die of a 16-bit microcontroller made by Texas Instruments, look at all of those closely packed traces! (Image source)

Microcontrollers in Action

How does a microcontroller get to work, transforming inputs like temperature and light into some useful action? Much like a traditional computer, a microcontroller relies on several features to make its computing action happen, including:

RAM

Just like in a computer, RAM will be used in a microcontroller to store data and other results that are created while your microcontroller is at work. And when you cut the power on your microcontroller, the memory in your RAM gets erased.

Within the RAM in a microcontroller, you’ll also have something called a Special Function Register (SFR). This memory comes pre-configured from your microcontroller’s manufacturer and controls how specific circuits will behave, such as an analog-to-digital converter, serial communication, and more.

ROM

The specialized task that a microcontroller carries out in the form of a program will be stored on its Read-Only Memory and will generally never change. ROM is what allows the microcontroller in your television to always know that pressing the change channel button on your remote should change what’s displayed on your screen.

The size of the program that can be stored in the ROM is entirely dependent on its size. Some microcontrollers ship with built-in ROM, while others can accept ROM added as an external chip. It varies between each microcontroller.

Program Counter

Another feature nestled within a microcontroller is the program counter, which allows your mini computer to execute a program based on a series of programmed instructions. This counter increments by 1 each time a line of instructions is carried out which helps it to keep track of its place in your line of code.

Inputs and Outputs

Unlike your computer, which you’ll likely interface with though a keyboard and mouse, most microcontrollers have other ways that humans interact with them. Typical input and output devices on microcontrollers can include switches, LED displays, and even sensors that can measure temperature, humidity, light levels, etc.

photoresistor
You can attach something like this photoresistor into a breadboard and then connect it to a microcontroller to sense light levels. (Image source)

Most of the embedded systems that you’ll encounter out in the wild don’t have a keyboard or screen that you can directly interact with because they weren’t intended for human-to-computer interaction, only machine-to-machine interaction. Because of this, microcontrollers will have up to a dozen General Purpose Input/Output Pins, or GPIO, that can be configured for various input and output devices.

raspberry-pi-gpio-pins
Some GPIO pins on a Raspberry PI that allows it to interact with our physical world. (Image source)

For example, you might have one pin on a microcontroller configured as an input that acts as a temperature sensor. Another pin can be configured as an output and connected to your thermostat which turns on your heater or air conditioning depending on the particular input temperature range that you’ve programmed. As you can see, this input and output dynamic is purely from machine to machine without requiring direct human interaction each time it makes a decision.

Real-Time Operation

Microcontrollers also have the ability to provide a real-time response to events when triggered within a larger embedded system. Take for example our washing machine. When an event occurs which signals that the water level has reached its required height, this will then trigger what’s called an interrupt. This interrupt will send a signal to the processor in your microcontroller to stop doing its current action, which would be to stop the flow of water.

This process of altering the actions of a microcontroller on the fly as it progresses through a specific sequence is called an Interrupt Service Routine, or ISR. These ISRs can come in many shapes and sizes, and it really just depends on the device a microcontroller is being used. You’ll find ISRs being used for events like internal timer overflows, completing an analog-to-digital conversion, or even putting a series of events into motion when a button is pressed.

Keeping Microcontrollers Organized

When working with microcontrollers on your own electronics projects, you’ll find them organized into several categories. These categories are all based on several variables, including the number of bits, amount and type of memory, the instruction set type, and the memory architecture used. Here are some examples:

You might be asking after reading about these categories, how do you know which microcontroller to select for your own project? This selection process requires consideration of a number of criteria and includes things like knowing what kind of hardware you need to interact with, how much memory you need, what kind of architecture you need, and how much you’re willing to pay. All of these considerations and more are summarized over at the ARM community in their 10 Steps to Selecting a Microcontroller blog post.

In the Palm of Your Hand

Microcontrollers are everywhere, serving as the invisible computers in our age of digital electronics and working tirelessly behind the scenes in all areas of our life. Can you count all of the devices in your immediate surroundings that you rely on that might have a microcontroller inside? You might be surprised at what you find. These computers have opened up a world of possibilities for new interactions and intelligence in otherwise common and everyday objects like washing machines, remote controls, power tools, toys, and a whole lot more. Without microcontrollers, the world we know today would never be possible.

Want to work with a microcontroller in your very own electronics project? Autodesk EAGLE includes a ton of ready-to-use microcontroller libraries all for free! Try Autodesk EAGLE for free today to get started.

Autodesk Fusion Logo

Elevate your design and manufacturing processes with Autodesk Fusion

Tags and Categories

Eagle EDA

Get Fusion updates in your inbox

By clicking subscribe, I agree to receive the Fusion newsletter and acknowledge the Autodesk Privacy Statement.