microcomputer interfacing.pdf

110
8/13/2019 Microcomputer Interfacing.pdf http://slidepdf.com/reader/full/microcomputer-interfacingpdf 1/110 Microcomputer Interfacing SSP 3312 Lecturer : *Dr Abd Rahman Tamuri Assoc. Prof Dr Yaacob Mat Daud Mr Mohd Khalid Kasmim Dr Abdul Khamim Ismail Email : [email protected]

Upload: karuna-avatara-dasa

Post on 04-Jun-2018

234 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Microcomputer Interfacing.pdf

8/13/2019 Microcomputer Interfacing.pdf

http://slidepdf.com/reader/full/microcomputer-interfacingpdf 1/110

Microcomputer Interfacing

SSP 3312

Lecturer : *Dr Abd Rahman TamuriAssoc. Prof Dr Yaacob Mat DaudMr Mohd Khalid KasmimDr Abdul Khamim Ismail

Email : [email protected]

Page 2: Microcomputer Interfacing.pdf

8/13/2019 Microcomputer Interfacing.pdf

http://slidepdf.com/reader/full/microcomputer-interfacingpdf 2/110

Lecture 01

Interfaces and Interfacing• Definitions of “ interface ” from Webster ’s Dictionary:

• noun: the place at which independent systems meetand act or communicate with each otherexamples:

human - machine interface (analogue-machine interface)terminal - network interface TTL - CMOS interface

2

parallel or serial interface

• Informal Definitioni) The physical, electrical and logical means of

exchanging Information with a functional moduleii) The process of enabling a computer to communicate

with the external world through Software, Hardwareand Protocols

Page 3: Microcomputer Interfacing.pdf

8/13/2019 Microcomputer Interfacing.pdf

http://slidepdf.com/reader/full/microcomputer-interfacingpdf 3/110

Lecture 01• An interface is a device and/or set of rules to match the

output of one device to send information to the input ofanother device

• physical connection• the hardware• rules and procedures• the software

3

• Interfacing is the process of connecting devices togetherso that they can exchange information

The process of reading input signals and sending outputsignals is called I/O

• I/O conventions• I/O direction is relative to the MCU• Input is data read by the MCU•

Output is data sent out by the MCU

Page 4: Microcomputer Interfacing.pdf

8/13/2019 Microcomputer Interfacing.pdf

http://slidepdf.com/reader/full/microcomputer-interfacingpdf 4/110

Lecture 01

Why is computer interfacing important ?

1. The human - machine interface determines the ultimatesuccess or failure of many computer- based systems

2. Digital systems exist within and must successfully interactwith an analo ue natural environment Di ital - analo ue

4

interfaces are unavoidable)

3. Rather than designing digital systems from elementarycomponents, computer engineers more typicallyassemble new systems from existing subsystems

Page 5: Microcomputer Interfacing.pdf

8/13/2019 Microcomputer Interfacing.pdf

http://slidepdf.com/reader/full/microcomputer-interfacingpdf 5/110

Lecture 01Typical Interfacing Activities• Selecting software/hardware subsystems that can (at least

potentially) interact well with each other• Appropriate D/A and A/D converters (speed, accuracy, …)• Serial vs. parallel communication

• Providing appropriate hardware connections• Selecting cabling, connectors, drivers, receivers, correct termination, etc.

5

• CMOS with TTL

• Configuring hardware interfaces correctly using low-levelsoftware drivers

LCD, Keypads in embedded systems• Interfacing software components correctly

• Selecting compatible software versions• Calling the correct procedures in the correct sequence with the correct

parameters

Page 6: Microcomputer Interfacing.pdf

8/13/2019 Microcomputer Interfacing.pdf

http://slidepdf.com/reader/full/microcomputer-interfacingpdf 6/110

Lecture 01

System-Level Interfaces

Human-MachineInterface

-

Digital-

InterfaceAnalogue

HumanUsers

AnalogueEnvironment

6

Human-machine interface• Input devices: keyboard, mouse, microphone, camera• Output devices: CRT, printer, light panel, audio amp

-

Other Digital Systems

Page 7: Microcomputer Interfacing.pdf

8/13/2019 Microcomputer Interfacing.pdf

http://slidepdf.com/reader/full/microcomputer-interfacingpdf 7/110

Lecture 01

Digital - Analogue Interface• Input devices: A/D converters, modems, sensors• Output devices: D/A converters, modems, transducers

actuators, stepper motors• Control devices: switches, multiplexers, amplifiers

attenuators

7

Digital - Digital Interface• Connectors: wires, ribbon cable, coax, twisted pair, PCB•

I/O devices: buffers, level-shifters, synchronizers

Page 8: Microcomputer Interfacing.pdf

8/13/2019 Microcomputer Interfacing.pdf

http://slidepdf.com/reader/full/microcomputer-interfacingpdf 8/110

Lecture 01

Hardware Interfaces within a Personal Computer (PC)(greatly simplified)

SerialPort Keyboard

Lab Board

8

DisketteController

MemoryController

DisketteDrive

HardDrive

DiscController

MainMemory

ontro er

Mouse

ParallelPortController

Printer

VideoController CRT

Page 9: Microcomputer Interfacing.pdf

8/13/2019 Microcomputer Interfacing.pdf

http://slidepdf.com/reader/full/microcomputer-interfacingpdf 9/110

Lecture 01

Standard Microcomputer Interfaces• Parallel Interface• Serial Interface• Universal Serial Interface (USB)

Other Interfaces

9

• General Purpose Interface Bus (GPIB)• Custom Interfaces

Page 10: Microcomputer Interfacing.pdf

8/13/2019 Microcomputer Interfacing.pdf

http://slidepdf.com/reader/full/microcomputer-interfacingpdf 10/110

Lecture 01Parallel Interface• Originally known as Centronic parallel interface• Centronic parallel interface is an older and still widely-used standard I/O

interface for connecting printers and certain other devices to computers• The interface typically includes a somewhat cumbersome cable and a 36- pin

male and female connector at the printer or other device• The cable plugs into a 25-pin parallel port on the computer• Data flows in one direction only, from the computer to the printer or other

device

10

• n a t on to e g t para e ata nes, ot er nes are use to rea statusinformation and send control signals

• Centronics Corporation designed the original Centronics parallel interface fordot matrix printers.

• When the Centronics parallel interface was first developed, the mainperipheral was the printer

• Since then, portable disk drives, tape backup drives, and CD-ROM players areamong devices that have adopted the parallel interface

• These new uses caused manufacturers to look at new ways to make theCentronics parallel interface better

Page 11: Microcomputer Interfacing.pdf

8/13/2019 Microcomputer Interfacing.pdf

http://slidepdf.com/reader/full/microcomputer-interfacingpdf 11/110

Lecture 01• In 1991, Lexmark, IBM, Texas instruments, and others met to discuss a

standard that would offer more speed and bi-directional communication• Their effort and the sponsorship of the IEEE resulted in the IEEE 1284committee. The IEEE 1284 standard was approved for release in March, 1994

• The IEEE 1284 standard specifies five modes of operation, each modeproviding data transfer in either the forward direction (computer to peripheral),backward direction (peripheral to computer), or bi-directional (one direction ata time)

• Compatibility mode

11

• e or g na en ron cs para e n er ace an n en e or use w omatrix printers and older laser printers

• The compatibility mode can be combined with the nibble mode for bi-directional data transfer.

• Nibble mode• allows data transfer back to the computer• The nibble mode uses the status lines to send 2 nibble s (4-bit units)

of data to the computer in two data transfer cycles• This mode is best used with printers.

Page 12: Microcomputer Interfacing.pdf

8/13/2019 Microcomputer Interfacing.pdf

http://slidepdf.com/reader/full/microcomputer-interfacingpdf 12/110

Lecture 01• Byte mode

uses software driver s to disable the drivers that control the data linesin order for data to be sent from the printer to the computer

• The data is sent at the same speed as when data is sent from thecomputer to the printer

• One byte of data is transferred instead of the two data cycles requiredby the nibble mode.

• ECP mode (Enhanced Capability Port mode)• an advanced bi-directional mode for use with printers and scanners

12

• a ows a a compress on or mage s, rs n, rs ou oritems in queue s, and high-speed, bi-directional communication

• Data transfer occurs at two to four megabytes per second. Anadvanced feature of ECP is channel addressing

• This is used for multifunction devices such as printer/fax/modem

devices• For example, if a printer/fax/modem device needs to print and send

data over the modem at the same time, the channel address softwaredriver of the ECP mode assigns a new channel to the modem so thatboth devices can work simultaneously.

Page 13: Microcomputer Interfacing.pdf

8/13/2019 Microcomputer Interfacing.pdf

http://slidepdf.com/reader/full/microcomputer-interfacingpdf 13/110

