Tuesday, February 12, 2008

Microprocessor

Microprocessor Control

Microprocessors represent the pinnacle of digital system design. They are used to control almost all automated processes. A microprocessor can be used to perform almost any function. It is small, relatively cheap and reliable. More importantly replacing it with a similar system built from discreet components would involve a very difficult and complex design task, an enormously complex, very large and unreliable electronic system, and a lot of maintenance.

As with all digital systems the trend with microprocessor design is towards increasing complexity with greater speed of operation at an ever reducing physical size and cost.

A microprocessor is controlling the PC you are using at the moment, but they are also at the heart of PLC's (Programmable Logic Controllers) and more recently PIC's (Programmable Interface Controllers) which are both widely used in industrial automation and control.

Basic Structure and operation of microprocessor systems

The two main elements of a microprocessor system are the CPU or Central Processing Unit and its Memory. The interconnections are known as buses because they contain a large number of parallel connecting wires. The three sets of buses connecting these two blocks are:

http://www.deyes.sefton.sch.uk/technology/_themes/my-industrial/bullet1.gif

The data bus

http://www.deyes.sefton.sch.uk/technology/_themes/my-industrial/bullet1.gif

The address bus

http://www.deyes.sefton.sch.uk/technology/_themes/my-industrial/bullet1.gif

The control bus

The data bus carries data being processed in both directions. The single direction address bus carries memory addresses. The control bus is used to make sure everything works in the correct sequence by sending and receiving timing signals.

http://www.deyes.sefton.sch.uk/technology/images/A-%20Level/mic-con/microp1.gif

There must also be some means of communicating between the CPU and the outside world. This is achieved using peripheral devices such as keyboards, mice and VDU's which either send (input) or receive (output) information via the input/output port.

Sometimes this information is digitally encoded and has to be decoded before the CPU can handle it. At other times it may be generated by an analogue device which needs to be converted into a digital signal (or vice-versa) using A-D (analogue to digital) or D-A (digital to analogue) converters before use.

All microprocessor systems have some memory. It may be permanent and non-volatile (Read Only Memory or ROM) or temporary, volatile memory (Random Access Memory or RAM).

http://www.deyes.sefton.sch.uk/technology/_themes/my-industrial/bullet1.gif

RAM or random access memory is a flexible read/write memory. Most PLC's and some PIC's will have some built in RAM which is used to store programs being written by the user. When we say that RAM is volatile we mean that it cannot be used to store data whilst the PLC or PIC is turned off unless the RAM is battery backed (has a battery permanently attached to hold the data in memory). CMOS RAM is usually used in a battery backed system because it uses so little power and operates of wider voltage ranges than traditional TTL circuitry.

http://www.deyes.sefton.sch.uk/technology/_themes/my-industrial/bullet1.gif

DRAM or dynamic random access memory effectively consists of capacitors which must be kept at a constant level of charge if they are to stored information. For this purpose refresh facilities regularly top up the charge on each cell. DRAM is much smaller than equivalent static RAM.

http://www.deyes.sefton.sch.uk/technology/_themes/my-industrial/bullet1.gif

ROM or read only memory is programmed during manufacture. We say it is non-volatile because its data is built in and is not lost if power is removed. ROM is often used to hold the operating system and other fixed data required by the microprocessor system.

http://www.deyes.sefton.sch.uk/technology/_themes/my-industrial/bullet1.gif

EPROM or erasable programmable read only memory is a type of ROM which can be programmed by electrical pulses and then erased by exposure to ultra-violet light through a quartz lens fitted into the top of each device. Once programmed the lens is covered by an opaque plastic or paper sticker. In this state the EPROM provides non-volatile ROM.

http://www.deyes.sefton.sch.uk/technology/_themes/my-industrial/bullet1.gif

