Skip to content

MICROCONTROLLER BASICS

Vatsal edited this page Mar 22, 2025 · 5 revisions

A microcontroller is a compact integrated circuit designed to govern a specific operation in an embedded system. A typical microcontroller includes a processor, memory and input/output (I/O) peripherals on a single chip.

Sometimes referred to as an embedded controller or microcontroller unit (MCU), microcontrollers are found in automobile engine control systems, robots, office machines, medical devices, mobile radio transceivers, vending machines and home appliances, among other devices. You can define a microcontroller as a simplified computer - one that is generally designed to run a single basic programme repeatedly. By definition, microcontrollers are typically intended to perform a single automated task, as pre-programmed by the user, in a single device. They are designed to do this one job repeatedly (or, as is also common, on a timed loop).

What do microcontrollers do?

When installed as part of a functioning circuit in a device or system, a microcontroller board can sense, monitor and respond to various events, behaviours or input signals that it detects from connected components and its environment.

A microcontroller, for example, might be programmed to push a specific type of output signal or behavioural control in response to certain input criteria. This could include the execution of tasks such as:

  • Illuminating an LED or OLED display in response to touch-based user demand
  • Playing lights and sounds in temperature-sensing applications or other varieties of alarms and warning systems
  • Responding to the need for a motor to switch on or off in a pump or other mechanical device
  • Adjusting for tilt, balance, and velocity in gyroscope or accelerometer-based applications.

Microcontrollers are used in numerous applications across different sectors, including automotive, consumer electronics, industrial automation, and the Internet of Things. Their ability to perform specific tasks efficiently, combined with their low power consumption and small size, makes them ideal for embedded systems where space and energy efficiency are crucial.

Components of a Microcontroller-

  1. CPU: This is the processor and the device's critical heart. It will process and issue responses to several instructions/commands that enable the functioning of the microcontroller.This will include I/O, logic, and arithmetic-related operations. It also handles data transfer while communicating the commands to other system components.

  2. Memory: It helps store all the data received by the system's processor and uses responses to instructions as per its programming. The microcontroller setup usually comes with two memory types. The first one is program memory which is the storage of long-term data regarding the instructions borne out by the CPU. Program memory falls in the non-volatile category, meaning it can hold data over time minus the power source requirement. Data memory is another type of memory.This is necessary for temporarily storing data while the instructions are being implemented. Data memory falls in the volatile category, meaning that the data it holds is temporary and maintained only when the device is linked to a power source.

  3. I/O Peripherals: The output and input devices are the primary interface for the processor about its relationship to the external world or environment. The input ports get data and dispatch the same to the processor as binary data. The processor will get this data before dispatching all main instructions to the output devices which will take care of other tasks external to the microcontroller.

    There are several other components which are also included in microcontrollers. The I/O peripherals definition may encompass various elements that have processor and memory interfaces. Some further supporting details include these:

  • ADC: This means an Analog Digital Converter, a circuit, thereby enabling the conversion of analogue to digital signals. It allows processors at the microcontroller's centre to interface with external sensors or analogue devices.
  • DAC: Digital to Analog Converters help take care of the reverse functionalities of the ADC while enabling the processor in the centre to easily communicate all outgoing signals to the components in the external analogue category.
  • System Bus: It is a connective wire which connects all the components of microcontrollers with aplomb.
  • Serial Port: It is an instance of I/O ports which enable microcontrollers to link up with external components. It works similarly to a parallel or USB port, although there is a difference in the bit exchange part.

How does a Microcontroller work?

A microcontroller is a tiny, self-contained computer on a single chip that can be programmed to perform specific tasks in electronic devices. Think of it as the brain of a simple gadget. A microcontroller works by reading inputs, processing them according to a program stored in its memory, and then producing outputs to control something. It's like a miniature computer that can be programmed to automate tasks in a wide range of devices.
Here's a breakdown of how it works:

  • Input: It takes information from the outside world through its input pins. This could be a signal from a button, a sensor, or another device.

  • Processing: The central processing unit (CPU) is the core of the microcontroller, where instructions are executed. It fetches instructions from memory, decodes them, and performs arithmetic and logical operations.

  • Memory: Microcontrollers have memory to store both the program (the set of instructions) and the data it works with. There are two main types of memory: Read-Only Memory (ROM) or Flash memory, which stores the program permanently, and Random Access Memory (RAM), which stores data temporarily while the microcontroller is running.

  • Output: After processing the input, the microcontroller sends out signals through its output pins to control other parts of the device. This could be turning on an LED, controlling a motor, or sending data to a display.

  • Clock: A clock signal synchronizes all the operations within the microcontroller, ensuring that everything happens in the correct order and at the right time.

  • Peripherals: Microcontrollers often include built-in peripherals like timers, analog-to-digital converters (ADCs), and communication interfaces (like UART, SPI, I2C) that allow them to interact with other devices and sensors.