Lecture 01

• EPP mode (Enhanced Parallel Port mode)• designed by Intel, Xircom, and Zenith Data Systems to provide a

high-performance parallel interface that could also be used with thestandard interface

• EPP mode was adopted as part of the IEEE 1284 standard•

The EPP mode uses data cycles that transfer data between thecomputer and the peripheral and address cycles that assign address,

13

channel, or command information• This allows data transfer speeds of 500 kilobytes to 2 megabytes per

second, depending on the speed of the slowest interface• The EPP mode is bi-directional• It is suited for network adapters, data acquisition, portable hard

drives, and other devices that need speed

Page 14: Microcomputer Interfacing.pdf

8/13/2019 Microcomputer Interfacing.pdf

http://slidepdf.com/reader/full/microcomputer-interfacingpdf 14/110

Lecture 01Serial port• Standard PC serial ports come in to versions: 9 pin and 25 pin one• The functions of those both version are exactly the same, only different kind of

connectors and different pinout• PC serial port is nowadays usually used for interfacing PC to modem or mouse• Original PC serial port was designed to operate up to 19.2 kbit/s (maximum

speed defined in RS-232C standard) but nowadays they can typically go up to115.2 kbit/s (some special cards can do even faster than that)

PC serial port send and receives data in serial format• In serial as nchronous data transfer the individual bits which com rise each

14

data byte are sent one after the other over a single line

• In this context, asynchronous means that the clock information is not includedwith the transmission, so that frequent re-synchronization using start/stop bitsis required

• The maximum length specified by RS-232 is only 50 feet (around 15 meters),however much longer lengths are possible with proper shielding on the cable

• Generally you can run 9600 bps communication up to 250 feet (80 meters)over shielded data cable or unshielded twisted pair cable in good environment

• When using shielded cable and slower data rate longer lengths are possible(up to hundreds of meters in good conditions)

Page 15: Microcomputer Interfacing.pdf

8/13/2019 Microcomputer Interfacing.pdf

http://slidepdf.com/reader/full/microcomputer-interfacingpdf 15/110

Lecture 01• The processing element of PC serial port is the UART•

UART is an integrated circuit used for serial communications, containing atransmitter (parallel-to-serial converter) and a receiver (serial-to-parallelconverter), each clocked separately

• The parallel side of a UART is connected to computer bus (usually ISA bus)• When the computer writes a byte to the UART's transmit data register (TDR),

the UART will start to transmit it on the serial line• The UART's status register contains a flag bit which the computer can read to

see if the UART is ready to transmit another byte

15

• no er s a us reg s er says w e er e as rece ve a y e romthe serial line, in which case the computer should read it from the receive dataregister (RDR)

• If incorrectly formated data is received the UART may signal a "framing error"or "parity error “

• The UART may be set up to interrupt the computer when data is received orwhen ready to transmit more data

• Data on the serial line is formatted by the UART according to the setting of theUART's control register

• Those registers control the baud rate, number of data bits, number of stop bitsand what kind of parity is used (odd, even or none).

Page 16: Microcomputer Interfacing.pdf

8/13/2019 Microcomputer Interfacing.pdf

http://slidepdf.com/reader/full/microcomputer-interfacingpdf 16/110

Lecture 01

• The original UART chip shipped with the IBM personal computer was the 8250• This chip was limited to 9600 bps maximum rate• It was replaced with the 16450 which had the same architecture as the 8250

but has a higher maximum bps specification (115200 bps)• Both of the chips only have a one byte FIFO/buffer• The newer 16550 UART contains a 16-byte buffer which helps the computer in

the communications and makes faster communication speeds without lostcharacters possible

16

• A 16-byte FIFO allows up to 16 characters to be received before the computerhas to service the interrupt

• There are also other UARTs with longer FIFOs• When operating under DOS at speeds below 9600 bps the 16450 should

provide satisfactory performance• When operating under any Windows or other multitasking operating system, a

16450 will be limited to about 1200 or 2400 bps reliable communication 16550or similar UART will work on multitasking enviroment at high speeds verynicely.

Page 17: Microcomputer Interfacing.pdf

8/13/2019 Microcomputer Interfacing.pdf

http://slidepdf.com/reader/full/microcomputer-interfacingpdf 17/110

Lecture 01

• Having FIFO in the UART means that the computer need to have interruptsless often, which means less processing power wasted on the serialcommunications and less likely that data is lost if it takes some time frominterrupt request that actual interrupt happens

• The UART's serial connections go via separate line driver and line receiverintegrated circuits which provide the power and voltages (+12V and -12V)required to drive the serial line and give some protection against noise on theline.

17

• Most modern PC serial cards and built-in serial ports are designed formaximum 115200 bps data rate

• There are also some special serial port card which can handlealso higher datarates (quadruple the clock speed (4X) will allow transmission speeds up to460,800 bps and a card with 8X setting will allow speeds up to 921,400 bps).

Page 18: Microcomputer Interfacing.pdf

8/13/2019 Microcomputer Interfacing.pdf

http://slidepdf.com/reader/full/microcomputer-interfacingpdf 18/110

Lecture 01

Universal Serial Bus (USB)• USB, or the Universal Serial Bus Interface is now well established as

an interface for computer communications• In many areas it has completely overtaken RS232 and the parallel or

Centronics interface for printers, and it is also widely used for memorysticks, computer mice, keyboards and for many other functions

• One of the advantages of USB is its flexibility: another is the speed

18

that USB provides• USB provides a sufficiently fast serial data transfer mechanism for data

communications, however it is also possible to obtain power throughthe connector and this has further added to the popularity of USB as

many small computer peripherals may be powered via this• From memory and disk drives to other applications such as small fansand coffee cup warmers, the USB port on computers can be used for avariety of tasks

Page 19: Microcomputer Interfacing.pdf

8/13/2019 Microcomputer Interfacing.pdf

http://slidepdf.com/reader/full/microcomputer-interfacingpdf 19/110

Lecture 01

USB Evolution• The Universal Serial Bus (USB) was born out of the frustration PC

users experience trying to connect an incredibly diverse range ofperipherals to their computers

• It was developed as a result of the need for a communicationsinterface that was convenient to use and one that would support thehigher data rates being required within the computer and peripherals

19

industries• Universal Serial Bus came into life when a group of 7 companies :

Compaq, Digital Equipment, IBM, Intel, Microsoft and NorthernTelecom decides to form a specifications to merge legacy connectivity

such as RS232, Printer port, PS2 port into a single common connectorto the Personal Computer• The first proper release of a USB specification was Version 0.7 of the

specification. This occurred in November 1994. This was followed inJanuary 1996 by USB 1.0. USB 1.0 was widely adopted and becamethe standard on many PCs as well as many printers using the standard

Page 20: Microcomputer Interfacing.pdf

8/13/2019 Microcomputer Interfacing.pdf

http://slidepdf.com/reader/full/microcomputer-interfacingpdf 20/110

Lecture 01

• The motivation of differentiating two transfer speed was to maintain thelow-cost implementation of computer peripherals such as keyboardsand mice, and, still allow higher speeds devices such that printers andscanners to be able to use the same serial bus

• USB was agreed to as a standard by Microsoft, Compaq and manyother large names in PC industry

• USB 1.0 standard was finally issued in 1996

20

• was a er mo e o . . ers on . was e vere onSeptember 1998

• The 1.1 specifications clarified many timing parameters which weregrey-areas in the past. However, no huge "functional" improvementswere given

Page 21: Microcomputer Interfacing.pdf

8/13/2019 Microcomputer Interfacing.pdf

http://slidepdf.com/reader/full/microcomputer-interfacingpdf 21/110

Lecture 01

• In addition to this a variety of other peripherals adopted the USBinterface, with small memory sticks starting to appear as a convenientway for transferring or temporarily storing data

• With USB 1.0 well established, faster data transfer rates wererequired, and accordingly a new specification, USB 2 was released

• With the importance of USB already established it did not take long forthe new standard to be adopted

21

• e n ng s p ace n e mar e , o er eve opmen s o estandard were investigated

• With the need for mobility in many areas of the electronics industrytaking off, the next obvious move for USB was to adopt a wirelessinterface

• In doing this wireless USB would need to retain the same flexibleapproach that provided the success for the wired interface

• In addition to this the wireless USB interface needs to be able totransfer data at rates which will be higher than those currentlyattainable with the wired USB 2 connections

To achieve this ultra-wideband UWB technology is used

Page 22: Microcomputer Interfacing.pdf

8/13/2019 Microcomputer Interfacing.pdf

http://slidepdf.com/reader/full/microcomputer-interfacingpdf 22/110

THANK YOU

22

Page 23: Microcomputer Interfacing.pdf

8/13/2019 Microcomputer Interfacing.pdf

