Internal configuration of microcontroller

What is inside micro controller?



Obviously, everything that occurs in the micro controller occurs at high speed and quite simple, but it would not be so useful if there are no special interfaces which make it complete.
Program Memory (ROM)
The Program Memory is a type of memory which permanently stores a program being executed. Obviously, the maximal length of the program that can be written to depends on the size of the memory. Program memory can be built in the micro controller or added from outside as a separate chip, which depends on type of the micro controller. Both variants have advantages and disadvantages: if added from outside, the micro controller is cheaper and program can be considerably longer. At the same time, a number of available pins is decremented as the micro controller uses its own input/output ports to be connected to the memory. The capacity of Internal Program Memory is usually smaller and more expensive but such a chip has more possibilities of connecting to peripheral environment. Program memory size ranges from 512 B to 64 KB.
Data Memory (RAM)
Data Memory is a type of memory used for temporary storing and keeping different data and constants created and used during operating process. The content of this memory is erased once the power is off. For example: when the program performs addition, it is necessary to have a register presenting what in everyday life is called “a sum”. For that purpose one of the registers in RAM is named as such and serves for storing results of addition. Data memory size goes up to a few KB's.
EEPROM Memory


The EEPROM Memory is a special type of memory which not all the types of the micro controllers have. Its content can be changed during program execution (similar to RAM), but it is permanently saved even after the power goes off (similar to ROM). It is used for storing different values created and used during operating process and which must be saved upon turning off the device (calibration values, codes, values to count up to etc.). A disadvantage of this memory is that programming is relatively slow- measured in milliseconds.
SFRs (Special Function Registers)
SFRs are a particular part of memory whose purpose is defined in advance by the producer. Each of these registers have its name and control some of interfaces within the micro controller. For example: by writing zero or one to the SFR controlling some input/output port, each of the port pins can be configured as input or output (each bit in this register controls the purpose of one single pin).

Program Counter
Program Counter is an engine which starts the program and indicates the address in memory where next instruction to execute is found. Immediately after its execution, the value of the counter is incremented by 1. For this automatic increment, the program executes one instruction at a time as it is written. However…the program counter value could be changed at any moment, which will cause “jump” to a new location in the program memory. This is how subroutines or branch instructions are executed. When finding its new place in the program, the counter resumes even automatic counting +1, +1, +1…
CPU (Central Processor Unit)
As its name tells, this is "Big Brother" who monitors and controls all operations being performed within the micro controller and the user cannot affect its work. It consists of several smaller units. The most important are:
Instruction decoder - a part of electronics which recognizes program instructions and on the basis of which runs other circuits.
Arithmetical Logical Unit (ALU) - performs all mathematical and logical operations with data. The features of this circuit are described in the "instruction set" which differs for each type of the micro controller.
Accumulator - is a special type of the SFR closely related to operating mode of the ALU. It is a kind of desk on which all data needed to perform some operation on are set (addition, shift etc.). It also contains a result, ready to be used further in operation. One of the SFRs, called the Status Register, is closely related to the accumulator, showing at any time the "status" of a number being in the accumulator (the number is greater than or less than zero etc.).

Bit - a word invented to confuse people who start handling electronics. In practice (only in practice) this word indicates whether the voltage is applied to an electrical conductor or not. In the first case, a logical one is present on the pin, i.e. the bit’s value is 1. Otherwise, if the voltage level is 0 V, i.e. a logical zero is present on the pin, the bit’s value is 0. It is more complicated in theory where the bit is actually a digit in a binary system, whereas, a bit is just a bit whose value amounts 0 or 1 (in decade system we are used to the digits’ value amounting 0, 1 , 2 , 3 , …..8 or 9).
Input/output ports (I/O Ports):
The micro controller cannot be of any use without being connected to peripheral devices. For that reason each micro controller has one or more registers connected to its pins (called ports in this case).
The oscillator can be compared with rhythm section of a mini orchestra. Equalized pulses coming from this circuit enable harmonious and synchronise operating of all other parts of the micro controller. It is commonly configured so as to use quartz-crystal or ceramics resonator for frequency stabilization. Besides, it can often operate without elements for frequency stabilization (like RC oscillator). It is important to know that instructions are not executed at the rate ordered by oscillator but several times slower. The reason for this is that each instruction is executed in several steps (In some micro controllers execution time of all instructions is equal, while in others micro controllers execution time differs for different instructions). Consequently, if your system uses quartz-crystal of 20 MHz, execution time of a program instruction is not 50 nS but 200, 400 or even 800 nS!
Timers/Counters
Most programs use in some way these miniature electronic "stopwatches". They are mostly 8- or 16-bit SFRs whose value is automatically incremented with each coming pulse. Once the register is completely "filled up"- an interrupt is generated !
If the registers use internal oscillator for its operating then it is possible to measure the time between two events ( if the register value is T1 at the moment measuring has started, and T2 at the moment measuring has finished, then the time that has passed is equal to the value gained by their subtraction T2-T1 ). If the registers for its operating use pulses coming from external source then such a timer is converted to counter.
This is a very simple explanation used to describe the essence of the operating. It’s a bit more complicated in practice.