A microcontroller is like a basic computer. It is much simpler though and has much less power than even the most basic PC. However, it consists of the same components, a processor, RAM, flash storage and hardware peripherals such as GPIO pins for connecting sensors and circuitry to. Most Arduino boards which use Atmel's ATmega series chips run at 16MHz while other boards which run on ARM processors can run at several hundred megahertz.
This means that the CPU clock ticks 16 million or greater times per second and on each clock cycle the CPU can perform a simple instruction. It then groups these simple instructions together to do bigger tasks like displaying data or reading an input.
So let's take a look at exactly how these microcontrollers work. So let's take the example of a 16MHz microcontroller. The Arduino Uno is a perfect example of this. It has an ATmega 328 chip on board which clocks in at 16MHz. So again, this megahertz, it's a really big number and it means times per second. Hz is a measure of frequency or how often something happens. So 16MHz is 16 million Hz or 16 million times per second. So every second there is an internal electrical clock on the chip which goes up and down, up and down, up and down at a set interval. And every time there is a clock edge when it changes states, it is a new cycle. And so every time, for example, if it goes into a low state, then the microcontroller is able to do something.
Now this is very, very simple instructions. We're not talking about the fact that every time it falls on one of these clock edges, it can display data on an LCD screen. The complex code behind that requires a much lower level of integration. Microcontrollers are based around mathematics. So on each of these clock cycles, it could be as simple as adding two numbers together, binary numbers, a one and a zero, or comparing the state of one number against the other. By doing this, you can group lots of small, lower level functions into tasks that are much more complex, such as what you see on modern computers, or even turning an LED on or off as we'll look at further on in the chapter.
Microcontrollers are a blank slate. Apart from the bootloader, they will only do exactly what you tell them to do and nothing else. There's no operating system running, nothing else going on except your code. Now this means they're able to do things really quickly and efficiently in the exact order that you require, despite their lower power, because there is no extra software to run.
Microcontrollers that are shipped straight from the factory do not come with a bootloader. However, every Arduino board should have the Arduino bootloader pre-flashed onto it. The only role of the Arduino bootloader is to allow it to properly communicate with the Arduino IDE over USB and be reprogrammed.
A typical computer needs a case full of hardware to operate, or even a laptop, whereas a microcontroller can usually function with only a handful of supporting components. On the Arduino Uno, for example, the microcontroller is the small black chip that you can see on the board, and that is all there is to it. In reality, all it needs is the microcontroller, an oscillator, and two capacitors, and the correct power supply to be able to run. All of the rest of the circuitry on the Arduino Uno is for extra functionality such as USB connection, the pin headers, and power supply filtering.
Now that we know what a microcontroller is, let's take a look at how a microcontroller works with the Arduino system.
Makers love reviews as much as you do, please follow this link to review the products you have purchased.