http://slidepdf.com/reader/full/microcomputer-interfacingpdf 23/110

Universal Serial Bus

(USB)Lecturer:

Dr Abd Rahman Tamuri,PM Dr Yaacob Mat Daud,Mr Mohd Khalid Kasmin,Dr Abdul Khamim Ismail.

Page 24: Microcomputer Interfacing.pdf

8/13/2019 Microcomputer Interfacing.pdf

http://slidepdf.com/reader/full/microcomputer-interfacingpdf 24/110

Lecture 02

• Universal Serial Bus (USB ) is a serial bus standard to interfacedevices

• USB was designed to allow many peripherals to be connected using asingle standardized interface socket and to improve the plug-and-playcapabilities by allowing devices to be connected and disconnectedwithout rebooting the computer (hot swapping)

Introduction

2

• er conven en ea ures nc u e prov ng power o ow-consump ondevices without the need for an external power supply and allowingmany devices to be used without requiring manufacturer specific,individual device drivers to be installed

• The USB "trident" Icon:

Page 25: Microcomputer Interfacing.pdf

8/13/2019 Microcomputer Interfacing.pdf

http://slidepdf.com/reader/full/microcomputer-interfacingpdf 25/110

Lecture 02USB Interface• a serial data-transmission system that uses cables to connect

peripheral equipment to PCs

• USB system is master-slave type bus• The PC is the master that supplied power to the bus and controls the

bus operation• The peripheral equipment connected to USB bus just follow the PC

3

controlling

• USB system -complicated, to interface something to USB, needpractically always use special ICs designed for USB interfacing

• Those ICs typically include USB controllers and general purposemicrocontrollers with built-in USB controllers.

Page 26: Microcomputer Interfacing.pdf

8/13/2019 Microcomputer Interfacing.pdf

http://slidepdf.com/reader/full/microcomputer-interfacingpdf 26/110

Lecture 02• A USB system has an asymmetric design, consisting of a host, a

multitude of downstream USB ports, and multiple peripheral devicesconnected in a tiered-star topology

• Additional USB hubs may be included in the tiers, allowing branchinginto a tree structure, subject to a limit of 5 levels of tiers

• USB host may have multiple host controllers and each host controllermay provide one or more USB ports

• Up to 127 devices, including the hub devices, may be connected to a

4

s ng e os con ro er

A conventional USB hub

Page 27: Microcomputer Interfacing.pdf

8/13/2019 Microcomputer Interfacing.pdf

http://slidepdf.com/reader/full/microcomputer-interfacingpdf 27/110

Lecture 02Types of USB Connectors

5

Pin configuration of the USB connectorsStandard A/B, viewed from face of plug:

Page 28: Microcomputer Interfacing.pdf

8/13/2019 Microcomputer Interfacing.pdf

http://slidepdf.com/reader/full/microcomputer-interfacingpdf 28/110

Lecture 02• Standard-A

! 4 x 12 mm Standard -A

• Standard-B! 7 x 8 mm Standard -B

USB TYPESThe data slots in A-Plug are actually

farther in the plug thanthe outside power wiresto prevent data errorsby powering the devicefirst, then transferringdata

6

• Micro-A and Micro-B plugsapproximately 2 by 7 mm

• are used for smaller devicessuch as PDAs, mobilephones or digital cameras

Mini-B, Micro-A, Micro-B , and Micro-AB

Page 29: Microcomputer Interfacing.pdf

8/13/2019 Microcomputer Interfacing.pdf

http://slidepdf.com/reader/full/microcomputer-interfacingpdf 29/110

Lecture 02

USB Cables• The maximum length of a standard USB cable is 5.0 meters (16.4 ft)• The primary reason for this limit is the maximum allowed round-trip

delay of about 1500 ns• If a USB device does not answer to host commands within the allowed

time, the host considers the command to be lost• When USB device response time, delays from using the maximum

7

number of hubs and delays from cables connecting the hubs, host anddevice are summed, the maximum delay caused by a single cableturns out to be 26 ns

• The USB 2.0 specification states that the cable delay must be less

than 5.2 ns per meter, which means that maximum length USB cable is5 meters long• However, this is also very close to the maximum possible length when

using a standard copper cable

Page 30: Microcomputer Interfacing.pdf

8/13/2019 Microcomputer Interfacing.pdf

http://slidepdf.com/reader/full/microcomputer-interfacingpdf 30/110

Lecture 02

USB Cable

8

Data Cable• The data cables are a twisted pair to reduce noise and crosstalk

Page 31: Microcomputer Interfacing.pdf

8/13/2019 Microcomputer Interfacing.pdf

http://slidepdf.com/reader/full/microcomputer-interfacingpdf 31/110

Page 32: Microcomputer Interfacing.pdf

8/13/2019 Microcomputer Interfacing.pdf

http://slidepdf.com/reader/full/microcomputer-interfacingpdf 32/110

Lecture 02

USB Connectors• All devices have an upstream connection to the host and all hosts

have a downstream connection to the device• Upstream and downstream connectors are not mechanically

interchangeable, thus eliminating illegal loopback connections at hubssuch as a downstream port connected to a downstream port

• There are commonly two types of connectors, called type A and type B

10

which are shown below• Type A plugs always face upstream• Type A sockets will typically find themselves on hosts and hubs• For example type A sockets are common on computer main boards

and hubs

Page 33: Microcomputer Interfacing.pdf

8/13/2019 Microcomputer Interfacing.pdf

http://slidepdf.com/reader/full/microcomputer-interfacingpdf 33/110

Lecture 02

• Type B plugs are always connected downstream and consequentlytype B sockets are found on devices

• It is interesting to find type A to type A cables wired straight throughand an array of USB gender changers in some computer stores

• This is in contradiction of the USB specification• The only type A plug to type A plug devices are bridges which are used

to connect two computers together

11

• er pro e ca es are ex ens ons w c as a p ug on oneend (either type A or type B) and a socket on the other

• These cables violate the cable length requirements of USB• USB 2.0 included errata which introduces mini-usb B connectors• The reasoning behind the mini connectors came from the range of

miniature electronic devices such as mobile phones and organisers.The current type B connector is too large to be easily integrated intothese devices

Page 34: Microcomputer Interfacing.pdf

8/13/2019 Microcomputer Interfacing.pdf

http://slidepdf.com/reader/full/microcomputer-interfacingpdf 34/110

Lecture 02

Power (V BUS )• One of the benefits of USB is bus-powered devices - devices which

obtain its power from the bus and requires no external plug packs oradditional cables

• However many leap at this option without first considering all thenecessary criteria

• A USB device specifies its power consumption expressed in 2mA units

12

in the configuration descriptor• A device cannot increase its power consumption, greater than what it

specifies during enumeration, even if it looses external power• There are three classes of USB functions

• Low-power bus powered functions• High-power bus powered functions• Self-powered functions

• Low power bus powered functions draw all its power from the V BUS andcannot draw any more than one unit load

• The USB specification defines a unit load as 100mA

Page 35: Microcomputer Interfacing.pdf

8/13/2019 Microcomputer Interfacing.pdf

http://slidepdf.com/reader/full/microcomputer-interfacingpdf 35/110

Lecture 02

Data Signaling Rate• Another area which is often overlooked is the tolerance of the USB

clocks• This is specified in the USB specification

• High speed data is clocked at 480.00Mb/s with a data signallingtolerance of ± 500ppm

• Full speed data is clocked at 12.000Mb/s with a data signalling

13

tolerance of ± 0.25% or 2,500ppm• Low speed data is clocked at 1.50Mb/s with a data signalling

tolerance of ± 1.5% or 15,000ppm• This allows resonators to be used for low cost low speed devices, but

rules them out for full or high speed devices

Page 36: Microcomputer Interfacing.pdf

8/13/2019 Microcomputer Interfacing.pdf

http://slidepdf.com/reader/full/microcomputer-interfacingpdf 36/110

14

Page 37: Microcomputer Interfacing.pdf

8/13/2019 Microcomputer Interfacing.pdf

http://slidepdf.com/reader/full/microcomputer-interfacingpdf 37/110

Introduction

to Microcontroller

Lecturer : Dr Abd Rahman Tamuri & Dr Yaacob Mat Daud

Physics Department, Faculty of Science,Universiti Teknologi Malaysia, 81310, JB

[email protected]

Page 38: Microcomputer Interfacing.pdf

8/13/2019 Microcomputer Interfacing.pdf

http://slidepdf.com/reader/full/microcomputer-interfacingpdf 38/110

Embedded System• You are used to chips like the Pentium and the Athlon, but in terms ofinstalled machines these are a small portion of total computer use.Think how many computers you have at home?

• Digital cameras, video cameras, TVs, mobile phones, calculators,

