Skip main navigation

What are Microcontrollers?

What are microcontrollers? Read to learn more.

In this article we take brief dive into world of microcontroller hardware, and you will gain awareness of how they work – inside and out.

Microcontrollers: A Computer in Miniature

Microcontrollers are themselves computers. They contain all of the core components that make up any modern digital computer – a central processing unit (CPU), memory and some form of data input and output. However, the design requirements and architecture of microcontrollers are vastly different to personal computers or laptops. Let’s see why.

As an example, let’s take the Microchip PIC10F322 microcontroller. The photo below shows this simple microcontroller. You will immediately notice several key differences to a laptop!

Figure 1 - A PIC10F322 MicrocontrollerFigure 1 – A PIC10F322 Microcontroller
(Click to expand)

More specifically:

  • Size Microcontrollers are always embedded into solutions – robots, cars, juggling balls… As such, they are designed to be extremely small to avoid constraining the form of that product. This microcontroller is one of the smallest in the world, measuring just 3mm x 2mm x 1mm! They are also incredibly inexpensive – a PIC10F322 costs less than 30 pence when bought in volume!
  • Integration Microcontrollers have little or no external components to run. Think of a modern PC or laptop, and all the complexity we see on its motherboard. The microcontroller shown above would execute your program with nothing more than a AA battery connected to it power (Vcc) and ground (Gnd) pin!
  • Interfacing Microcontrollers have no requirements for a screen, keyboard, or other user interface. They are not designed to talk to you. Instead, they are designed to talk the languages that transducers speak – digital communication protocols. The exposed pins on the microcontroller allow sensors and actuators that speak these protocols to be connected directly to the device.

Systems within Systems

The following block diagram illustrates what is inside the PIC10F322.

Figure 2 - Block Diagram of a PIC10F322 MicrocontrollerFigure 2 – Block Diagram of a PIC10F322 Microcontroller
(Click to expand)

Here we can see the CPU that your program and to the left an internal oscillator. This tells the CPU how quickly to run your program. Typical clock speeds for microcontrollers can be as low as 32kHz (32000 instructions per second) but are typically in the range of 4-64MHz. Compare that to a PlayStation 5 GPU that is capable of over 10TeraFlops – that’s 10,000,000,000,000 instructions per second! This relatively slow speed is also there by design – it reduces electrical power requirements, meaning your device can run for much longer when on battery. A PIC10F322 at its slowest speed could run for decades on a pair of AA batteries!

You may also notice the memory. RAM is where your variables are stored. FLASH memory is used to hold the instructions that make up your program, so that if electrical power is lost you don’t lose your program. This means that once your program is loaded, it will never be lost (FLASH memory does eventually decay, but it’s good for around 30 years!).

Note also the blocks marked PORTA, ADC and PWM. These provide hardware support for different types of digital communication protocols.

Common Digital Communication Protocols

Microcontrollers communicate by setting or sensing small electrical voltages on one or more physical pins on the microcontroller. As microcontrollers are digital devices, these voltages have only two states – they can either be HIGH or LOW. LOW voltages are always 0 volts, whilst HIGH voltages are typically 3.3 volts or 5 volts. Let’s look briefly at some of the most common ways that microcontrollers connect to sensors and actuators.

GPIO (General Purpose Input/Output)

This is the simplest of all connections and is implemented by the PORTA block in our example above. GPIO gives full control of a pin’s voltage (HIGH or LOW) to the program running on the microcontroller. Software writing a ‘1’ to a well-defined location in memory will cause the voltage on a given pin will be set HIGH and writing a ‘0’ produces a LOW voltage. Similarly, the voltage on a pin can be sensed, and read from that memory location. GPIO is perfect for the integration of very simple transducers, such as a button or an LED, but soon becomes unwieldy for more complex interactions.

Pulse Width Modulation (PWM)

PWM allows for a single value to be shared over a pin through a very simple mechanism. Specialist hardware (a PWM driver) on a microcontroller will periodically change the value on a pin high and then low. The frequency at which this happens can be controlled, as can the duty cycle (the ratio of how the long the pin stays high compared to how long it stays low). This creates a repeating “train” of HIGH pulses on a pin, without the CPU needing to be directly involved. PWM is a very common mechanism for controlling motors, servos, controlling the brightness of LEDs and even making simple sounds!

Embedded Serial Protocols (SPI, I2C, UART)

The more sophisticated sensors and actuators are supported by more sophisticated protocols. Detailed treatment of these protocols are beyond the scope of this article, but they are work on the same core principle. They transmit a train of pulses similarly to PWM, but not in a repeating pattern. Instead, each HIGH pulse or LOW pulse corresponds to a single bit of data (a ‘1’ or ‘0’). SPI, I2C and UART are capable of sending and receiving very flexible data at high speed (up to millions of bits per second), and are commonly used in devices you will be highly familiar with, including SD cards, LCD graphics displays, movement sensors, GPS trackers and even stage lighting.

Summary

In this article we have seen how microcontrollers are small, simple, low power devices designed to integrate with sensors and actuators. They can run user programs on their CPU and communicate over a range of digital protocols from GPIO, PWM, SPI, I2C and UART. To develop a deeper understanding of how a simple microcontroller operates, take a look at the PIC10F322 datasheet [1]. Also see [2] for a very accessible article on the common uses of PWM, and similar articles for I2C, SPI and UART. We’ll also see some live examples as we progress through the course!

This article is from the free online

Build a Physical Computing Prototype

Created by
FutureLearn - Learning For Life

Our purpose is to transform access to education.

We offer a diverse selection of courses from leading universities and cultural institutions from around the world. These are delivered one step at a time, and are accessible on mobile, tablet and desktop, so you can fit learning around your life.

We believe learning should be an enjoyable, social experience, so our courses offer the opportunity to discuss what you’re learning with others as you go, helping you make fresh discoveries and form new ideas.
You can unlock new opportunities with unlimited access to hundreds of online short courses for a year by subscribing to our Unlimited package. Build your knowledge with top universities and organisations.

Learn more about how FutureLearn is transforming access to education