Microcontroller
Microcontroller
Circumstances that we find ourselves in today in the field of microcontrollers had their beginnings in
the development of technology of integrated circuits. This development has made it possible to store
hundreds of thousands of transistors into one chip. That was a prerequisite for production of
microprocessors , and the first computers were made by adding external peripherals such as memory,
input-output lines, timers and other. Further increasing of the volume of the package resulted in
creation of integrated circuits. These integrated circuits contained both processor and peripherals. That
is how the first chip containing a microcomputer , or what would later be known as a microcontroller
came about.
1.1Memory unit
Memory is part of the microcontroller whose function is to store data. The easiest way to explain it is to
describe it as one big closet with lots of drawers. If we suppose that we marked the drawers in such a
way that they can not be confused, any of their contents will then be easily accessible. It is enough to
know the designation of the drawer and so its contents will be known to us for sure.
Memory components are exactly like that. For a certain input we get the contents of a certain
addressed memory location and that's all. Two new concepts are brought to us: addressing and
memory location. Memory consists of all memory locations, and addressing is nothing but selecting
one of them. This means that we need to select the desired memory location on one hand, and on
the other hand we need to wait for the contents of that location. Beside reading from a memory
location, memory must also provide for writing onto it. This is done by supplying an additional line
called control line. We will designate this line as R/W (read/write). Control line is used in the
following way: if r/w=1, reading is done, and if opposite is true then writing is done on the memory
location. Memory is the first element, and we need a few operation of our microcontroller .
1.2Central Processing Unit
Let add 3 more memory locations to a specific block that will have a built in capability to multiply, divide,
subtract, and move its contents from one memory location onto another. The part we just added in is
called "central processing unit" (CPU). Its memory locations are called registers.
Registers are therefore memory locations whose role is to help with performing various mathematical
operations or any other operations with data wherever data can be found. Look at the current situation.
We have two independent entities (memory and CPU) which are interconnected, and thus any exchange
of data is hindered, as well as its functionality. If, for example, we wish to add the contents of two
memory locations and return the result again back to memory, we would need a connection between
memory and CPU. Simply stated, we must have some "way" through data goes from one block to
another.
1.3Bus
That "way" is called "bus". Physically, it represents a group of 8, 16, or more wires There are two types
of buses: address and data bus. The first one consists of as many lines as the amount of memory we
wish to address, and the other one is as wide as data, in our case 8 bits or the connection line. First one
serves to transmit address from CPU memory, and the second to connect all blocks inside the
microcontroller.
As far as functionality, the situation has improved, but a new problem has also appeared: we have a unit
that's capable of working by itself, but which does not have any contact with the outside world, or with
us! In order to remove this deficiency, let's add a block which contains several memory locations whose
one end is connected to the data bus, and the other has connection with the output lines on the
microcontroller which can be seen as pins on the electronic component.
As we have separate lines for receiving and sending, it is possible to receive and send data (info.) at the
same time. So called full-duplex mode block which enables this way of communication is called a serial
communication block. Unlike the parallel transmission, data moves here bit by bit, or in a series of bits
what defines the term serial communication comes from. After the reception of data we need to read it
from the receiving location and store it in memory as opposed to sending where the process is reversed.
Data goes from memory through the bus to the sending location, and then to the receiving unit
according to the protocol.
However, in order to utilize it in industry we need a few additionally blocks. One of those is the timer
block which is significant to us because it can give us information about time, duration, protocol etc. The
basic unit of the timer is a free-run counter which is in fact a register whose numeric value increments
by one in even intervals, so that by taking its value during periods T1 and T2 and on the basis of their
difference we can determine how much time has elapsed. This is a very important part of the
microcontroller whose understnding requires most of our time.
1.7 Watchdog
One more thing is requiring our attention is a flawless functioning of the microcontroller during its run-
time. Suppose that as a result of some interference (which often does occur in industry) our
microcontroller stops executing the program, or worse, it starts working incorrectly.
Of course, when this happens with a computer, we simply reset it and it will keep working. However,
there is no reset button we can push on the microcontroller and thus solve our problem. To overcome
this obstacle, we need to introduce one more block called watchdog. This block is in fact another free-
run counter where our program needs to write a zero in every time it executes correctly. In case that
program gets "stuck", zero will not be written in, and counter alone will reset the microcontroller upon
achieving its maximum value. This will result in executing the program again, and correctly this time
around. That is an important element of every program to be reliable without man's supervision.
Finnally, the microcontroller is now completed, and all we need to do now is to assemble it into an
electronic component where it will access inner blocks through the outside pins. The picture below
shows what a microcontroller looks like inside.
Thin lines which lead from the center towards the sides of the microcontroller represent wires
connecting inner blocks with the pins on the housing of the microcontroller so called bonding lines.
Chart on the following page represents the center section of a microcontroller.
1.9Program
Program writing is a special field of work with microcontrollers and is called "programming". Try to write
a small program in a language that we will make up ourselves first and then would be understood by
anyone.
REGISTER2=MEMORY LOCATION_B
PORTA=REGISTER1 + REGISTER2
END
The program adds the contents of two memory locations, and views their sum on port A. The first line of
the program stands for moving the contents of memory location "A" into one of the registers of central
processing unit. As we need the other data as well, we will also move it into the other register of the
central processing unit. The next instruction instructs the central processing unit to add the contents of
those two registers and send a result to port A, so that sum of that addition would be visible to the
outside world. For a more complex problem, program that works on its solution will be bigger.
Programming can be done in several languages such as Assembler, C and Basic which are most
commonly used languages. Assembler belongs to lower level languages that are programmed slowly,
but take up the least amount of space in memory and gives the best results where the speed of program
execution is concerned. As it is the most commonly used language in programming microcontrollers it
will be discussed in a later chapter. Programs in C language are easier to be written, easier to be
understood, but are slower in executing from assembler programs. Basic is the easiest one to learn, and
its instructions are nearest a man's way of reasoning, but like C programming language it is also slower
than assembler. In any case, before you make up your mind about one of these languages you need to
consider carefully the demands for execution speed, for the size of memory and for the amount of time
available for its assembly. After the program is written, we would install the microcontroller into a
device and run it. In order to do this we need to add a few more external components necessary for its
work. First we must give life to a microcontroller by connecting it to a power supply (power needed for
operation of all electronic instruments) and oscillator whose role is similar to the role that heart plays in
a human body. Based on its clocks microcontroller executes instructions of a program. As it receives
supply microcontroller will perform a small check up on itself, look up the beginning of the program and
start executing it. How the device will work depends on many parameters, the most important of which
is the skillfulness of the developer of hardware, and on programmer's expertise in getting the maximum
out of the device with his program.