micro-wave ovens etc all contain processors.In order for a

INTRODUCTION TO MICROCONTROLLER 2

, ,components for receiving and sending data must be added to it.

• On the other hand, microcontroller is designed to be all of that in one.• No other external components are needed for its application because

all necessary peripherals are already built into it.• Thus, we save the time and space needed to construct devices.• The PICmicro was originally designed around 1980 by General

Instrument as a small, fast , inexpensive embedded microcontrollerwith strong I/O capabilities.

Page 39: Microcomputer Interfacing.pdf

8/13/2019 Microcomputer Interfacing.pdf

http://slidepdf.com/reader/full/microcomputer-interfacingpdf 39/110

Characteristics of Embedded System

• Embedded computers have to be very low cost, simple andreliable.

• They can not use any moving parts (disk drives) because:1. power hungry

INTRODUCTION TO MICROCONTROLLER 3

2. bulky3. expensive

Page 40: Microcomputer Interfacing.pdf

8/13/2019 Microcomputer Interfacing.pdf

http://slidepdf.com/reader/full/microcomputer-interfacingpdf 40/110

Features of Embedded System

• Program in Read Only Memory – ROM• Limited RAM storage – variables only not code• Built in I/O devices• Use very little power

Embedded S stem General Block Dia ram

INTRODUCTION TO MICROCONTROLLER 4

Page 41: Microcomputer Interfacing.pdf

8/13/2019 Microcomputer Interfacing.pdf

http://slidepdf.com/reader/full/microcomputer-interfacingpdf 41/110

Components of a Computer System

INTRODUCTION TO MICROCONTROLLER 5

Page 42: Microcomputer Interfacing.pdf

8/13/2019 Microcomputer Interfacing.pdf

http://slidepdf.com/reader/full/microcomputer-interfacingpdf 42/110

Microcontroller

• Microcontrollers, as the name suggests, are small controllers• They are like single chip computers that are often embedded into other

systems to function as processing/controlling unit• For example, the remote control you are using probably has

microcontrollers inside that do decoding and other controlling functions• They are also used in automobiles, washing machines, microwave

INTRODUCTION TO MICROCONTROLLER 6

ovens, toys ... etc, w ere automat on s nee e• The key features of microcontrollers include:

• High Integration of Functionality• Microcontrollers sometimes are called single-chip computers

because they have on-chip memory and I/O circuitry and othercircuitries that enable them to function as small standalonecomputers without other supporting circuitry

Page 43: Microcomputer Interfacing.pdf

8/13/2019 Microcomputer Interfacing.pdf

http://slidepdf.com/reader/full/microcomputer-interfacingpdf 43/110

• Field Programmability, Flexibility•

Microcontrollers often use EEPROM or EPROM as theirstorage device to allow field programmability so they areflexible to use

• Once the program is tested to be correct then large quantitiesof microcontrollers can be programmed to be used inembedded systems

INTRODUCTION TO MICROCONTROLLER 7

• Assembly language is often used in microcontrollers and since

they usually follow a RISC architecture, the instruction set issmall

• The development package of microcontrollers often includes

an assembler, a simulator, a programmer to "burn" the chipand a demonstration board

• Some packages include a high level language compiler suchas a C compiler and more sophisticated libraries

Page 44: Microcomputer Interfacing.pdf

8/13/2019 Microcomputer Interfacing.pdf

http://slidepdf.com/reader/full/microcomputer-interfacingpdf 44/110

Microcontroller, Microprocessor and Microcomputer• A microcontrollers are is like a single chip computers that are often

embedded into other systems to function as processing/controlling unit• Microcontrollers are used in a wide number of electronic systems

such as:• Engine management systems in automobiles• Keyboard of a PC

INTRODUCTION TO MICROCONTROLLER 8

• Electronic measurement instruments (such as digitalmultimeters, frequency synthesisers, and oscilloscopes)

• A microprocessor is a programmable digital electronic componentthat incorporates the functions of a central processing unit (CPU) into asingle IC package

• These functions are• The ability to execute a stored set of instructions to carry out

user defined tasks• The ability to be able to access external memory chips to both

read and write data from and to the memory

Page 45: Microcomputer Interfacing.pdf

8/13/2019 Microcomputer Interfacing.pdf

http://slidepdf.com/reader/full/microcomputer-interfacingpdf 45/110

Page 46: Microcomputer Interfacing.pdf

8/13/2019 Microcomputer Interfacing.pdf

http://slidepdf.com/reader/full/microcomputer-interfacingpdf 46/110

Both ROM and EPROM memory are used to hold the programcode of a microprocessor used in an embedded system, ie. amicroprocessor used in an application where the program code isalways the same and is designed to execute every time thesystem is switched on

• Most development work is done using EPROM or EEPROM type

memory, ROM memory being used in the final production version

INTRODUCTION TO MICROCONTROLLER 10

w en a e program co e as een u y es e• Random Access Memory (RAM)

• All microprocessor systems need memory that can be both readfrom and written to - such memory is RAM

• RAM got its name because early read-write memories weresequential, and did not allow random access. RAM memory isused to store dynamic data (that will change during the operationof the program)

Page 47: Microcomputer Interfacing.pdf

8/13/2019 Microcomputer Interfacing.pdf

http://slidepdf.com/reader/full/microcomputer-interfacingpdf 47/110

RAM takes the form of integrated circuits that allow the stored datato be accessed in ANY order — that is, at random and without thephysical movement of the storage medium or a physical readinghead

• The word "random" infers that any piece of data can be returnedquickly, and in a constant time, regardless of its actual physical

location, in relation to the previous data storage location

INTRODUCTION TO MICROCONTROLLER 11

• e ey ene o s a re r eva mes are s or anconsistent. The disadvantages of RAM are cost, and the loss ofdata when power is turned off (volatile).

• A typical microprocessor system will contain both ROM (could beEPROM, EEPROM, or ROM) to store the program code, and RAM tostore dynamic data

Page 48: Microcomputer Interfacing.pdf

8/13/2019 Microcomputer Interfacing.pdf

http://slidepdf.com/reader/full/microcomputer-interfacingpdf 48/110

Input/Output (I/O)• I/O (input/output) is the collection of interfaces that different functional

devices, of any information processing system, use to communicatewith each other

• Every information transfer is an output from one device and an inputinto another

• For instance, on a computer, a keyboard and mouse are considered

INTRODUCTION TO MICROCONTROLLER 12

input devices while monitors and printers are considered outputdevices

• Typical devices for communication between computers, such asmodems and network cards, operate as both input and output devices

• I/O can be:• A number of digital bits formed into a number of digital inputs or

outputs called a port• These are usually eight bits wide and thus referred to as a BYTE

wide port. i.e. byte wide input port, byte wide output port

Page 49: Microcomputer Interfacing.pdf

8/13/2019 Microcomputer Interfacing.pdf

http://slidepdf.com/reader/full/microcomputer-interfacingpdf 49/110

A serial line from the microprocessor (Transmit or TX) and a serialline to the microprocessor (Receive or RX) allowing serial data inthe form of a bit stream to be transmitted or received via a two wireinterface

• Other I/O devices such as Analogue to Digital Converters (ADC)and Digital to Analogue Converters (DAC), Timer modules,

Interrupt controllers etc. (which will be discussed later in the

INTRODUCTION TO MICROCONTROLLER 13

con ex o m crocon ro ers• These are relatively complex sub systems that can be obtained as

separate Ics• They are connected to the microprocessor in a similar manner to that

of the memory devices.• Indeed, they often contain their own memory to support internal

operations (i.e. registers)

Page 50: Microcomputer Interfacing.pdf

8/13/2019 Microcomputer Interfacing.pdf

http://slidepdf.com/reader/full/microcomputer-interfacingpdf 50/110

Microcontroller Hardware• Basically, a microcontroller is a device which integrates a number of

the components of a microprocessor system onto a single chip (IC),with the following common features:

• The CPU core - ranging from simple 4-bit processors tosophisticated 32/64-bit processors

• Memory (both ROM and RAM)

INTRODUCTION TO MICROCONTROLLER 14

• Some parallel digital I/O

Main components of a microcontroller

CPU Memory I/O

Bus

Page 51: Microcomputer Interfacing.pdf

8/13/2019 Microcomputer Interfacing.pdf

http://slidepdf.com/reader/full/microcomputer-interfacingpdf 51/110

Most microcontrollers will alsocombine other devices such as:• A Timer module to allow the

microcontroller to perform tasksfor certain time periods

• A serial I/O port to allow data to

flow between the

Timer16 –Bit

RAM Area

CPU ADCPort

A

ROM Area Serial Port

Tx

Rx

8

88

INTRODUCTION TO MICROCONTROLLER 15

m crocon ro er an o erdevices such as a PC oranother microcontroller

• An ADC to allow themicrocontroller to acceptanalogue input data forprocessing

• The CPU is the processing moduleof the microcontroller.

A single chip microcontrollerand CPU

85

Page 52: Microcomputer Interfacing.pdf

8/13/2019 Microcomputer Interfacing.pdf

http://slidepdf.com/reader/full/microcomputer-interfacingpdf 52/110

Microcontrollers are nowadays brimming with added functionality onthis single IC and often include:• Communications Peripherals: SPI, I2C ™ , UART, CAN, USB,

Ethernet, IrDA ®, LIN• Control Peripherals: capture/compare, counters, real-time clock &

calendar, motor control & PWM• Integrated Display Drivers: LED, LCD

INTRODUCTION TO MICROCONTROLLER 16

• n-c p n erna osc a ors an ase- oc e oop c ose oopfeedback control)

