Introduction

In this article I want to talk briefly about how modern computers work. Just briefly, you can go very deep in the topic. But I believe you can learn something new here, especially if you know a little bit of computers. I think all of us use CPU, RAM or hard drive.

When we purchase new PC or laptop we care about is it i5 or i7 intel CPU or how many GBs of RAM and so on.

In this article I want to talk about how some of these components work and how they interact with each other. And lastly what is the difference between microcontroller and microprocessor.

CPU

This is the brain of the Microcontroller. If I want summarize its function in one sentence it is this, “The CPU job is to bring the code/program from memory and execute it”. There are some subcomponents in the CPU like Control Unit (CU), Arithmetic Logic Unit (ALU), buses, registers … more on that in the future.

Programs are not saved in CPU itself. But where are they saved? Programs are saved in memory (RAM, ROM, Hard drive, …). CPU requests codes from memory and execute them one by one.

There are some types of outcomes of program’s code (in CPU they’re called instruction). Outcome could be changing data in memory, do some action in Outside device, arithmetic calculation (add, subtract, multiply or divide), save data in memory and much more.

What fascinates me the most is how well is this system designed. I mean for many many many years I wondered how the CPU knows where the program is in memory? The answer to this is quite long but in short the CPU uses addresses. The CPU knows the address of the program it needs to run. There a component in CPU called Program Counter (PC), it tells the CPU to execute the instruction/ code in memory location number 1 for example. Then execute what’s in memory location 2 and so on. If there’s data needed to be pulled from somewhere else the instruction will tell CUP the find it in memory location 1343 for example, then PC continues original counting.

I mentioned memory multiple times until now so let’s get into it.

Memory

As I mentioned above, programs are not saved in CPU they are saved in memory. Memory also holds data as well. I will briefly discuss about types of memory

ROM or Read-Only Memory. From the name you can see this type of memory is used in situations when you don’t want to change data so often. ROM does not erase data when power is switched off unlike RAM.

In the early days of computers changing data in ROM was so difficult. One type of ROM you need to apply ultra-violate light to erase data, and when data get erased that way all data is gone, so you have to program ROM again.

However this is a good component for storing programs. Because when you turn off your computer you don’t want to lose your program, right? Also sometimes ROM is used to store other types of data.

Nowadays, it’s very easy to change data in ROM and you can change partial data of ROM. But still data doesn’t get erased when computer is switched off.

Some types of ROM are PROM, EPROM, EEPROM and Flash EPROM. You might be wondering what about RAM. Although similar name but they have different function and specs.

RAM or Random Access Memory. This is mainly used to temporarily save data or programs. When computer is switched off all data get erased. However this is much faster the ROM.

The way it works in computers, if you have a program in memory which you want to run. First the program is loaded into RAM, then CPU starts executing program instructions from RAM. Because RAM is so fast to respond to CPU unlike hard drive. The more you have RAM memory the more program and data you can save into RAM which  lead to faster performance overall.

ROM store programs, but usually is used to bootstrap the computer when you first turn on the computer. If you know BIOS in computers, they are in ROM.

Some types of RAM are SRAM and DRAM

Other components

IOs or Input Output peripherals. Sometimes you want a user input to the CPU or program, and the input device can be a keyboard or a mouse or even some data from another device, then you process this input data. And sometimes you want to output data to LED screed or printer. There are some pins and peripherals dedicated for that.

Buses. A bus is a kind of link or cabling between CPU, RAM, ROM, IOs, etc. You can think of bus as a link to send data between different components. There are some types of buses like control bus, data bus and address bus.

Microcontroller vs Microprocessor

You might’ve heard these two words. The difference is simple. Microprocessor only contains the CPU. Microcontroller has everything you need for a computer like CPU, memory, timers etc.

If you’ve built computers before, you know that each component is purchased separately and linked through motherboard. In our computers we use microprocessors, although Apple changed this norm recently with the M1 and M2 chips.

Microcontrollers in the other hand although have all the components but usually they are used in small electronic devices. Arduino uses ATmega328P microcontroller. Again apple changed this norm and used Microcontroller in their newer versions of Macbooks (at the time of this writing M2 is the newest chip)

Summary

In this article I talked about a brief introduction to main components of microcontrollers and microprocessors. I talked about CPU, Memory and some other components. Then lastly, I compared between microcontroller and microprocessor.