Thursday 12 May 2016

Microcontrollers part I: Basic structure

Last time I wrote about the Raspberry Pi, a beer can sized computer. Now it's time to go even smaller. The following couple of posts are about microcontrollers which shall be the brain and soul of my future game console.

The microcontroller, or MCU, is simply put a very small computer crammed into a single chip. Unlike personal computers, MCUs have typically a rather humble amount of computing power but they are low cost and don't require much electricity. Therefore they are perfect to solve relatively simple tasks in embedded systems. If a desktop computer is a car and the Pi is a motorcycle, then the microcontroller would be a lawnmower: not very fast but good for its intended purpose.
Basic building blocks of a microcontroller.
The core of the MCU consists of a control unit and at least one arithmetic and logic unit (ALU). The control unit is responsible that all the action happens where it should; it translates the instructions to actual operations, temporarily stores small bits of data in registers and moves the data around the chip. It is the manager that follows the programmer's instructions telling the ALU what to do. The arithmetic and logic unit is the part that does all the number crunching and logical operations. Together the control unit and the ALU are called central processing unit, or CPU, just like the processor in the desktop computer.

In addition to the CPU, a microcontroller contains memory, input and output peripherals and quite often an internal clock. Memory comes in two flavours: volatile and non-volatile memories. Here volatile memory is synonymous with random access memory (RAM) which is fast but requires power hold information. RAM is therefore used for run-time storage of data, such as the position of the player or the number of lives left.

Non-volatile memory on the other hand retains its data even without power. However, depending on the type of the memory it is either non-writeable or slow. Non-volatile memory is thus most suitable for storing the program itself or data that needs to be preserved even when the system is down, like save states.

Input and output peripherals connect the chip to the surrounding world. Input can be, for example, signals from a controller to move the player around. Output signals can control the graphics on the screen or play funky music out of the speaker.

The last but not the least is the clock, an oscillator that produces a periodic signal that rapidly switches between ON and OFF states. The clock makes the microcontroller tick controlling the pace at which the instructions are executed.

Schema of a clock signal
Whenever you see MHz (million oscillations per second) or GHz (billion oscillations per second) mentioned in the context of computers, it most likely refers to the frequency of the clock signal. Higher the frequency, the more ticks per second. This, however, doesn't necessarily mean that a microcontroller with higher clock frequency has faster computation speed as the number of clock cycles to execute instructions depends on how they are implemented in a particular processor. Many MCUs have an internal clock but their frequency can be unstable. One uses an external crystal like in electronic watches when precise timing is required.

Well, that was a good bunch of theory. In the next post I'll make it more concrete through an example chip that I'll be using in applications once I get there. Until then, stay tuned.  


References:

James J. Brophy, Basic Electronics For Scientists, 1983, McGraw-Hill International Book Company

https://en.wikipedia.org/wiki/Microcontroller

No comments:

Post a Comment