• Analog Peripherals: A/D Converters, comparators, op amps,brown-out detection & reset, low voltage detection, temperaturesensors, D/A Converters and voltage regulators

Page 53: Microcomputer Interfacing.pdf

8/13/2019 Microcomputer Interfacing.pdf

http://slidepdf.com/reader/full/microcomputer-interfacingpdf 53/110

Memory in a microcontrollerThe amount of memory contained within a microcontrollervaries between different microcontrollersSome may not even have any integrated memory (eg.Hitachi 6503, now discontinued)However, most modern microcontrollers will have integrated

INTRODUCTION TO MICROCONTROLLER 17

memoryThe memory will be divided up into ROM and RAM, withtypically more ROM than RAM

Page 54: Microcomputer Interfacing.pdf

8/13/2019 Microcomputer Interfacing.pdf

http://slidepdf.com/reader/full/microcomputer-interfacingpdf 54/110

Page 55: Microcomputer Interfacing.pdf

8/13/2019 Microcomputer Interfacing.pdf

http://slidepdf.com/reader/full/microcomputer-interfacingpdf 55/110

Typically, the amount of ROM type memory will varybetween around 512 bytes and 4096 bytes

• Some 16 bit microcontrollers such as the Hitachi H8/3048can have as much as 128 Kbytes of ROM type memory

• ROM type memory, as has already been mentioned, isused to store the program code

INTRODUCTION TO MICROCONTROLLER 19

• ROM memory can be either ROM (as in One TimeProgrammable memory), EPROM, or EEPROM

Page 56: Microcomputer Interfacing.pdf

8/13/2019 Microcomputer Interfacing.pdf

http://slidepdf.com/reader/full/microcomputer-interfacingpdf 56/110

Microcontroller RAM• The microcontroller RAM is used to store data

Timer

16 –

RAM Area

CPU ADCPort

8

INTRODUCTION TO MICROCONTROLLER 20

ROM Area Serial Port

Port B Port C

TxRx

85

8

Page 57: Microcomputer Interfacing.pdf

8/13/2019 Microcomputer Interfacing.pdf

http://slidepdf.com/reader/full/microcomputer-interfacingpdf 57/110

Introduction to PIC

Microcontroller

Lecturer : Dr Abd Rahman Tamuri, Dr Yaacob Mat Daud

Physics Department, Faculty of Science,Universiti Teknologi Malaysia, 81310, JB

Page 58: Microcomputer Interfacing.pdf

8/13/2019 Microcomputer Interfacing.pdf

http://slidepdf.com/reader/full/microcomputer-interfacingpdf 58/110

Lecture 04

More on Microcontrollers• Microcontrollers integrate all the components of a computer system

onto a single chip• All components are optimized to perform the functions necessary to

control a larger system• Size, capability, cost, and power consumption are more important

considerations

2

• 8 bit microcontrollers have the majority of the market right now, but 16and 32 bit microcontrollers are available and gaining market share

Page 59: Microcomputer Interfacing.pdf

8/13/2019 Microcomputer Interfacing.pdf

http://slidepdf.com/reader/full/microcomputer-interfacingpdf 59/110

Lecture 04

Common Microcontrollers

3

Page 60: Microcomputer Interfacing.pdf

8/13/2019 Microcomputer Interfacing.pdf

http://slidepdf.com/reader/full/microcomputer-interfacingpdf 60/110

Microcontroller Manufacturers• There are lots of microcontroller manufacturers

PIC MICROCONTROLLER 4

Page 61: Microcomputer Interfacing.pdf

8/13/2019 Microcomputer Interfacing.pdf

http://slidepdf.com/reader/full/microcomputer-interfacingpdf 61/110

PIC MICROCONTROLLER 5

Page 62: Microcomputer Interfacing.pdf

8/13/2019 Microcomputer Interfacing.pdf

http://slidepdf.com/reader/full/microcomputer-interfacingpdf 62/110

The PICmicro was originally designed around 1980 byGeneral Instrument as a small, fast, inexpensive embeddedmicrocontroller with strong I/O capabilities.

• PIC stands for " Peripheral Interface Controller".

PIC MICROCONTROLLER 6

• General Instrument recognized the potential for the PICand eventually spun off Microchip, headquartered inChandler, AZ to fabricate and market the PICmicro.

Page 63: Microcomputer Interfacing.pdf

8/13/2019 Microcomputer Interfacing.pdf

http://slidepdf.com/reader/full/microcomputer-interfacingpdf 63/110

PIC Microcontroller• Range of low end 8 bit microcontrollers.• Smallest have only 8 pins, largest 40 pins.• Typical chip is an 18 pin one.• Very cheap, you can pick them up at less than £1 each.• Targeted at consumer products, burglar alarms etc.

PIC MICROCONTROLLER 7

Advantages of PIC• It is a RISC (Reduced Instruction Set Computer) design• Only thirty seven instructions to remember• Its code is extremely efficient, allowing the PIC to run with typically less

program memory than its larger competitors.• It is low cost, high clock speed

Page 64: Microcomputer Interfacing.pdf

8/13/2019 Microcomputer Interfacing.pdf

http://slidepdf.com/reader/full/microcomputer-interfacingpdf 64/110

Harvard architecture• Like many micros the PIC is a Harvard not a von-Neumann

machine• This is simpler and faster• Separate program bus and data bus: can be different

widths!

PIC MICROCONTROLLER 8

• For example, PICs use: – Data memory (RAM): a small number of 8bitregisters – Program memory (ROM): 12bit, 14bit or 16bit wide (in

EPROM, FLASH, or ROM)

Page 65: Microcomputer Interfacing.pdf

8/13/2019 Microcomputer Interfacing.pdf

http://slidepdf.com/reader/full/microcomputer-interfacingpdf 65/110

Comparison Between Architectures

MemoryData + Code

AddressData

ProgramMemory

DataMemory

PIC MICROCONTROLLER 9

CPU

I/ODevices

Von Neumann Machine

Data

CPU

I/ODevices

Harvard Machine

Instructionaddress

Variableaddress

Page 66: Microcomputer Interfacing.pdf

8/13/2019 Microcomputer Interfacing.pdf

http://slidepdf.com/reader/full/microcomputer-interfacingpdf 66/110

Harvard architecture is a newer concept than von-Neumann's. It roseout of the need to speed up the work of a microcontroller.• In Harvard architecture, Data Access and Address Access are

separate. Thus a greater flow of data is possible through the centralprocessing unit.

• PIC16F877 uses 14 bits for instructions which allows for all instructions

to be one word instructions.

PIC MICROCONTROLLER 10

Advantages of Harvard model• An add operation of the form a:=b+c must fetch 2 operands from

memory and write 1 operand to memory. In addition it is likely to haveto fetch 3 instructions from memory.

• With a single memory this will take 6 cycles.• With 2 memories, we can fetch the instructions in parallel with the data

and do it in 3 cycles.• We have different word lengths for instructions and data – 8 bit data

and perhaps 12 bit instructions.

Page 67: Microcomputer Interfacing.pdf

8/13/2019 Microcomputer Interfacing.pdf

http://slidepdf.com/reader/full/microcomputer-interfacingpdf 67/110

Harvard vs von Neumann Block Architecture

Harvard Von- Neumann

PIC MICROCONTROLLER 11

DataMemory CPU

ProgramMemory CPU

ProgramMemory

8 14 8

Page 68: Microcomputer Interfacing.pdf

8/13/2019 Microcomputer Interfacing.pdf

http://slidepdf.com/reader/full/microcomputer-interfacingpdf 68/110

Von Neumann Architecture• Used in: 80X86 (PCs), 8051, 68HC11, etc.)• Only one bus between CPU and memory• RAM and program memory share the same bus and the same memory,

and so must have the same bit width• Bottleneck: Getting instructions interferes with accessing RAM

PIC MICROCONTROLLER 12