Types of Microcontrollers:

Microcontrollers can be categorized into several types based on various factors such as architecture, bus width, memory, and manufacturer. Here are the main types of microcontrollers:

Based on Bus Width

  • 8-bit microcontrollers: The most basic type, used in simple applications like toys and remote controls.
  • 16-bit microcontrollers: More capable, used in medical devices, automotive systems, and industrial control.
  • 32-bit microcontrollers: The most powerful and feature-rich, used in demanding applications like gaming consoles and high-end industrial automation.

Based on Architecture

  • RISC (Reduced Instruction Set Computer) microcontrollers: Execute fewer compute instructions faster than other methodologies.

  • CISC (Complex Instruction Set Computer) microcontrollers: Have a larger set of more complex instructions, with each instruction potentially taking several clock cycles to complete

  • ARM (Advanced RISC Machine) microcontrollers: Widely used in mobile devices, automotive systems, and industrial control.

  • Harvard Architecture: Complete instruction in one machine cycle, with separate bus lines for program code and data.

  • Von Neumann (Princeton) Architecture: Uses single memory for program and data storage, common in computers and laptops.

Popular Microcontroller Families

  • PIC Microcontrollers: Produced by Microchip Technology, available in 8-bit, 16-bit, and 32-bit versions.

  • AVR Microcontrollers: Developed by Atmel (now part of Microchip), known for their efficiency.

  • 8051 Microcontrollers: Originally created by Intel, now produced by various manufacturers.

  • ARM Microcontrollers: Widely used across various industries due to their performance and energy efficiency.

These different types of microcontrollers cater to a wide range of applications, from simple consumer electronics to complex industrial systems and automotive controls.

Microcontrollers vs Microprocessors:

There is often confusion with regards to precisely what defines a microcontroller vs a microprocessor (MP) or System on Chip (SoC).

In a nutshell, a microcontroller is a simplified, single-task version of a SoC. Although an MCU technically contains a CPU or processor of sorts as part of its integrated circuit, it is a much more simplified version. This reduced-power microprocessor effectively functions as a simple CPU or brain for the microcontroller unit, giving the MCU the basic ability to perform its single programmed role.

In terms of laying out the other key differences between a microprocessor and a microcontroller, the easiest definition is to talk in terms of components. A true microprocessor does not contain any memory (RAM or ROM) or I/O ports and can only operate as part of wider embedded systems. The instruction sets telling a standalone microprocessor how to execute a given function are generally stored externally. In a microcontroller, all these various components - including the simplified processor - are combined into a single self-contained unit.

Microcontrollers vs Microprocessors: Performance Breakdown

Microcontrollers

  • Are an entirely self-contained unit that contains a very simple CPU or microprocessor
  • Are used for a single specific application, as pre-programmed by the user
  • Are not especially powerful in performance terms; typically, they only draw a small amount of power and contain little in terms of integrated data storage capacity
  • Need to be programmed by the operator to perform any meaningful role
  • Cannot operate outside of their specifically programmed remit (the code written for them - and the quality of it - will entirely define their performance)
  • Are generally meant for use in specific devices or appliances designed to perform one task repeatedly

Microprocessors

  • Are much more complex and versatile in terms of function range, and intended for use in more general computing (as opposed to in specialised one-task devices)
  • Have much faster processor (clock) speeds than MCUs, often measured in gigahertz (GHz) rather than Hz
  • Are challenging and expensive to manufacture, unlike relatively simple and cheap microcontrollers
  • Require far more external components (RAM, I/O ports, data storage, EEPROM or flash memory) to operate, none of which are integrated into the MP and must be bought and connected separately
  • Have a considerably higher power draw and are subsequently much less cost-effective to run continually

test

Clone this wiki locally