EEPROM or electrically erasable programmable read only memory is similar to EPROM but is erased as well as programmed using electrical pulses. It has the flexibility of battery backed CMOS RAM but does not require the battery back up. It will store data indefinitely until reprogrammed. EEPROM is used in most modern PLC's and PIC's primarily for this reason but writing data into an EEPROM does take longer than into RAM. For most applications however this is not a problem.

The current developments in solid state technology and a move towards ever increasing miniaturisation means that in modern PLC's and PIC's most if not all the memory requirements are provided on a single chip.

THE CPU

This is the microprocessors 'brain' - what it can do depends to a large extent on the set of instructions (called the instruction set) which it is designed to work with.

Typically a CPU consists of 3 main parts:

http://www.deyes.sefton.sch.uk/technology/_themes/my-industrial/bullet1.gif

The ALU

http://www.deyes.sefton.sch.uk/technology/_themes/my-industrial/bullet1.gif

The Registers

http://www.deyes.sefton.sch.uk/technology/_themes/my-industrial/bullet1.gif

The Control Unit

http://www.deyes.sefton.sch.uk/technology/images/A-%20Level/mic-con/microp2.gif

The ALU or Arithmetic Logic Unit performs all the arithmetic or logical functions.

The Registers are shift registers where data to be processed can be fed in and temporarily stored. The number and purpose of the registers varies from one microprocessor to another but one of these shift registers is used as a program counter to provide the addresses fed onto the address bus. Another register is used as the accumulator which contains the data being processed at any one time.

The Control unit is linked to a clock which generates pulses at a frequency measured in megahertz. Its purpose is to control and synchronize the way data is processed.

The Instruction register holds each instruction while it is decoded by the Instruction decoder which then sends a signal to the control circuitry to enable the instruction to be executed.

As an example let's look at just one machine cycle. The first cycle in a program.

The content of program counter initially 0000 0000 is placed on the address bus.

The instruction in this first address is 'read out of memory' and placed on the data bus

The instruction is held in the instruction register whilst it is decoded into a signal that goes to the control circuitry. This then carries out the instruction.

Let us suppose the instruction was to load a number stored in memory into the accumulator.

The program counter increments to 0000 0001 the contents of this address are placed on the data bus and the control circuitry loads this into the accumulator.

http://www.deyes.sefton.sch.uk/technology/images/A-%20Level/mic-con/microp3.gif

If we wanted to add the data stored in the accumulator to another number stored at a different address, the program must give the necessary instructions to shift the first number from the accumulator into one of the internal registers and to then read the second number and place this in the accumulator.

An instruction to then add the contents of the accumulator to the contents of the internal register can be sent to the ALU and the result can then be stored in the accumulator for transfer to the output unit.

Number Systems

Writing down groups of binary digits such as 1001 1110 can be cumbersome and confusing we often convert binary numbers into decimal (base10), Octal (base 8), hexadecimal (base 16) or binary-coded decimal numbers.

Each of these number systems is described below.

Binary

The binary number system uses two counting digits (1 and 0). We write a binary number with its most significant bit (MSB) furthest to the left and its least significant bit (LSB) furthest to the right so that it is organised in ascending powers of 2 starting with the least significant bit.

the diagram below should explain the conversion from binary to decimal quite clearly.

Bit 7 (MSB)

Bit 1 (LSB)

1

0

1

1

0

1

0

1

128

64

32

16

8

4

2

0

27

26

25

24

23

22

21

20


Binary 10110101 = (1x128)+(0x64)+(1x32)+(1x16)+(0x8)+(1x4)+(0x2)+(1x1)

Octal

The octal (base 8) number system uses a set of eight digits (0 to 7). Octal numbers are organised in ascending powers of 8. For example:

The octal number 321 = (3x82)+(2x81)+(1x80) = (3x64)+(2x16)+(1x1) = 209 in decimal

To convert a binary number to octal you need to split it into groups of three bits. This is because the octal numbers 0 to 7 represent the 3-bit binary numbers 000 to 111.

Octal

7

6

5

4

3

2

1

0

Binary

111

110

101

100

011

010