RISC Architecture• Complex/Reduced Instruction Set Computers• A minimal set of instructions, combined, can do every operation• Usually execute in a single cycle• CPU is smaller• Other hardware can be added to the space: (overlapping register

windows)

Page 69: Microcomputer Interfacing.pdf

8/13/2019 Microcomputer Interfacing.pdf

http://slidepdf.com/reader/full/microcomputer-interfacingpdf 69/110

Traditionally, CPUs are“

CISC”

• Complex Instruction Set Computer (CISC)• Used in: 80X86, 8051, 68HC11, etc.• Many instructions (usually > 100)• Many, many addressing modes• Usually takes more than 1 internal clock cycle to execute

PIC MICROCONTROLLER 13

PICs and most Harvard chips are “ RISC ”

• Reduced Instruction Set Computer (RISC)• Used in: SPARC, ALPHA, Atmel AVR, etc.• Few instructions (usually < 50)• Only a few addressing modes• Executes 1 instruction in 1 internal clock cycle

Page 70: Microcomputer Interfacing.pdf

8/13/2019 Microcomputer Interfacing.pdf

http://slidepdf.com/reader/full/microcomputer-interfacingpdf 70/110

The PIC Family: Cores• PICs come with 1 of 4 CPU ‘cores ’:• 12bit cores with 33 instructions: 12C50x, 16C5x• 14bit cores with 35 instructions: 12C67x,16Cxxx• 16bit cores with 58 instructions: 17C4x,17C7xx• ‘ Enhanced ’ 16bit cores with 77 instructions: 18Cxxx

PIC MICROCONTROLLER 14

The PIC Family: Packages• PICs come in a huge variety of packages:

• 8 pin DIPs, SOICs: 12C50x (12bit) and 12C67x (14bit)• 18pin DIPs, SOICs: 16C5X (12bit), 16Cxxx (14bit)• 28pin DIPs, SOICs: 16C5X (12bit), 16Cxxx (14bit)• 40pin DIPs, SOICs: 16Cxxx (14bit), 17C4x (16bit)• 44 - 68pin PLCCs*: 16Cxxx (14bit), 17C4x / 17Cxxx (16bit)

Page 71: Microcomputer Interfacing.pdf

8/13/2019 Microcomputer Interfacing.pdf

http://slidepdf.com/reader/full/microcomputer-interfacingpdf 71/110

The PIC Family: Speed• PICs require a clock to work.• Can use crystals, clock oscillators, or even an RC circuit.• Some PICs have a built in 4MHz RC clock

– Not very accurate, but requires no external components!• Instruction speed = 1/4 clock speed• All PICs can be run from DC to their maximum specified speed:

PIC MICROCONTROLLER 15

• 12C50x 4MHz• 12C67x 10MHz• 16Cxxx 20MHz• 17C4x / 17C7xxx 33MHz• 18Cxxx 40MHz

Page 72: Microcomputer Interfacing.pdf

8/13/2019 Microcomputer Interfacing.pdf

http://slidepdf.com/reader/full/microcomputer-interfacingpdf 72/110

The PIC Family: Program Memory• PIC program space is different for each chip.• Some examples are:

12C508 512 12bit instructions16C71C 1024 (1k) 14bit instructions

16F877 8192 (8k) 14bit instructions

PIC MICROCONTROLLER 16

17C766 16384 (16k) 16bit instructions

Page 73: Microcomputer Interfacing.pdf

8/13/2019 Microcomputer Interfacing.pdf

http://slidepdf.com/reader/full/microcomputer-interfacingpdf 73/110

The PIC Family: Program Memory• PICs have two different types of program storage:1. EPROM (Erasable Programmable Read Only Memory)

• Needs high voltage from a programmer to program (~13V)• Needs windowed chips and UV light to erase• Note: One Time Programmable (OTP) chips are EPROM chips,

but with no window!

PIC MICROCONTROLLER 17

• PIC Examples: Any ‘C ’ part: 12C50x, 17C7xx, etc.

2. FLASH• Re-writable (even by chip itself)• Much faster to develop on!• Finite number of writes (~100k Writes)• PIC Examples: Any ‘F ’ part: 16F84, 16F87x, 18Fxxx (future)

Page 74: Microcomputer Interfacing.pdf

8/13/2019 Microcomputer Interfacing.pdf

http://slidepdf.com/reader/full/microcomputer-interfacingpdf 74/110

The PIC Family: Data Memory• PICs use general purpose “ file registers ” for RAM (eachregister is 8bits for all PICs)

• Some examples are:12C508 25 Bytes RAM

16C71C 36 Bytes RAM

PIC MICROCONTROLLER 18

16F877 368 Bytes (plus 256 Bytes of nonvolatileEEPROM)17C766 902 Bytes RAM

• Don ’t forget, programs are stored in program space (not indata space), so low RAM values are OK.

Page 75: Microcomputer Interfacing.pdf

8/13/2019 Microcomputer Interfacing.pdf

http://slidepdf.com/reader/full/microcomputer-interfacingpdf 75/110

The PIC Family: Control Registers• PICs use a series of “ special function registers ” for controllingperipherals and PIC behaviors.

• Some examples are:STATUS Bank select bits, ALU bits (zero, borrow, carry)INTCON Interrupt control: interrupt enables, flags, etc.

TRIS Tristate control for digital I/O: which pins are ‘floating ’

PIC MICROCONTROLLER 19

TXREG UART transmit register: the next byte to transmit

Page 76: Microcomputer Interfacing.pdf

8/13/2019 Microcomputer Interfacing.pdf

http://slidepdf.com/reader/full/microcomputer-interfacingpdf 76/110

The PIC Family: Peripherals• Different PICs have different on-board peripherals• Some common peripherals are:

– Tri-state ( “ floatable ” ) digital I/O pins – Analog to Digital Converters (ADC) (8, 10 and 12bit, 50ksps) – Serial communications: UART (RS-232C), SPI, I2C, CAN – Pulse Width Modulation (PWM) (10bit)

PIC MICROCONTROLLER 20

– Timers and counters (8 and 16bit) – Watchdog timers, Brown out detect, LCD drivers

Page 77: Microcomputer Interfacing.pdf

8/13/2019 Microcomputer Interfacing.pdf

http://slidepdf.com/reader/full/microcomputer-interfacingpdf 77/110

Page 78: Microcomputer Interfacing.pdf

8/13/2019 Microcomputer Interfacing.pdf

http://slidepdf.com/reader/full/microcomputer-interfacingpdf 78/110

PIC Peripherals: ADCs• Only available in 14bit and 16bit cores• Fs (sample rate) < 54KHz• Most 8bits, newer PICs have 10 or 12bits• All are +/- 1LSB and are monotonic• Theoretically higher accuracy when PIC is in sleep mode (less digital

noise)

PIC MICROCONTROLLER 22

• Can generate an interrupt on ADC conversion done• Multiplexed 3 (12C671) - 12 (17C7xxx) channel input• – Must wait Tacq to charge up sampling capacitor

Page 79: Microcomputer Interfacing.pdf

8/13/2019 Microcomputer Interfacing.pdf

http://slidepdf.com/reader/full/microcomputer-interfacingpdf 79/110

PIC Peripherals: USART: UART• Serial Communications Peripheral: Universal Synchronous/Asynchronous Receiver/Transmitter

• Only available in 14bit and 16bit cores• Interrupt on TX buffer empty and RX buffer full• Asynchronous communication: UART (RS-232C serial)

– Can do 300bps - 115kbps

PIC MICROCONTROLLER 23

– 8 or 9 bits, parity, start and stop bits, etc. – Outputs 5V so you need a RS232 level converter (e.g., MAX232)

Page 80: Microcomputer Interfacing.pdf

8/13/2019 Microcomputer Interfacing.pdf

http://slidepdf.com/reader/full/microcomputer-interfacingpdf 80/110

PIC Peripherals: USART: USRT• Synchronous communication: i.e., with clock signal• SPI = Serial Peripheral Interface

– 3 wire: Data in, Data out, Clock – Master/Slave (can have multiple masters) – Very high speed (1.6Mbps) – Full speed simultaneous send and receive (Full duplex)

PIC MICROCONTROLLER 24

• I2C = Inter IC – 2 wire: Data and Clock – Master/Slave (Single master only; multiple masters clumsy) – Lots of cheap I2C chips available; typically < 100kbps(For example, 8pin EEPROM chips, ADC, DACs, etc.)

Page 81: Microcomputer Interfacing.pdf

8/13/2019 Microcomputer Interfacing.pdf

http://slidepdf.com/reader/full/microcomputer-interfacingpdf 81/110

PIC Peripherals: Timers• Available in all PICs• 14+bit cores may generate interrupts on timer overflow• Some 8bits, some 16bits, some have prescalers• Can use external pins as clock in/clock out (ie, for counting events or

using a different Fosc)• Warning: some peripherals share Timer resources

