Easy guide to microcontrollers

A microcontroller can be defined as miniaturized computer which is used together with other electronic circuits to control or monitor different systems.

Microcontrollers have penetrated a vast domain of markets and technologies. Some examples of industries and applications where microcontrollers are used heavily are:

  • industrial systems: heating and ventilation, lightning, electronic door locks
  • automotive: powertrain control, battery energy manafements, multimedia, navigation
  • medical: portable medical meters (glucometer, heart rate meter), X-ray scan machines, diagnostic devices
  • home applicances: washing machines, cookers, refrigerators, blenders
  • consumer electronics: electric shavers, trimming machines
PIC18F Microcontroller

Image: PIC18F Microcontroller
Credit: Microchip

Microcontrollers are suited for diverse applications, from simple control algorithms to fully integrated systems, involving various communication protocols (USB, Ethernet, CAN) as well as Touch Sensing and LCD. Any electronic device that has a sensor, a user interface, a controlled actuator or a display most probably contains also a microcontroller.

Microcontrollers are classified function an several parameters. One of the is the size of the data unit. Based on this criteria, we can have: 8, 16 or 32 bit microcontrollers. An 8 bit microcontroller allocates 8 bit of memory (1 byte) for the most of its data units .

Microcontroller manufacturers are classifying their microcontroller products mainly based on the size of the data unit (8 bit, 16 bit, etc.) and the number and configurations of pins. In the picture below you can see an overview of the 8 bit microcontrollers family from Microchip.

PIC 8 bit Microcontrollers Overview

Image: PIC 8 bit Microcontrollers Overview
Credit: Microchip

Looking inside a microcontroller we can see that it has several core components:

  • Central Processing Unit (CPU)
  • Program Memory
  • Data Memory
  • Internal Oscillator
  • Timers/Counters
  • Input Output (I/O) Ports (pins)

All the above component are integrated into a single microchip.

The Central Processing Unit (CPU) is a microprocessor which controls and monitors all the processes inside the microcontroller. The CPU consists on several smaller units, the core one being the Arithmetic Logical Unit (ALU). This unit is responsible with the execution of all logical and mathematical operations.

The Program Memory is the place where the instruction set (code/program is stored). For example, if the program was developed in C programming language, a binary file (e.g. *.hex) will be generated by the programming environment. The *.hex file is loaded into the Program Memory. For more information about the process to generate a binary file from source files, read the article How C programming works – from editor to executable.

The content of the binary file is arranged in data records and stored in the Program Memory. The Central Processing Unit accesses the data records, interprets them as instructions and executes them one after the other.

The content of the Program Memory can not be changed during execution. Once the binary file has been loaded, which means that the microcontroller was programmed, the instruction set will remain unchanged. This is why the Program Memory is also called Read Only Memory (ROM).

There are several types of Read Only Memory. The most common type of ROM are:

  • Erasable Programmable Read Only Memory (EPROM)
  • Flash Erasable Programmable Read Only Memory (FEPROM)

EPROM can be reprogrammed by using Ultra Violet (UV) light. This kind om Program Memory doesn’t come integrates on the same microchip with the microcontroller, but as a separated component which communicates with the CPU of the microcontroller through a Address/Data Bus.

The most common type of Program Memory is the FEPROM. The content of a FEPROM can be reprogrammed electrically using a reprogramming unit which communicates with the microcontroller through a serial interface. This type of memory usually comes integrated with the microcontroller on the same microchip.

8 bit PIC Microcontroller Architecture

Image: 8 bit PIC Microcontroller Architecture
Credit: Microchip

Data Memory is regarded as the main memory of the microcontroller. This memory is used as a storage place for variables used during computations. When the ALU is performing logical and mathematical operation it will store the variables and results in the Data Memory.

There are two types of Data Memory:

  • volatile
  • non-volatile

The volatile Data memory is also called Random Access Memory (RAM). it’s called volatile because when the power supply is disconnected from the microcontroller, all the data inside the RAM is lost.

Some of the control algorithms of a microcontroller requires to save some of the data even if the power supply is disconnected. For example, if a control unit is controlling the position of linear actuator, it needs to know which are the end limits, the minimum and maximum of the linear movement. For this we need to use a Non Volatile Random Access Memory (NVRAM). All the data stored inside NVRAM is saved even is the power supply is disconnected.

The Internal Oscillator is the internal clock of the microcontroller. Every microcontroller needs an internal clock in order to execute instruction in rhythm with the clock (time based manner). a basic instruction is executed at every tick of the clock.

A Timer is a counter which is incremented at every tick of the internal (system) clock. Timers are used to keep track of time and to start/stop different task at desired time intervals. A specific type of timer is the watchdog timer. This is incremented continuously and must be reset by the CPU at regular intervals. If, for some reasons, the CPU doesn’t perform a reset of the watchdog, the timer will reach a maximum threshold. This means that there is a problem with the CPU and the watchdog will trigger a reset of the CPU.

The Input/Output Ports (pins) are used to connect the microcontroller with the outside world. Generally speaking I/O ports are used: to read incoming signals (analog or digital), to generate control signals (e.g Pulse Width Modulated signals) and for connection with a power supply. If the microcontroller requires additional external memory, the communication between the CPU and the external memory is done through one of the dedicated ports.

It happens that some people are confusing microprocessors with microcontrollers. They are totally different electronic devices. A microprocessor is the equivalent of the CPU within a microcontroller. A microprocessor doesn’t contain ROM and RAM memory, it’s only used for logical and mathematical operations.

For any questions, observations and queries regarding this article, use the comment form below.

Don’t forget to Like, Share and Subscribe!

Leave a Reply

Ad Blocker Detected

Dear user, Our website provides free and high quality content by displaying ads to our visitors. Please support us by disabling your Ad blocker for our site. Thank you!