001

000

The diagram below demonstrates how to convert an eight bit binary number to octal and then decimal:

8 bit binary number 11111101

Split into groups of three bits 011 111 101

Octal number 3 7 5

Decimal number 3x82 + 7x81 + 5x80 = 192 + 56 + 5 = 253

Hexadecimal

The hexadecimal number system (base16) uses a set of sixteen digits (0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, F). The letters A to F represent the numbers 10 to 15. Hexadecimal numbers are organised in ascending powers of 16.

Converting the number 321 used in the previous example from hexadecimal to decimal = (3x162) + (2x161) + (1x160) = (3x256) + (2x16) + (1x1) = 768 + 32 + 1 = 801.

To convert a binary number to hexadecimal you need to split the number into groups of four bits. This is because the hexadecimal numbers 0 to F represent four bit numbers ranging from 0000 to 1111.

Hexadecimal

F

E

D

C

B

A

9

8

7

6

5

4

3

2

1

0

Binary

1111

1110

1101

1100

1011

1010

1001

1000

0111

0110

0101

0100

0011

0010

0001

0000

The diagram below demonstrates how to convert an eight bit binary number to hexadecimal and then decimal:

8 bit binary number 10101100

Split into groups of four bits 1010 1100

Hexadecimal number A C

Decimal number A(10)x161 + C(12)x160 = 10x16 + 12x1 = 172

Binary-Coded Decimal

Binary-coded decimal (BCD) numbering, codes decimal numbers into 4-bit binary numbers. The digits 0 to 9 are represented by the numbers 0000 to 1001.

BCD

9

8

7

6

5

4

3

2

1

0

Binary

1001

1000

0111

0110

0101

0100

0011

0010

0001

0000

The diagram below demonstrates how to convert a decimal number to BCD

Decimal number 954

Binary Coded Decimal 1001 0101 0100

http://www.deyes.sefton.sch.uk/technology/_themes/my-industrial/bullet1.gif

See how a microprocessor works at Intel's Site

Programming

All the systems that you have built or investigated using discreet components have their function decided by the connections you make between the various components. They are known as dedicated systems because they are built to do just one thing. For example you will have seen how D type flip-flops can be used to build a four bit binary counter, a latch or a shift register, depending on how you connect them up. Once built they will only perform one of these tasks. We say they have been hard wired. you can only change their function by re-wiring them.

A programmable system such as a microprocessor however, can have its function changed without changing any of its connections. To communicate with a microprocessor we must give it instructions (called a program) so that it knows what it must do and how to do it. The program tells the CPU the order in which it has to perform the various operations provided by its instruction set. Different tasks require these operations to be performed in different ways. Each task will have a different program written for it.

At its most basic level programming can be done in machine code. This is the series of 0's and 1's which a microprocessor has to work with. Writing programs in this way however is tedious, difficult and inevitably leads to errors which make the program fail.

To make programming more intelligible program languages have been developed which make the task of writing a program less difficult.

There are two main types:

http://www.deyes.sefton.sch.uk/technology/_themes/my-industrial/bullet1.gif

Low level or assembly language.

http://www.deyes.sefton.sch.uk/technology/_themes/my-industrial/bullet1.gif

High level languages

Low level or assembly languages

Programs for these are written in mnemonics (memory aids). They are provided in an instruction set which must be adhered to. The mnemonic for 'loading the contents of a memory address into the accumulator' might be LDA and the binary code for the operation 1001 1110. This is more conveniently written in hexadecimal code (which is 9E). Conversion of these inputs into machine code is done by a program usually stored in ROM called an assembler.

High level languages

Programs for these are written using commands which are much easier to understand and remember since they use terms such as Load, Add , Compare, Build etc. The one big drawback is that they need more memory space and computer time because each statement has to be decoded into a number of machine code instructions. A compiler or an interpreter (similar to the assembler program) does the translation into machine code. BASIC, LOGO and PASCAL are all examples of high level languages