PIC MICROCONTROLLER 25

Page 82: Microcomputer Interfacing.pdf

8/13/2019 Microcomputer Interfacing.pdf

http://slidepdf.com/reader/full/microcomputer-interfacingpdf 82/110

PIC Peripherals: CCP Modules• Capture/Compare/PWM (CCP)• 10bit PWM width within 8bit PWM period (frequency)

– Enhanced 16bit cores have better bit widths• Frequency/Duty cycle resolution tradeoff

– 19.5KHz has 10bit resolution – 40KHz has 8bit resolution

PIC MICROCONTROLLER 26

– 1MHz has 1bit resolution (makes a 1MHz clock!)• Can use PWM to do DAC - See AN655• Capture counts external pin changes• Compare will interrupt on when the timer equals the value in a compare

register

Page 83: Microcomputer Interfacing.pdf

8/13/2019 Microcomputer Interfacing.pdf

http://slidepdf.com/reader/full/microcomputer-interfacingpdf 83/110

PIC Peripherals: Misc.• Sleep Mode: PIC shuts down until external interrupt (or internal timer)wakes it up.

• Interrupt on pin change: Generate an interrupt when a digital input pinchanges state (for example, interrupt on keypress).

• Watchdog timer: Resets chip if not cleared before overflow• Brown out detect: Resets chip at a known voltage level

PIC MICROCONTROLLER 27

• LCD drivers: Drives simple LCD displays• Future: CAN bus, 12bit ADC, better analog functions

• VIRTUAL PERIPHERALS: – Peripherals programmed in software. UARTS, timers, and more

can be done in software (but it takes most of the resources of themachine)

Page 84: Microcomputer Interfacing.pdf

8/13/2019 Microcomputer Interfacing.pdf

http://slidepdf.com/reader/full/microcomputer-interfacingpdf 84/110

Introduction to PIC

Microcontroller

Lecturer : Dr Abd Rahman Tamuri, Dr Yaacob Mat Daud

Physics Department, Faculty of Science,Universiti Teknologi Malaysia, 81310, JB

Page 85: Microcomputer Interfacing.pdf

8/13/2019 Microcomputer Interfacing.pdf

http://slidepdf.com/reader/full/microcomputer-interfacingpdf 85/110

Lecture 04

More on Microcontrollers• Microcontrollers integrate all the components of a computer system

onto a single chip• All components are optimized to perform the functions necessary to

control a larger system• Size, capability, cost, and power consumption are more important

considerations

2

• 8 bit microcontrollers have the majority of the market right now, but 16and 32 bit microcontrollers are available and gaining market share

Page 86: Microcomputer Interfacing.pdf

8/13/2019 Microcomputer Interfacing.pdf

http://slidepdf.com/reader/full/microcomputer-interfacingpdf 86/110

Page 87: Microcomputer Interfacing.pdf

8/13/2019 Microcomputer Interfacing.pdf

http://slidepdf.com/reader/full/microcomputer-interfacingpdf 87/110

Page 88: Microcomputer Interfacing.pdf

8/13/2019 Microcomputer Interfacing.pdf

http://slidepdf.com/reader/full/microcomputer-interfacingpdf 88/110

PIC MICROCONTROLLER 5

Page 89: Microcomputer Interfacing.pdf

8/13/2019 Microcomputer Interfacing.pdf

http://slidepdf.com/reader/full/microcomputer-interfacingpdf 89/110

The PICmicro was originally designed around 1980 byGeneral Instrument as a small, fast, inexpensive embeddedmicrocontroller with strong I/O capabilities.

• PIC stands for " Peripheral Interface Controller".

PIC MICROCONTROLLER 6

• General Instrument recognized the potential for the PICand eventually spun off Microchip, headquartered inChandler, AZ to fabricate and market the PICmicro.

Page 90: Microcomputer Interfacing.pdf

8/13/2019 Microcomputer Interfacing.pdf

http://slidepdf.com/reader/full/microcomputer-interfacingpdf 90/110

PIC Microcontroller• Range of low end 8 bit microcontrollers.• Smallest have only 8 pins, largest 40 pins.• Typical chip is an 18 pin one.• Very cheap, you can pick them up at less than £1 each.• Targeted at consumer products, burglar alarms etc.

PIC MICROCONTROLLER 7

Advantages of PIC• It is a RISC (Reduced Instruction Set Computer) design• Only thirty seven instructions to remember• Its code is extremely efficient, allowing the PIC to run with typically less

program memory than its larger competitors.• It is low cost, high clock speed

Page 91: Microcomputer Interfacing.pdf

8/13/2019 Microcomputer Interfacing.pdf

http://slidepdf.com/reader/full/microcomputer-interfacingpdf 91/110

Harvard architecture• Like many micros the PIC is a Harvard not a von-Neumann

machine• This is simpler and faster• Separate program bus and data bus: can be different

widths!

PIC MICROCONTROLLER 8

• For example, PICs use: – Data memory (RAM): a small number of 8bitregisters – Program memory (ROM): 12bit, 14bit or 16bit wide (in

EPROM, FLASH, or ROM)

Page 92: Microcomputer Interfacing.pdf

8/13/2019 Microcomputer Interfacing.pdf

http://slidepdf.com/reader/full/microcomputer-interfacingpdf 92/110

Comparison Between ArchitecturesMemory

Data + Code

AddressData

ProgramMemory

DataMemory

PIC MICROCONTROLLER 9

CPU

I/O

Devices

Von Neumann Machine

Data

CPU

I/O

Devices

Harvard Machine

Instructionaddress

Variableaddress

Page 93: Microcomputer Interfacing.pdf

8/13/2019 Microcomputer Interfacing.pdf

http://slidepdf.com/reader/full/microcomputer-interfacingpdf 93/110

• Harvard architecture is a newer concept than von-Neumann's. It roseout of the need to speed up the work of a microcontroller.

• In Harvard architecture, Data Access and Address Access areseparate. Thus a greater flow of data is possible through the centralprocessing unit.

• PIC16F877 uses 14 bits for instructions which allows for all instructions

to be one word instructions.

PIC MICROCONTROLLER 10

Advantages of Harvard model• An add operation of the form a:=b+c must fetch 2 operands from

memory and write 1 operand to memory. In addition it is likely to haveto fetch 3 instructions from memory.

With a single memory this will take 6 cycles.• With 2 memories, we can fetch the instructions in parallel with the data

and do it in 3 cycles.• We have different word lengths for instructions and data – 8 bit data

and perhaps 12 bit instructions.

Page 94: Microcomputer Interfacing.pdf

8/13/2019 Microcomputer Interfacing.pdf

http://slidepdf.com/reader/full/microcomputer-interfacingpdf 94/110

Harvard vs von Neumann Block Architecture

Harvard Von- Neumann

PIC MICROCONTROLLER 11

DataMemory CPU

ProgramMemory CPU

ProgramMemory

8 14 8

Page 95: Microcomputer Interfacing.pdf

8/13/2019 Microcomputer Interfacing.pdf

http://slidepdf.com/reader/full/microcomputer-interfacingpdf 95/110

Von Neumann Architecture• Used in: 80X86 (PCs), 8051, 68HC11, etc.)• Only one bus between CPU and memory• RAM and program memory share the same bus and the same memory,

and so must have the same bit width• Bottleneck: Getting instructions interferes with accessing RAM

PIC MICROCONTROLLER 12

RISC Architecture• Complex/Reduced Instruction Set Computers• A minimal set of instructions, combined, can do every operation• Usually execute in a single cycle• CPU is smaller• Other hardware can be added to the space: (overlapping register

windows)

Page 96: Microcomputer Interfacing.pdf

8/13/2019 Microcomputer Interfacing.pdf

http://slidepdf.com/reader/full/microcomputer-interfacingpdf 96/110

Traditionally, CPUs are“ CISC ”

• Complex Instruction Set Computer (CISC)• Used in: 80X86, 8051, 68HC11, etc.• Many instructions (usually > 100)• Many, many addressing modes• Usually takes more than 1 internal clock cycle to execute

PIC MICROCONTROLLER 13

PICs and most Harvard chips are “ RISC ”

• Reduced Instruction Set Computer (RISC)• Used in: SPARC, ALPHA, Atmel AVR, etc.• Few instructions (usually < 50)• Only a few addressing modes• Executes 1 instruction in 1 internal clock cycle

Page 97: Microcomputer Interfacing.pdf

8/13/2019 Microcomputer Interfacing.pdf

http://slidepdf.com/reader/full/microcomputer-interfacingpdf 97/110

The PIC Family: Cores• PICs come with 1 of 4 CPU ‘cores ’:• 12bit cores with 33 instructions: 12C50x, 16C5x• 14bit cores with 35 instructions: 12C67x,16Cxxx• 16bit cores with 58 instructions: 17C4x,17C7xx• ‘ Enhanced ’ 16bit cores with 77 instructions: 18Cxxx

PIC MICROCONTROLLER 14

The PIC Family: Packages• PICs come in a huge variety of packages:

• 8 pin DIPs, SOICs: 12C50x (12bit) and 12C67x (14bit)• 18pin DIPs, SOICs: 16C5X (12bit), 16Cxxx (14bit)• 28pin DIPs, SOICs: 16C5X (12bit), 16Cxxx (14bit)• 40pin DIPs, SOICs: 16Cxxx (14bit), 17C4x (16bit)• 44 - 68pin PLCCs*: 16Cxxx (14bit), 17C4x / 17Cxxx (16bit)

Page 98: Microcomputer Interfacing.pdf

8/13/2019 Microcomputer Interfacing.pdf

http://slidepdf.com/reader/full/microcomputer-interfacingpdf 98/110

The PIC Family: Speed• PICs require a clock to work.• Can use crystals, clock oscillators, or even an RC circuit.• Some PICs have a built in 4MHz RC clock

– Not very accurate, but requires no external components!• Instruction speed = 1/4 clock speed•

All PICs can be run from DC to their maximum specified speed:

PIC MICROCONTROLLER 15

• 12C50x 4MHz• 12C67x 10MHz• 16Cxxx 20MHz• 17C4x / 17C7xxx 33MHz• 18Cxxx 40MHz

Page 99: Microcomputer Interfacing.pdf

8/13/2019 Microcomputer Interfacing.pdf

http://slidepdf.com/reader/full/microcomputer-interfacingpdf 99/110

The PIC Family: Program Memory• PIC program space is different for each chip.• Some examples are:

12C508 512 12bit instructions16C71C 1024 (1k) 14bit instructions

16F877 8192 (8k) 14bit instructions

PIC MICROCONTROLLER 16

17C766 16384 (16k) 16bit instructions

Page 100: Microcomputer Interfacing.pdf

8/13/2019 Microcomputer Interfacing.pdf

http://slidepdf.com/reader/full/microcomputer-interfacingpdf 100/110

The PIC Family: Program Memory• PICs have two different types of program storage:1. EPROM (Erasable Programmable Read Only Memory)

• Needs high voltage from a programmer to program (~13V)• Needs windowed chips and UV light to erase• Note: One Time Programmable (OTP) chips are EPROM chips,

but with no window!

PIC MICROCONTROLLER 17

• PIC Examples: Any ‘C ’ part: 12C50x, 17C7xx, etc.

2. FLASH• Re-writable (even by chip itself)• Much faster to develop on!• Finite number of writes (~100k Writes)• PIC Examples: Any ‘F ’ part: 16F84, 16F87x, 18Fxxx (future)

Page 101: Microcomputer Interfacing.pdf

8/13/2019 Microcomputer Interfacing.pdf

http://slidepdf.com/reader/full/microcomputer-interfacingpdf 101/110

The PIC Family: Data Memory• PICs use general purpose “ file registers ” for RAM (eachregister is 8bits for all PICs)

• Some examples are:12C508 25 Bytes RAM

16C71C 36 Bytes RAM

PIC MICROCONTROLLER 18

16F877 368 Bytes (plus 256 Bytes of nonvolatileEEPROM)17C766 902 Bytes RAM

• Don ’t forget, programs are stored in program space (not in

data space), so low RAM values are OK.

Page 102: Microcomputer Interfacing.pdf

8/13/2019 Microcomputer Interfacing.pdf

http://slidepdf.com/reader/full/microcomputer-interfacingpdf 102/110

The PIC Family: Control Registers• PICs use a series of “ special function registers ” for controllingperipherals and PIC behaviors.

• Some examples are:STATUS Bank select bits, ALU bits (zero, borrow, carry)INTCON Interrupt control: interrupt enables, flags, etc.

TRIS Tristate control for digital I/O: which pins are‘

floating’

PIC MICROCONTROLLER 19

TXREG UART transmit register: the next byte to transmit

Page 103: Microcomputer Interfacing.pdf

8/13/2019 Microcomputer Interfacing.pdf

http://slidepdf.com/reader/full/microcomputer-interfacingpdf 103/110

The PIC Family: Peripherals• Different PICs have different on-board peripherals• Some common peripherals are:

– Tri-state ( “ floatable ” ) digital I/O pins – Analog to Digital Converters (ADC) (8, 10 and 12bit, 50ksps) – Serial communications: UART (RS-232C), SPI, I2C, CAN –

Pulse Width Modulation (PWM) (10bit)

PIC MICROCONTROLLER 20

– Timers and counters (8 and 16bit) – Watchdog timers, Brown out detect, LCD drivers

Page 104: Microcomputer Interfacing.pdf

8/13/2019 Microcomputer Interfacing.pdf

http://slidepdf.com/reader/full/microcomputer-interfacingpdf 104/110

PIC Peripherals: Ports (Digital I/O)• All PICs have digital I/O pins, called ‘Ports ’

– the 8pin 12C508 has 1 Port with 4 digital I/O pins – the 68pin 17C766 has 9 Ports with 66 digital I/O pins

• Ports have 2 control registers – TRISx sets whether each pin is an input or output –

PORTx sets their output bit levels

PIC MICROCONTROLLER 21

• Most pins have 25mA source/sink (directly drives LEDs)• WARNING: Other peripherals SHARE pins!

Page 105: Microcomputer Interfacing.pdf

8/13/2019 Microcomputer Interfacing.pdf

http://slidepdf.com/reader/full/microcomputer-interfacingpdf 105/110

PIC Peripherals: ADCs• Only available in 14bit and 16bit cores• Fs (sample rate) < 54KHz• Most 8bits, newer PICs have 10 or 12bits• All are +/- 1LSB and are monotonic• Theoretically higher accuracy when PIC is in sleep mode (less digital

noise)

PIC MICROCONTROLLER 22

• Can generate an interrupt on ADC conversion done• Multiplexed 3 (12C671) - 12 (17C7xxx) channel input• – Must wait Tacq to charge up sampling capacitor

Page 106: Microcomputer Interfacing.pdf

8/13/2019 Microcomputer Interfacing.pdf

http://slidepdf.com/reader/full/microcomputer-interfacingpdf 106/110

PIC Peripherals: USART: UART• Serial Communications Peripheral: Universal Synchronous/Asynchronous Receiver/Transmitter

• Only available in 14bit and 16bit cores• Interrupt on TX buffer empty and RX buffer full• Asynchronous communication: UART (RS-232C serial)

Can do 300bps - 115kbps

PIC MICROCONTROLLER 23

– 8 or 9 bits, parity, start and stop bits, etc. – Outputs 5V so you need a RS232 level converter (e.g., MAX232)

Page 107: Microcomputer Interfacing.pdf

8/13/2019 Microcomputer Interfacing.pdf

http://slidepdf.com/reader/full/microcomputer-interfacingpdf 107/110

Page 108: Microcomputer Interfacing.pdf

8/13/2019 Microcomputer Interfacing.pdf

http://slidepdf.com/reader/full/microcomputer-interfacingpdf 108/110

Page 109: Microcomputer Interfacing.pdf

8/13/2019 Microcomputer Interfacing.pdf

http://slidepdf.com/reader/full/microcomputer-interfacingpdf 109/110

PIC Peripherals: CCP Modules• Capture/Compare/PWM (CCP)• 10bit PWM width within 8bit PWM period (frequency)

– Enhanced 16bit cores have better bit widths• Frequency/Duty cycle resolution tradeoff

– 19.5KHz has 10bit resolution –

40KHz has 8bit resolution

PIC MICROCONTROLLER 26

– 1MHz has 1bit resolution (makes a 1MHz clock!)• Can use PWM to do DAC - See AN655• Capture counts external pin changes• Compare will interrupt on when the timer equals the value in a compare

register

Page 110: Microcomputer Interfacing.pdf

8/13/2019 Microcomputer Interfacing.pdf

http://slidepdf.com/reader/full/microcomputer-interfacingpdf 110/110

PIC Peripherals: Misc.• Sleep Mode: PIC shuts down until external interrupt (or internal timer)wakes it up.

• Interrupt on pin change: Generate an interrupt when a digital input pinchanges state (for example, interrupt on keypress).

• Watchdog timer: Resets chip if not cleared before overflow•

Brown out detect: Resets chip at a known voltage level • LCD drivers: Drives simple LCD displays• Future: CAN bus, 12bit ADC, better analog functions

• VIRTUAL PERIPHERALS: – Peripherals programmed in software. UARTS, timers, and more

can be done in software (but it takes most of the resources of themachine)