You are on page 1of 33

2 CHAPTER to Introduction MicroProcessorControl Based

OBJECTIVES
After studying this chaptet you should be able to: . Unalerstand what a microprocessoris. what it does, and how it works. . Understand conceprs RAM and ROM computermemory and how of the and via memoryis accessed the address databuses . Understandhow parallel and serial data intedaces work. . Perform relevant calculationspertaining to analog-to-digital converte$ and digital-to analog converters. . Understandthe principles of digilal controller software. . Recognizeand describethe characteristicsof the various types of available procomputers, single-board digital controllefi, that is, micrccontrollers, grammablelogic conoollen, and pe$onal computers.

INTRODUCTION
The digital integratedcircuit (IC) called a microprccessor lFigure 2.1(a)l' hasushered electronics This revolution has occtmedbecausei in a whole new erafor control systems con(rol andrhecomiutarional brings fleribilil) ol pfogram the rhemicroprocessor po*er of i iirmputer to beai ciii any problem.iAutomatic co rol applications are pafofthis technology'andmicroprocessor-based ticularly well suitedto takeaalvantage ciron based analog manyolder controlsystems rapidlyreplacing are confo] systems contlollen ofthe first microprocessor-basd relays,One cuits or electromechanical madespecifically for control applicationswas the pogrammable logic conrroller(PLC), by andin Chapter12.A microprocessor itself laterin this chapter which is discussed is not a computer; additional componentssuch as memory and input/output circuits are rcquirealto make it opemtional.Howevet tbe microcontroller lFigure 2 1(b)], which is

26

2 CHAPTER

2.1 Figure

(a) Microprocassor

Mlcfocontrollgr

CPU (microprocessor)

(b) Microcohtroller

on functions a sindoeJ of a closerelative the microprocessor, containall the computer of $e po$er and speed the ne\ er mjcroproceslack sle IC, MicroconLrollers someof Inosl'u calleJ i' io,t Urt 'f,.rr compcclrre* idedlfor mrn) controlJpp'icrtron\: arereallyusingnicrosuchas vendingmacbines, Llevices, micioorocessor-conirolled in design control for roasons usinga digitalr'microprocessor Somespecific contrJlle6. are systems the following: long lo oncoconverted digital' canbe transmitted . Low level siSnals from sensors, virtuallyerorjree. distances 'lralegie' and c"lculalion\ conlrol compler . A microproce..or ec'il) h"ndle can . tonrr.irnt..utyi.rvcilablelokeeplmclolpardmeterqin\lo$nroting'y'lem . irroininn o".onior srategy is easyby loading in a new program;no hardware changesare requfeo. . Micriprocessor baseticontrollersare more easily connectedto the computernetwork andreadcur_ within an organization This allows designeff to enterprogram changes rromlheirJe'krermr'lrl' rcnr\)slemslalus

ro rNrRoDUCloN tvl!891899E9998!49E!!9!fB9!

27

In this chapter,we will presentthe basic conceptsof a microprccessor--and syslem-applicamicrocontrolle;basedsystemwith particularemphasison control to makethe restof the text but an tions.It is by no means in-depthtreatment, enough moremeaningful, hardware of the ofthis chapter basicconcepts microprocessor sections In the firs-t also apply to microcontrollers)l have (theseconcepts and ooemtionare introduceal shouldhaveat of student moderncontrol systems tecausethe inctudea*ris materiat performsitsjob ofhow the nicroprocessor knowledge leasta general

TO 2.1INTRODUCTION MICROPROCESSOR SYSTEMIIARDWARE


unit the units: ceniulprocessing (CPU)' functional up is A computer made of fourbasic compuF the unit (VOl Thecentratprocessing does actual and input, oLrtput memoiv. sections logjc thearithmetic unilandcontrol innoniit iotoor.a oi l\ o subparls: and (ALU) performs aclurlnumerical logic, $e ,iin*" Z.:l-fli. *itrlt.tic logi; unit ol AND. subEacdon. OR andsoon Theconrolreclion as such addition ia)iulations ptogramInstructhe and as flow' such reading executing the theCPUmanages data it hands overto theALU for protheconfol section calculations, re-quire tions.Ifdata is the the compulet, mjcroprocessor CPU a cessing.ln mi;roprocessor_based 2,2 Figure

r------------------i
ALU

cPU(mlcroProcessor) Bus Address

Outptjt TO indicatorc, To
Registers DataBus ConlrolBus

28

CHAPTER 2 Digital datais in the folm of bits, whereeachbit hasa value of either I or 0. Digital logic 1 and0 Vdc to represenr logic 0. Eightbits circuits suallyuse5 Vdc to represent handlesdigital datain words, wherea word togetheris called a byte. A microprocessor may be 8, 16, or 32 bits wide. For example, 8-bit microprccessor a byte sized an has word, with a maxinum decimalvatueof 255. (Computers represent numbers the in binary numbersJstem;forexample, 11111111 binary = 255 decimal.) The rightmost bit in a binarynumber the leastvalue(usually1) andis calledtheleastsignificant has (LSB). The leftmostbit represents highestvalueandis calledthe most signiff" the bit cant bit O4SB). The convenion betweenbinary and decimal can be performeddirectly usingthe technique with mostscientific calculators manually or shownin Example 2.1. To express values largerthan255,lwo or morewordsareput togetherIn this text, we are will assume bit microprocessors usedunless 8 otherwise stated,

Find the decimalvalueof the 8-bit binarynumber

SOLUTJON

MSB

LSB

r28..64:. 1 6 32 ,0.rr
I : 1 I lxl= I 2x1= 2 4x0= 0 8x0= 0 16x1= 16 32x1= 32 64x0= 0.. 128 1=128 x +
179 decimal

The memory section of the computer is a place where digital data in binafy form (ls and 0s) are stored. Memory consists cellsorganized S-bitgroups. of in Eachbyte

CONTROL TO INTRODUCTION MICROPROCESSOR.BASED

29

its is given a unique numeric address, which reprcsents location just as a sreet adalrcss of a house,Dala are written into memory and read out of memrepresentsthe location might ory, basedsolely on thoir address.In a particular memory circuit, the addresses 2.3 diagramsa section of memory. and start at 1OO0 run consecutivelyto 2000. Figure Note that the fiIst byte of datahas a decimal value of 2 (00000010= 2 decinal) and an of address 1000. memory.The first is landomCompute$usuallyhavetwo kinds of addressable (RAJI), which allows the computerto read and write dataat any of its accssmemory (it addresses is also calledread/writememory or RWM). Alt datain this t ?e of memory is are lost when the poweris tumed off andis calledvolatile memory (an exception where RAM is kept "alive" with a small battery). The secondtype of memory alesigns is read-only memory (ROM), which is similar to RAM exceptthat new datacannotbe written in; ali dala in ROM are loadedat the factory and cannotbe changedby the computer This memory does not lose its data when power is tumed off and is called nonvolatile mmory, Most miooprccessol systemshave both RAM and ROM. RAM is used for temporary program stomge and as a tempomry scratch-padmemory for the CPU. ROM is usedto storeprogramsanddatathat needto be alwaysavailable Actually, pro$anrmableread-orilymemory) oi an EEPmany computelsusean EPROM (erasable prograrnnableROM) insteadof a ROM for long{erm mem ROM (electdcally erasable can ory. EPROMScan be erasedwith a strongUV light and reproFammed. EEPROMS repogrammed electrically.Disk ddvosalso storedigital databut in a form be ensed and to before they arc accessible the microprocessor. that must be processed The inpuuoutput (VO) sectionof the computei allows it to inteface with the ool side wor1d.The input section is the conduit tbrough which new programsand dataare lo allo\L"lhe compuler communicale and outpulsecuon rnleredinto the compuler. Lhe is called a port. An input polt is a circuit that connectsinput its rcsults.An VO interface and devices to the compuler; examplesof input devicesare keyboards,sensors, computerto output devlces. the switches.An oulput polt is a circuit that connects Examples of output devicesare indicator lamps, actuators,and monilors. lnput/oulput is discussedin more detail in the next seciion Referring again to Figure 2.2, we seethat the blocks are connectedby thrce lines bus, databus, aIId control bus The addrss buljs a group of wiros that labeled adalress carries an address(in binary {orm) from the CPU to the memory and VO circuits. The Address 1000 1001 1002 1003 1004 Data 00000010 01100100 00000000 01011100 10011010

Fig!re 2.3

30

2 CHAPTER addresses already has beendiscussed, you may wonbut needfor memoryto receive It der why VO ports need adalrcsses. tums out that all I/O ports are assignedaddresses and are treated essentially like memory locatrons by the CPU. The CPU oufputs data to the outside world by sendilg them to a port address.When the circuitry of the designated output port detectsils assigned addresson the addressbus, it opensand allows data to passfrom the databus to whateveris connectedto fhe poIt. There arc two ways use is that yO adalressing done.Somemicroprccessors what is calledmemory-mapped Other itrpuvoutput, where an VO addressis teated just like anothermemory adalrcss. completely sepante liom memory addresses, microprocesson treat VO addresses The dats buqis a group of eight wires that carries the actual numedcal data ftom place to place within the computer Figure 2.2 showshow the databus interconnects all blocks. Data flow in both dircctionson t}le databus. For example,input dataenler tbrough the input port and proceedtbrough the databus to fte CPU. If the CPU needs to store thesedata, it will sendthem back through the data bus to memory. Data to be outputted are sent (by the CPU) through lhe databus to lhe output port. If the databus is connects all blocks.how do the dataknow which block to go to? The answer the to For example, when t]rc CPU sendsdata to memory, it does it in two addresssystem. First, it puts the destination memoryaddress the address on bus; second, puts it steps: memory detectsits own address, it the dala on the data bus.When the designated to "wakesup" and takesthe datafrom the databus.The otherblocks connected the because they were not addressed. good anaiA buseswill igrore the wholesequence to ogy hereis the phonesystem, wherethe phonenumberis analogous the memory of may be connected the syslem, to whenyou address. Eventhoughthousands phones dial a numbe! only the designatedphone iings. The beauty of the bus systemis that it yO is expandable.Memory or addressable units can be addedto the systemby simply themto the buses. connecting The contml bus (seeFigue 2.2) consistsof timing and event-controlsignalsfrom the CPU. These signalsare usedto control the dataflow on the databus. For example, is oneof the controlsignals the rad vrite (RJW)line. This signalinformsthe memory if the CPU wishesio read existing daia out of memoly or write new datainto memmachineshave a menory-I/O control li e.Thls signal ory. Non-memory-mapped involves memory or an yO port. In geninfo.ms the systemif the cunent dataexchange as and eral,the controlbusis not as standardized arethe address databuses.

2.2 INTRODUCTION MICROPROCESSOR TO OPERATION


The microprccessor works by executing a program of instructions. Creating the prc gram is similar in concepl to programming in BASIC, C, or any other highlevel com puter language.Each type of microprocessorhas its own instruction set! which is the insFuc to set ofcommandsthatit wasdesigned rccognizeandobey.Microprocessor

CONTROL TO INTRODUCTION NIICROPROCESSOR-BASED

3l

tions are very elementaland specific, and it usually takesmore than one to accomplish what a single, high-level languageinshrction would. Many micmprocessorinstructions simply move datafrom one place to anotherwithin the computer;othen perform mathematical or iogic operations.Still anothergroup of instructions conllol program flow, such asjumping forward or backwad in the program Each instruction in the instruc tion set is assignedits own unique operstion cod, (which is typically 8 bits long and refered to as the op,code). The CPU usesthis 8-bit number to identify the instluction. have at leastone accumulator lFigure 2.4(a)], which is a dataAll microprccessorc holding registerin the CPU. The accumulatoractsas a "staging area"for data.It is common for datacoming to the CPU to go fiIst to the accumulatot where it can be operated Mathematical on. Similarly,most dataleavingthe CPU exits ftom the accumulator. operationsusually store the result in the accumulator.Ma[y of the instructions involve the accumulatorin one way or another. (in A machine languageprogramis a list of instructions op-codeform) for the program can be executed,it musl first be loaded microprocessorto follow. Before the into memory.The op codefor lhe first instructionis loadedat the first sequenlially location, the op-codefor the secondinstruction is loadednext in line, and so on. adahess Figure 2.4(b) showsa sectronof memory with a shofi Fogram loadedin. The pro(A gmm listing includesthe addrcss, op-code,mnemonic,and a brief explanation. mnemonic is an English abbreviation of an insffuction. A Fogram listing using only mnemonicsis called assemblylaDguage.)The plogram in Figure 2.4(b) dircctsthe CPU to get I byte of datafrom input port 01, add I to it, and sendthe result lo outputport 02. Beforc execution can stat, the addressof the first instruction must be loaded into the register thatthe prcgramcounter, The program counter is a specialaddress-stomge CPU usesto keep lrack of where il is in the program, much like a bookmark. Tbe program counter always holds lhe addressof the next instruction to be executed.Oncethe

2.4 Figure
The CPUuseso

CPU

Adr Op Code 00 DB 01 3C D3 02
76

lnstruction tN 01 INRA OUT02 HLT Explanation I Get datafrominputport 01. Incrsment accumulaior. t Senddatato oulputport 02.
Hall.

o1
02 03 04 05

o6

(a)

(b) Example microprocessorprogram

2 CHAPTER is microprocessor activated,executior of ihe progmm is complelely automatic.The exe first cycles,wherebythe microprocessor process a seriesof fetch-execute is cution it. and then executes The following arethe specific fetchesthe instruction fiom memory would go tkough to executelhe program of Figure 2 4(b): stepsthe microprocessor ftches first i talction from memory lt knows whereto the L The microprccessor find the instruction becauseits addtessis in the program counter 2- Once in th CPU, the op-codeis decodedto seewhich instructionit is, then the proper hardwareis activatedto executethis instruction. In the exampleprogram of Figure 2.4(b), the 6I5t instruction(IN 0l) is 2 bt'tes long. The first byte of the instruction is the op-code,telling the CPU to inpul data from a Port. The secondbyte of the instruction rclls the CPU )v/ri./l po( to read from. Exection of tbis instruction causes dataftom input port 0l to travel along the databus to the accumulator'AIso, the proof gramcounteradvances 02 (theaddress the next instruction)Execution the of to is first instruction now complete. 02. cycle stans,this time fetchilg lhe insruction flom address 3. The next fetch-execute (INR A) is "increment accumulator," the accumulator is so the The new instruction (add l) andthe resultpu! backin lhe accumulato theALU to be incremented sent of to counter advances 03, which is the address the llextinstruction. tor The program from address cycle stans,this dme fetchingthe instruction 4. The next fetch-execute (OUT 02) is executed, causing accumulator the datato be sent 03. The instruction to outputpoft 02. to the 5. The final instructionis fetched.It is a "halt," which causes microprocessor and cease operadng go into a wait mode.

TO 2.3 INTERFACING A MICROPROCESSOR CONTROLLER


An imporlant pan of any control systemis the link betweenthe controller and the real world. For a digital controller, dataenter and exit through a parallel inlerface or through a serial interface. Both data formats are discussednext.

The ParallelInterface
The parallel interface transfer data8 bits (or more) at the sametime, using eight separatewires. It is essentially an extensionof the data bus into th outside world. The that areeither parallelinterfaceis idealfor inputtingor outputtingdatafrom devices a on or off. For example, singlelimitswitch usesonly one inputbit, andan on-offsignal to a motor requrresonly one output bit. these l-bit signals are called logic variabls, and eight such signals can be provided from a single (8-bit) port This concept will be expandedon later in this section.

CONIBQ! TO TNTRODUCTTON I\,IlCROPROCESSOR-BASED

33

2.5 Figure

Digital inpul

(analogvollage) Yout

'-9.96V

-ace to to connect an inte the In otberapplicalions, collrollermayusea paral]el a the DC motor. such case, ln drivinga variable-speed device-for example, analog it voltage before into firstbeconverted ananalog must ofthe controller binaryoutput a circuit called digital-toby is Thisoperation pefformed a special cand vethemotor. analog converter e Digital-to-Andog Conv ft iotl a Thedigitol"to-analogconverter(DAC)is a circuit thatconverts digital wordinto an workings theinternal of Ii analog voltage. is notwithinthescope thistextto describe pararnetersappropnate. is ofihe understanding operating olthe DAC,bu!a general of the 2.5 Figure shows blockdiagram a typical8-bitDAC.Theinputis an8-bit and inputvalue !o that is digitalword.Theoutput a current is proportional thebinary (yrtt must voltage A reference anop_amp stable with to be must converted a voltage analog voltage-that is, for the defines maximum to be supplied theDAC.This voltage y,"r.If theinPutis 00000000, %,,r the 11, a digitalinputof 11111I %,,iis essentially ot voltage a linearpercentage is the in will beOVdc.Forall values between, output for voltage anydigitalinput(forthe8-bitDAC)is the V,"rSpecifically, outprrt
inpul x Ytul 256 = DAC outputanalogvoltage %,,, input = decimalvalueofthe binaryinput Yd = relerencevoltage to the DAC

(2.1)

Find 10011011. theana-

7
34
2 CHAPTER

is conversion resolution.The resof An impoitantconsideration digital to analog whenconvertirgbetween of a DAC is the wo$t caseerror that is introduced olution disdete only rcpresent digital wordsczm because This effor occurs digital andanalog. the in Figure2.5.For example, ma\imum diagram by values, indicated the stair-step as "steps" which meansthere:re 255 possible valueofan s-bit numberis 255 decimal, steps the valueofthe leastsignjficant is between The difference ofthe ouQut voltage. is incrcment onestep,the rcsolution(for 8-bitdata)is the bit (LSB). Because smallesl but for is This tesolution adequate manyapplicalions, if morc I part in 255,or 0.39Eo. Two portsprovide16 bils of two (ormore) 8 bit portscanbe usedtogether. is needed. Being ableto dividean analog data.The maximumdecimalvalueof 16bils is 65,535. that eachpart wiil be much smallel,so we can more numberinto 65,535paits means precisely representthat number.

INTRODUCTION MICFOPROCESSOR-BASED TO CONTROL

Figurc shows dara 2.6 a sheet an8-bi!DAC(DAC08O8). device for This comes as a 16-pin (dual DIP in-line package) uses extemal and an (such theLF 351), op_anp as tworcsistors, a capacitor complete circuit. rcquires andminus and io the It plus powe;_ supplyvoltages. timeto complete conversion a fast 150ns (nanosecondsl. The a is (The circuitshown Figure hasa y,.rof l0Vdc.) in 2.6 Figure 2.6
for the DAC0808. an 8-bitdigital-to(courtesy of

ZlaNahonal ItrSemlconcfuctor
Ganerrl Degcriptlon
Th. o^coafi ftier t! .r s.bhhcncrrhic diirLro *iol 6nsft, toacl t.dur ne I rur xd. d&ur 130 wli ! cl0tnrtn'.nrv d 33dw wirhrEV eprlq. it h|.r.".. N,;..r ti"..] oomiry ), nqui.d rorrqi 'pprcrror rm rr'jiJri er. ourN..uifqi L lyr4dry!t Lsgor 2a6rrEr/ 263, id.r|{ &udI of 5.k drrn rO,rO* ;;;. sbir monoroih(y.^d rii{ ry *}ih &6 td.t ourllr .u'6r or hn rhr a r/A F4tdd &blrkro eur..e i0' IFEF> 2 nA thi po*ri rupptv tuihB ot +. DACCoI rn6 n. Ind.o.ndrnr btr .dr rid ot .rhrblr u{.ri.tly dnrii d.rr...h.tr.r.,hto o{, tb .nri.r ru.pryvolrrr. tri!., ?h. DAClgOg risre d rc y *$ !eh, TTL *tit oll or Cirosheicrrdr, Indn rdrcr Dtxmmi r& {,. Mc1!03/MC Fe htdrsrdDord t.03. onr .. DACoIOo d.n dtr

Digilal'toAnalog Convertels

DAC'0808, DAO080Z DAC08(m D/AConvoders &Bit


Foeluros
io.$r .fd h&imuh r Fulrrd.curbnrnndhr rs8 !Y' il . 7 rid &bn &aruv rrit.bl. toACOtOr. DACOOO6| r F d r r t i r r l m . r5 o r r y D l tnoult r.. TTL nd CMOS . H{0h rF.d nulirtytht i.p. js {r: g 6A/rn . Por rclpry eohrt u$: |a.svlo !l6v . L@ Fsd codu pl o.r !! iw e r5v

coa)

Elock Connqcllor and Dlagrarns

TypicalAppllcatlon

t..;

l1

36

2 CHAPTER Com'ers'n Analag-to-Disital AIl analog-to-digital cotrvrter (ADC) is a circuit that convefis an analogvoltage into a digital wcird.A typical ADC consistsof a single IC with a few support components (thanfor the DAC), and process is Analog{o-digital conversion a morc complicated time, which is typically in the microsecond conversion requiressome the haralwaro on range.The conversiontime requjreddepends the type ofADC, the appliedclock ftequency,and the number of bits being converted.Figurc 2.7 showsa block diagram for yin is 0 an 8-bitADC. The input yi" canbe any voltagebetween0 V and yef When yd the ouQut is 11111111 (255 decimal). when Vinis Vdc, the outputis 00000000; 0 For input voltagesbetvr'een and V,er the output increaseslinearly with Vin;therefore, ratio for theADC: a we candeveloD simDle

output 255 _ v; Vnt gives followingl the Solving output for

(for 8 bits)

Y" x 255 outp'rt=--output = decimal output value of an 8-bit ADC 4" = analog input voltage to the ADC V*r = ADC referencevoltage

(:2.2)

pulseis sentto theADC. TheADC ptocess, slat_conversion a To startthe conversion tbe analoginput and convertsit to binary.When completed.the ADC actithen samples vatesthe data-readyoutput. This signal can be usedto ale the computerto lead in the binary da!a.

Figure2.7
Sla conve|sion Clock voltageinput) Vn (analog
Digilal ouIpul

Dala rady

CONTROL TO INTRODUCTION NIICBOPROCESSOB-BASED


Figure 2.8 for lhe ADC0804,

37

ZNational ZSemiconductor

Analog-tGDigltal Converters

ADC0803, ADC0804 8-BitpP ADCo8fi,ADC0802, ArDConverlers Compatible


Corp.)

Gengral Dsscription
Th. Aoc0301, ADmao?, aDco003, A9$04.t ourps m.{ l?L voka$ lcsl shichU$'60d1''.d@lntiomd MrcBoBUstu nrid.d 30304 .onbl bu., ird TarsTAr dlb bB, Th6? A/0' rNE, rikr r wo*swrrh 2.sv i 1M336) voxan 4irro& . 0V b 5v . ros lnpurvonas.r

! 03" n.ndiid widrh?0.pii olP pi.r* and o n'lhgvo]bg.rt..l se inplr ai b. ldjund 10all@ . anra vohrg.rpr. ro rh3rurr3bi! ol BrcLuuon, rhe @mmon-dodr 4jcriod

Koy Specifications
Sbitr !l/4 LsB.r1l? LsB3nd1r LsB

Fgalures
r MTcROBUS{30404.omp*ible

5voc
rop?ot!6liom&iJ|yo'wih or :ndrot.prn.diuft d !01116 r.c6rc.

Typical Applicatlons

Diagrams Connectlon

38

2 CHAPTER
: .:,i,,

as fof sheet an 8-bitADC (ADC0804) Packaged a 20-pin Figure2.8 showsa alata an external DIP, this device can operateon a single 5_Vdc power supply and requires pulseis applied resi;tor and capacitorio completetie ADC circuit The start conversion

i"

ADc This from comes pin5 (INT-R) panicular fw:nj,'"'a tm a"" 'iady sisnal afterthe "Ji connected a free-running whereit perfoms one conversion mode in ca; be

setaI half otheras fast asit can.Nolice alsothatthe pin labeledV*rD(pin 9) mustbe rangeot analogvoltage call if olthe ac$al V."r For example, the requirements for an rs 0-5 Vdc, then pin 9 would be setto 2 5 Vdc The time to completea converslon making it almost700 times slowerthanthe approximately100 $s (micro seconds), earlier DAC0808discussed ACo tol $sten UsingPara el Purts basedconlroller Figure 2.9 showsa positioncontrolsystemusing a microprocessor ports (each wit"hpara el ports. This pafiicular systemhasone output poll andthreeinput rn a DAC oorri^ is o" n aaat "r the oulputpon i' panition(d:six bil' dreconvened f molordirecrion| 'ignal.lhere\en!hbil \pecitre' io proriderte ;nalogmolor-dnve the eighthbitturns on an audioalarmif some and O clo'ckwise. = counlerctockwise)' sec emergencysituation is detected.The firsr input port inputs the selpoint data' the various I -bit logical r,aflona iputs ttre ,nOC datafrom the sensol'and the third inputs limi! ables.ln this case,the systemhas three front-panelswitchesas well as two

INTRODUCTION I\,4ICROPROCESSOR-BASED TO CONTROL Figure2.9


Analog

'l

Switches input 1o set pointin binary. / Gnd = logic0 \

"-1

t0

CHAPTER 2 switches. limit switches usedasa "backup" to detect if the loadhasgoneout The are it of its designaled range. Operation ofthe systenproceeds follows:The controllerinputsthe datafrom as port 03 !o determineif the start (or stop) button hasbeen pressed.If the stat button has beenpressed, thenthe setpoint is readin from port 0 1 andthe digitizedsensor datai s readin from porl 02. Basedon its controlstraregy, controlleroulputsto port 00 a the binary word representingthe motor control voltage.This digital data is convertedto an arulog voltage with the DAC. This entire sequence repeatedover and over until lhe is stopbuttonis pushed.

The Serial Intelface In a sdal interface, the data are sent I bit after the other on a single wire. There are a numberof goodreasons doingthis.First,the cablingis simplerbecause for only two (at wiresareneeded a minimun), thosebeing"data" and"retum."Second. shielding a small groupofwires, which is olten necessary an electrically in noisyindustdal envi ronment, easie.Third, serialdatacanmakeuseofexisting single-channel lines is data suchas tije telephone system(whichmay requireusinga modem). For these reasons, greater serialdatatransfer usuallyrecommended distances is for than 10-30 ft. Because dataalwaysexistin a parallelform insidethe computet it mustbe converted to serial databefbrc coming oul the sedal polt. This is accomplishedwith a spe cial parallel-to-serialconverter IC called a universal asynchronous rceiver transmittr (UART). On the otherend ofthe line, a receiyerrnustconvert serial the databackinto paralleldala,which is donewilh another UART.Figure2.10shows the basicserialdatacircuit. Serial data.rreclassified beiDg as eithersynchronous orasynchronous. S]rchftrrr&r datd require that the databytes be sent as a group in a "package." It is usedin sophistjcated communication that systems movea lot of dataandwill not be furtherdiscussed herc. Arytrchmtnus data tlanslbr is the more conmon (but slower) type of serial trans fer and a11ows individualbytesto be sentwhenneded. for

Figure2.10 conlroller Serialdala Paralleldata Serial'loparallel (UART)

INTRODUCTION IVICEOPROCESSOR,BASED TO CONTBOL


Figure 2.11

41

(w I0110010 ith

"*{.!$n*..cuon"o"..";.f
Time Figure 2. I 1 shows the standardformat for asyncbronous serial data. First, a stat bir rs .enl. rhenrhedatarLSB fint,. Lhen paril)_enor c checUng andfinall\ rhesroD bit, r. Drus 5ome vaflalionis alio$ed lo !hi. format.bur bothEar.mitrer andreceir mu,r er use the samefomat. The other important Dara nrcarryIncorrec( mostaase,). rn Srrnddrdbir rars are J00 6ps , bit\ per secondl, 1200

u* p.,,."."Jilliffi i:i':1fl'#ffi;1ifl ,,illiliJ:Ji: Tfl "iii",."i

bps.%00 bp.. 14.400 28.800 bps bps.iJ.600 bps.andj7.000bp".Se;iat 9l_\-2a00 h rlo\aer paralJel rh0n rransmi5(ion..]oO ir Lales At bps, ajmosl t,ms-lo tran(mil b] le of dara. compared less anu mi.ro,econA parutiit_ ro rt fo, "l rnr(r\ lhousands tifie( slowfr Slill.for many of applications. pdnicularly proce.\ con_ trol, the longerdata-transfer timesarcnot a problem, RS232 In orderto make serialinterface the practical, setof specifications a calledtheRS,232 sandard ase,!abtirhed. v Officialty. RS-232 fie shnaara,pec;nes seriui iru.r_*e Lra race Delq dalalerminalequipmenl een tDTE) anddalacommunication equiDment (DCE).A commor dpplicarion RS2J2 is rheinrerfrce ot Uerween ;ta;il; modem, whichcase computer theDTE anathenrodem Are in the is is DCe tsee Fieu;e 2.I2(a)lA modemis a device conveds thar digiral Antu uuOto into ro*, * tf,uiit?" beftansmitted thetelephone As shown Figure over lines. in 2.12, RS_232 the intefaca consists seven of signals; serialalata sentondn Z ina receiv"O pin:; ifreotfrer the is on signals, suchas"Request send', Clearto send,,, used confiimthat to and are to thetwo un(sareread)rocommunica(e. RS232skndard The specifie\ connector r\Des. sienal name...pin num,bers. vologes. pracdce. nS_ZlU aod In lhe rtana"ra li'rpoL;.?rl *" any seial interfaceastongas oneunir acrsas a Dfe anatfreottrer asa OCil n iwo DTE units needto interfacewirh eachother-for e*"-pl", a pC ro pC_;s;;;i"j a cable called rrullmodmor crossover a cableis use<]. 232is comm."t;;;;; RS thecontrolfield whentwo unitsneed exchange to data_for example, conieci a pi to to a local controlunit for thepurpose downloading n"* of u ot p.og.u., *_ittuJ tiated Figure in 2.12(b). "ont RS-232 serialdatatransfer somewhat is morecomplicated paralleldatatrans than fer, but it offersadvantages as two-wjrecommunications such anda universallv accepted inferface. hardware handle The to serialdatais standardized, readity avaitab/. andreliable.

:HAPTER 2 RS-232 2 3 5 6 20 7 Computer


Oaiaset ready

=8,;re2.12

DCE 2 3 5 6 20 7 Modem t'

=_

].,.

.]

(a) lnterface belween datatermjnal equipment (DTE) anddatacommunjcalion equipmenl (DCE). Serialdala transferred pins2 and3;the othersignats are on conlrol

{DCE) (b)Using RS-232 an seriat cable connect pC ro a contrcer 10 a

port(DTE) COIV

Probably*le most commonuseofsedal datais in networking. More andmore,net works are being usedto interconnect the units and device;in all the conrrolsy;tem. Network cabling differsdepenaling the type of Iocal area on network (LAi), but most usethe generalized sysrem bus diagmmmed Figure2.13.Typically,eachunit in on the net has a uniqueaddress numberand also aaa.ess aetecti# ci."riit y' Wfr"n one unir wantsto talk to anolherunit, ir filst broadcasts address the ofth; unit its wantsto talk to (serially,ofcourse,on the signalwire) andthen sends lhe data(seri_

CONTROL TO INTRODUCTION MICROPROCESSOR-BASED

43

Figure 2.'13

intefacemodule

of ally), which consists somenumberof bytes.All units on the net will receivethe receiverwill activateand tben read in the data.The addiess, but only the inteDded interface betweenthe network cable and the PC is done through a commercially availcardcalleda networkinteface card (NIC). Other devices able interfaceexpansion on the net, such as control units, would require a special interface circuit. which may are as bebuilt in or available an extemalmodule.Control systemnetworks discussed fufther in Chapter12.

TO 2.4 INTRODUCTION CONTROLLER PROGRAMMING


It is beyond th scopeof this text to presenta detailed discussionof how to program a micrcprocessor in machine language.Stiil, it is useful to investigatein a geneml way what the software must do. A digital con oller is a computer operating in real time. This meansthat tr pmSram is running all the time-repeatedLy taking in rhe ne\uest sensordata and the calculating a new outputfor the actuator. The basic structure of a controller program is a loop. [n a loop sftucture,the same over and over again,and eachpassthroughthe sequence ofinstructionsis executed prccontro]ler loop is caliedan iteration, or scafl Figure 2.14 showsa generalized the program follows: $am, and an explanation of L The program rcads in the set-poinl data (recall that the set point is the desiredposition of the controlled vadable).This data could be rcad in from an input port or ftom memory.

2 CHAPTER

2.14 Figure

Read in set Point data

Subtractto get eror ,

Sendoulpulvalue i nme delay(oflional)l )

(from a sensor)the actualvalue of the con2. The program diEcts the computerto rcail rolled variable. po-tnllo gel lj)e efior l. The actual dala are subtractedfrom the set a calculales new aclualorconuol slgnar' 4 Basedon the enor da!4 the compuler 5. The new ouqnrt is sentto ihe actualor' agarn' 6. The pmgrams looPsback to step I and starts ovel pass drougb lhe loo! deretmine' lor The dme il Lakes tbecompuErro exwuteoDe fie sampling mte) ll ous rnFrvat rs -nog. lhe dme hterval betweeninput readbgs ftnowD as \ariable"is picnxeol whal tbecontrolled tay Dotgetan accumte ;..otpr"t .o olatiasingr'E\ecudonoffie loopcan be o* b"ot"r i I lo;a discussion '"r,irl1* the progmm ln otheriruaor u-"lfi.*oiuy .p".iryine a laslercompuler strearnlininS mighl be in\enedlo.'glve a pause ano muslpaLrse walt.ru exarnph tioos.thecompuler for a motorto splnoown' or lo aliow time un opa-tot,i-" ,o a^t a .ome adjustmeot loopsh rheprogramA time'deia} loop is simpl} dme{elay iift"o 0."" ur-f"..** ' loop wherethe computeris instmctedto count up to some ;i*n*r .i*toilitc, "pi*i"g -rrtr| loop $e clcle dmefor lher)lain f*o t*.ft.*"|D tigure 2.l4).lhe efecl is !o slow ptedeerminedvalue o.* tiorce marchingof tle samplerale lo some i*ri -et .Jr",-". i. efficienl midoprocessor pro_ one time, peopte thought that the best and most

rff ffi #iili1Jtr!.: #:#5*x**t;:l*tli"ffir.*.ffi


r,".; ;;;
programs Today sophisticaled instructions language Lectly relecrthe mactrine

il;;;;;

w-ould h languase-lhar fie prosrammer in Jirec"uv assemulv (calleo

BASEDCONTROL TO NTRODUCTION I\4ICROPROCESSOR pdmarily C, into .rmpiler.!) can conve( a programwdtten in a highlevel language, very efficient machinelanguage.Highlevel languagesuseEngiish-soundingwords and programming operato a set ofpoweful commands specil, simpleand complicated to of instruciions. Using a highlevel language write programs tions witb a mjnimum suchas more compactprogram Listing.ease ollers big advantages. ibr a microprocessor writdocumentation. Also. programs and of wdting equations, morecomprehensible can ten in a high levellanguage be compiledto run on any modelof microprocessor

CONTROLLERS 2,5 MICROPROCESSOR.BASED


(Microcontrollers) Microcomputers Single-Chip
A miooprocessor by itself is not a computer To be functional, the microFocessormust be connectedto other integraledcircuits thal provide the memory and yO capabiiity.A specifically controlapplicafor is on microcontroller a computer a singleIC, designed memory(bothRAM andROM), VO pofts,and ofa microprocessor, tions.It consists Having the completecontroller possibly otherfeaturessuchas timers andADCS/DACS. on a single chip allows the hardwaredesign to be simple and very inexpensive. Microcontrollers are showing up iDcreasinglyin products as varied as industrial appli and cations.home appliances, toys. In suchusesasthese,they al cailedembeddedcon' trollers becausethe controller is locatedphysically in ihe equipmentbeing controlled. The main dillerence betweenmicroprocessorsand microcontrollers is that microprocessors being designed usein microcomputerswheregreaterspeedand larger are for word size are the driving requirements,whercasmicrocontrollers are evolving toward morehdrdware functionson tbe chip. Most control reduced chip countby integratiDg speed the of applications not needthe 32-bit word sizeand500-MHz (megahertz) do newermicroprocessors. Eight or 16bits and I MHz will workjusl fine in manyapplicostsmuch less. microcontroller cations, dndthe single-chip the microprocessors microconffollers and concerns Anothef difference between dealingwith movtendsto be rich in instructions instructionset.The microprocessor ing datainto and out of memory. The microcontroller has fewer memory-moveinstrucThe reasonfor the lack ofmemory-move tions and more bit-handlinginstructions. instructionsis that the microcontrollertypically has only a small amountofRAM, were which it usesonly as a "scratchpad."The additionalbit handlinginstructions in controlsystemapplicalions. example, a For they are so uselul;n includedbecause paralll outpul word might control a different bit control system,eachseparate ofa instructions allow the soft device,suchas a motoror indicatorlight. The bit-handling ware to tum one device easily on or off without affecting the others. The Motorola 68HC11is a popularS-bit microcontrollerthat has256 bytesof It RAM, 8K ofROM, and512K bytesofEPROM (seeFigure2.15a). alsohasfive 8 Anolhercommon8 bit polts with built-in sedaldatatransfer andADC capability. bit

15

2 CHAPTEB

Figure 2,15 Elock

--fI
PAOPA2 PA3-PA6 PA7 PBO PBT

P6iie.:,1

(s6raLport) (o thlADc nph)

Also exlenalAddress and Dala bus (a) N4olorola68HC11 microconlroller block diag!am

Also exlernalAddless afd Databus (b) lnrel8051 mcrocontroller bLockd agtam

RAs RAO (Canaiso be ADC inpuls) PIC 16C72mjcfo coilroller blockdiagram

FBO-FB7

RCO-FC7

( C a na l s ob e senarpon & iimer !nlerface)

INTRODUCTION MICROPROCESSOR-BASED TO CONTROL

47

microcontroller the Intel 8051,which has 128b)'tesof RAM and4K bytesof ROM, is four paralleldatapolts, anda sedalpolt (seeFigue 2.15b).For coffio1applications, usuallyare adequate: ROM is usedto storethe control thesehardwarearrangemenrs program, and RAM is used as data registers and a "scrafch pad." The VO signal lines can usuallybe connected direclly to the microcontrollerwithout addilionalpo cir cuiny. Software is typically written in C+ or some other language (including assembly language)and then convertedinto machinelanguagewith a compiler or assembler prcgram.The machinelanguage programwould then be loadedinto the microcon trolier's ROM or EPROM. Another popular micloconfoller is the PIC from Microchip Technology.For example, the PICl6Cxx family of 8-bit microcontrollers is a low-cost, versitle product that hasfound wide acceptance Figure 2.15(c)].Therc are a wide rangeof options, [see including ROM, EPROM, EEPROM, ADCS, Timers, and serial ports. The PIC usesa slightly differcnt architecturefrom the 68HC1i and 8051 in that the ROM (o. EPROM) that containsthe programconnects the CPU with its own l+bit bus, whereasthe iegto ular databus is 8 bits. Allowing I 4 bits for the program memory meansthat all instnrctions arejust one word long. The devicehasthreeI/O ports,but many ofthe I/O bits can be used in diflerent ways (such as for an orl/off switch or ADC input), depending on how they are programmed. Finally, anotherprcduct calledthe BASIC Stampftom Pamlla.\ Inc. is usually considered a microcontrollet allhough it is actually a very small circuit boad with a few ICs and pins. The whole circuit board plugs into an IC socket, as though il were an IC (seeFigure 2.16 ). Wlat makesthe BASIC Siamp somewhatuniqueis that it hasan onboard BASIC program interperater.A program can be written in BASIC on a PC and tln dirccdy downloadedinto the Stamp'sEEPROM through a RS 232 pot. No assembler or compiling operation is required. There are now oiher micrccon[ollers on the market that can be prograrnmedin BASIC. In summary, a wide vanety of microcontrollers are available. At the low end are the 4-bit models, which are morc than adequatefor appliancesand toys. Thesetend to be large-volume,low-cost applications.Eight-bit microcontrollers (suchas the 68HC11 earlier)are very popularbecause bits turn out to be a convenand 8051 menlioned 8 ient size for both numericandcharacter data.At the high end, 16 and32-bit microhigh-speed controllers are availablefor control systemsrequiiing sophisticated,

2.16 Figure
BASIC Stamp nodule(BS2Ic).

.$

2 CHAPTER or avionics, as servomechanisms. powerfor suchapplications complicated calculating imageprocessng.

Computers Single"Board
computersbuilt on a Sitrg'board computers are off-the-shelf microprocessor_based butin genprinted-circui! Theycomein manyconfigurations, card(Figure2.17). single such eraltheyusea standadmicroprocessor astheZilog 280, the IntelxS6lamilt the They alsoincludememoryICs (bothRAM and Motorola68000,or a microconlroller perhaps specialinterfacecircuitssuchasADCSorDACS and RoM),l/O capability, produceN suchas by compulers manufactured major nicroprocessor are Single-bodrd SomesingleboardcomIntel and Motorolaas well as manyolhersmallercompanies. of card.The obviousadvantage putersare desjgned plug into a PC as an expansion to and design_ board-testing boardis thatit eliminales usinga rcady mademicroprocessor time. This is paticularly important in small volume productior or one of kind systems.

Logic Controllers Programmable


microprocessor-based A programmable logic controller (PLC) is a self contained includes an yO sectionthat can unit, designedspecifically to be a controller. The PLC 2.17 Fig|.lre

..

il ! i!n m!.d I *dr1;r.ir! "r ,iarrra. t &91{d..,

CONTROL TO INTRODUCTION NI]CROPROCESSOR-BASED

49

relays,small motors,and as intedacedjrectly to suchsystemcomponents swiiches, lights. Developedin the late 1960sto replacerelay logic controllers,PLCShave PLCScomein motioncontrolapplications. evolvedto be ableto ha dle sophisticated The big difi:er of Figure2.18 showsa selection PLCS. andcapabilities; varioussizes is discussed this sectlon thatthe PLC has in encebetween PLCSandthe otherdevices packagethat hasbeenruggedi porls, andpower supply built i o a the microprocessor, the is in Installation vefy easybecause manycases zedfof an industrialenvironment. sensorsand actuatorscan be connecteddircctly to the PLC- Once installed, the micrc_ suchas apersonal programis downloadedinto the PLC from somesource processor computer.The PLC manufacturerusually supplies software to facilitate the program This softwareallows the userto write a programwith line-byline ming operation. or instructions, it can converta relay logic-wiring diagram(ladderdiagram)directly

2.18 Figure
(Allen-Bndley

50

2 CHAPTER into a PLC program. Multiple PLCSin a plant can be networked so the individual units can be monitored and programmedfrom a single station. This is a form of distdbuted in in computer control (DCC) discussed Chaptor 1. PLCs are discussed detail in Chapter12.

Personal Computers Usedin Control Systems


The availabilityofrelatively low-cost,off-the-shelfpersonal computers (PCs)has madethem an attractivealtemativefor small, one-of-kind confol applications.control system software packagesare commercially available for the PC that run under DOS and Windows. Theseprcgrams are adaptableand allow the user to tailor the software to fit the control application,essentiallytuming a PC into a PLC (aithoughnot as use rugged).Most of thesepackages interactive graphicsto link animation with changprocessvalues.Someprograms ing haveprovisionsto mathematically simulatethe process beingcontrolled help optimizethe controllercoefficients. to A standardPC comeswith xpansion slofs, which are circuit-cald connecton emanaring frcm he motherbodrd(main board) of the computer.E4)ansion cards plug into ihese slots and foIm a bridge betweenthe compuier and the outside world. Many dif ferent types of interface cards are available, such as VO seial and parallel datapors,

2.19 Figure
Muiti-function lO boaJd. includesADC. DAC, and digital LO. (Coulresyof Engineering, Inc.) Omega

INTBODUCTION MICROPROCESSOR,BASED TO CONTROL

51

ADCS, DACS,and computer-controlled output relays, to name a few Figure 2.19 shows an example of a'l interface expansioncard. Histodcally, data-acquisitionand controi functions were kept separate. Controllers ran the process,and other insfuments measuledand recorded the iesu]t. The concept of having single perform a PC \eem\ logical: bolhtasLs afler.rll.the pC cdnuseir. computingability first as the controllerandthen tabulatesystemperfomancedata. These data can be siorcd on disk and/or displayed on the moniioi. A potential problem may arisebecause contoller must operatein real time. If a the computeris to control a process monitor it at the sametime, the alata-rcduction and process must not take so long as to interferewith the control duties; a connol rcsponse can't wait. One way to overcomethis problem is to divide the control and data-acquisitiontasks amongmultiple processors, Using the PC as the mastercomputer, separate a microprccessoron an expansionca.d canperfom datacolleclion uninterrupted.one type of yO controller cardhas slots for threesmallerboads. Thesesmallet boardshavevatious combilations of analogand digital yO ports and counter-timers.Someboardsare available with solid-staterelays, which can be usedto directly control AC andDC motors. A rc with tO expansion cardsoften costslessthan a stand-alone computedzed con tloi system.The cardsdo not needa separute enclosureand use the pc's power supply, keyboard for input, and monitor for display.Also, using a standardPC meansthat plogiams canbe developed anothercompatiblecomputer,eliminating process on downtime. Numerous manufacturersare selling iugged PCs that can survivo in haish industrial environments.Thesecomputerstypically use a membmne,typekeyboard(the keyboard appears one continuous as sheetofflexible plastic)and havesealed cases and filte$ covering the air vents.Somemodels of thesecomputersare rack mountableand -backup \ontainlheiro$ n balter) power luppl.

SUMMARY
A micrcprocessor is a digital integated circuit that peforms the basic operationsof a computer.Microprocessonareusede"xtensively the basisof a digikl controller Digital as control systemsare advantageous because digital data can be tmnsferredand storedvirtually error-free,andthe contml stmtegycaDbe changedby simply reprogramming. A computer consists offourbasic functional units:(1) the CPU (microprccessor), which executes programmed the insfuctions andperfoms the calculations; the (2) memory,which stores programand data;(3) input; and (4) output.Inpuvoutpu! ihe interfaces the computer to ihe outside world. A microprocessor,based computerinterconnects theseunits with threegroupsof signals calledbuses. address carrjes The bus the address ofthe datato be processed. databus caries the data,andthe con[o] The bus carriostiming and control signals.Computershandle data as groups of binaty bits. Many microprocessorbasedcontrollers handle data in 8-bit gloups called a byte. A microprccessorhas a set of instructionsthat it can execute(called ihe instruction set).Each instruction is identified by a digital code called the operationcode (oP.code).

52

2 CHAPTER A program consists of a list of ihese op-codesstored in memory Tbe micrqro6(f them. one bt oEautomatically fetcheslhe instructions ftom memory and executes A digital conrroller may havetwo kinds of data intefaces: paiallel and senal-Tbe system,where all 8 bits are sentat fte parallel interf-ace the most straightforward is inteface, datais sent 1 bit after the otber sametime on eight sepantewires. In the serial on a single wire. Serial data transfer is better for longei distances that require an analogsignalinterface; usecomponents Many control systems therefore, the signals to or from the digital conuoller must be convened with an ADC (analog-to-digital converter) or a DAC (digital to-analog converter) Both circuits are avaiiablein IC folm. format.First, it readsthe setpoint The digital controllerprogramhasa siandard enor Based ihe thesevalues determine system to Thenit subtracts values, andsensor responsesignal and sends on lhe error value, it next calculatesthe appropriateactuator the of it out.Thenit loopsbackto the beginning the progmmandexecutes samesetof instructions over and over, forms.A micro_ controllers comein a numberof standard based Microprocessor memory,and inpuvoutputall on a singlelC. A microprocessor, controllerincludesa computet assembled single-board computer is an off{he-shelf microprocessor_based logic controller(PLC) is a selfonto a singleprinled circuit board.A programmable (PC)is a computer A designed be a controller. personal to unit specifically contained computer;however,with the addilion of interface generalpurpose,self-contained expansioncards, a PC becomesa very adaptableand cosFeffectivecontroller.

GLOSSARY
used register themictoprocessor in in accumulator A tempomrydigital datastorage moving operalion\. dnd mrn) mrlh.rogic. datc converter. ADC See analog-to-digital or the that address A number represents locationof I byle of datain memory a spe_ port. cific input/oulput to memory yO and fromthemicroprocessor coming ofsignals addressbus A group ports, the specifying address. logicunit. ALu See arithmetic and arithmetic logi arithmeticlogic unit (ALU) Thepaltof theCPUthatperforms cal opemlions. (usually IC) thatcanconvert anaan (ADC)A dvice an converter analog-to-digital into its digital binaryequivalent log voltage

INTRODUCTIONTOVICROPBOCESSOB-BASEDCOI\TBOL 53

progmmwrittenin Drnemonics, assembly language A computer whichareEnglishlike abbrevntions machine-code for instruclioft . baud Therateat whichthe signalstates changing; are liequentlyused mean"bits to per second," bjt Thesmallest of digitai unit data, whichhasa value 1 or 0. of byte An 8-bitdigital word. pan central processingunit (CPU)Thecentral ofa computet CPUperforms the all calculations handles contlol and the functions thecomputer of control bus A group oftimiDg control and signals coming fromthomicroprocessor to memory yo pots. and crossovel cable Sr" null modm. CPU See cntralprocessing unit. DAC See digital-to-analogconverter. goingto andfrom themicroprccessor, data bus A groupof signals memory, VO and ports.Thedatabuscaries theactualdatathat arebeingprocessed. data communication equipment(DCE)Oneof twounitsspecified theRS-232 by (for standard serialdatatransfer); DCEis usuallya modem. the dataterminalequipment(DTE)Oneoftwo unitsspecified theRS-232 by srandard (for serialdatatransfer). DTE is rsually the computer The DCE See dalacommunication equipmenl digital-to-analog converter(DAC)A circuit translates that digital data ananainto log voltage. prcgram datainto a computei download To transfer computer a (ftom another or compu@r), DTE Seedata terminal equipment. embeddedconttollei A srnall microprocessor-based contloller is permanendy that installedwid n themachine is controlling. it expansioncard/slot An expansion is a printed card circuitcardthatplugs into an (PC). expansion on themotherboard a porsonal slot of computer Theexpansion card usuallyinterfaces PCto theoutside the world. letch-execute cycle A computer cyclewhere CPUfetches instruction then the an and Inpuvoutput(UO)Dataftomtherealwoddmoving andoutof a computer in YO Seinput/output.

54

2 CHAPTER

that microprccessor is instfuction set Thesetofprogram commands a panicular designed recognize execute. to and program executed thedigital coniteration Onepass thfough computer the bing by data the troller; each iteration"reads"theset+oint andsensor andcaiculates outputto ihe actuator, LAN See localarcanetwork. mean leastsignilicantbit (LSB) Therightrnost of a binary bit number also Can the incrcment change. of smallest cases where single is used rcprea bit to Iogicalvariable A single data in those bit sentanon-off switch.motoron-offconrol. andsoon. that multiple units communicate to with Iocalareanetwork(LAN) A systen allows wire. each orherall sharing (dmeinrerconnecrion lhe LSB sdleastsignificantbit. mach,nelanguageThesetof operation codes a CPUcanexecute. that storcs digitaldata. Memory data stored is as memory Thepartofthe computerthat whereeachbyteis givenanaddress. bytes, memory-mapped input/outpLrt system A where portsaretreated vo exacdy like memory locations, a memory, and microcontroller An integrated circuitthatincludes microFocessot inpuroutput;in essence, "computer a chip." a on microprocessorA digital integmted circuitthatperforms basic the operations ofa but support integrated circuitsto be functional. computer rcquiressome number. most significantbit (MSB)Theleftmost in a binary bit of code. mnemonic An Englishlike abbreviation anopemtion serialdatafrom diqitalform into tones canbesent that modem A circuitthatconverts throughthe telephone system. MSB See mostsigdficsntbit, when nonvolatlle memory Computer memory suchasROMthatwill notloseits data thepoweris turnedoff. (rre two with oiher null modem A cable allows DTEunitsto communicate each that RS-232). code wordusedby micioprocessor the to idenoperationcode (op-code)A digital tify a particularinsffuction. parallel intertace A typeofdatainterface where8 bits enter leave unitat the ol a same time on eisht wircs.

TO INTRODUCTION ]\iIICROPROC@ PC Seepe$onal computer. genemlpurpose self_contained' personal computer (PC) A microprocessor-based, computer (usuauy refers to an IBM or compatible computer) PLC S?eprogrammable logic controller. eachport has an port The pan of a computerwhereI/O data lines are connected; address. registerin a computerthat holds the program counter A specialaddress-holding to ad&essof the nextinstruction be executed microprocessorprogrammable logic controller (PLC) A rugged,self contained to be usedin an industrialenvironmenl specifically basedcontrollerdesigned memorY. RAM Sedrandom-access calledread/write memory'a memory random'access memory (RAM) Sometimes wheredatacanhe written in or readou| RAM losesits usingadalresses arrangemenl whenthe poweris turnedoff. contents memory'but it read-onty memory (ROM) Sirnilarlo IiAM in rhat it is addressable also' it doesnoi loseits dalawhen be anal comespr;programmed cannot wilten into; the power is turned ofi to memory read/write (R/W) line A conlrolsignalthatgoeslrom the microprocessor lata at the sametime thal the dali reaf time Refersto a comp ter mat rs processing by are generated the syslem digitaldata because the conversion, enor that occurs resolution In digital-toanalog vaiues. canonly havecefain discfete ROM Seread-onlymemory. and levels voltage ihat standard specifies RS-232standard A seial datatransmission DCE (modem or other device) signal protocol between a DTE (computer) and a BAV Sesrad/write line. data a sampling rate The timespl3rsecond digiralcontrollerreadsthe sensor scan Seiteration. serial inte{ace a singlewire. A type of intedace where data are transferred 1 bit ailer the other on

onlo assembled computer microprocessor-based single-board computer A premade card. a singleprinted-cifcuit

56

CHAPTEB? is wherethe computer givena "do-noth_ time-delay loop A progatrming techDique time' of for thePurpose delaying largenumtter to ing" job suchas_cormtin! some rceivertratrsmitter' universalasynchronous UART See purpose inte_ universalasynchronousreceivertransmitter (UART) A special andvice versa' from parallelto sedalformat gratetlcircuit that conve(salata memorysuchasI{AM that wil lose its datawhenthe volatile memory Computer poweris tumedof4' \ r cornmon ord sizesaJe compute uses: word A unit of digilal datalhata particular 8. 16.and32birs.

E)(ERCISES
2.1 Secaion
and 1. Briefly descdbe the functions of the AIU' confiol unit, CPU momory' input/oLrtPut. (Specify 2. V/hat stepsdoes the microprocessortake to rcad data at address 1020? bus the actions of the adakess and data bus in your answer') brs' data bus ^id control bus' 3. Briefly alefined/d/ess num4. Use the methoalshownin Example 2.1 to find the decimal value of the brnary ber01011101. the binary 5. Use the methoal shown in Example 2.1 to find the decimal value of number11011010.

Section 2.2
6. wlat is a microFoce ssor instraction set, aldhow is it different from a high-level latrguage such as BASIC? 7. A certain nicroprocessor has a simple instruction set shown below' SET INSTRUCTION ExDlaation Op-code l{a1t the mrcloprocessol 16 Add next byie to accunmlalorc6t SubEct lext byte frcm accunulator' D5* Itrcrement the accuulato! 3C Decrerent the accunulator3D Move lhe nert byte into the accumulator' 3E* 'These ins"flclions use tuo bli"eE'

belowwasrun? showll after wouldbein theaccumulator theProgram what number

INTRODUCTION lllICROPROCESSOR-BASED TO CONTROL


PROGRAIi4 Add"ess 001 002 003 004 005 006
0p-code

3E 05 D6 a2

:c
76

Section 2.3
E. Temperature valuesfrom -20"F to 120"F arc input data for a micropmcessor com_ puter Are 8 bits sufEcient? Ifso, what is the resolution? Explainrhe luncrionol he fo|,owingt rutt?l ljam poft and,"riat dan pon. pa .9.. s - e n a t d a l a lU a r e\ r n r a r1 2 0 0 b p s u s i n g l h e l o r m a r o f F i g u r e 2 . l l . w i { h o n e s r o How long wouldit taketo send10OO bytesofdata? 11, An 8 bir DAC has a referencevoltage of 9 V The binary input is 00 00. Find the analogoutputvoltage. 12. The^b-inary ftom the computerin a cetain application are data expectedto go from 00000000 or ) 00t | | I I L These ro daraare|}leinpurof a DAC. The dnalo;oLbur rhouldgo 0.5 V find $e DAC reference !otlage nece,.aryLomakerhisiaoojn

13. An 8-bir ADChas rererence a !ottage t2 v u"aun-rtoe t"pur j.i tiFi;d of thebinaryoutput. "r 14. Thebinaryoulpurof anADC shouldhavethe mnge00000000_ t 1 11 11cone_ sponding aninput of 0-6V Find thenecessary to rcfetence voltage. Section 2,4

15-, U\that real-time ls ar!p,'jrg, andis it necessary controlsystems? for 16. De.cribe bdsic.leps a conrolprogram (toopj. dre in \can jn | /. Ar (omepornt lheprogram js de\ired hare compuler il to the wait5 ! lor an operalor re.pon\e. How\ ouldrhisdelay accomplishedsoftwarel be in _^ t6. A program conrains jnsFucdonq. l})e 150 and aterage e\ecuiion rimeperinstruc_ ps.Findthesample of thisprogam. tionis 2 rate Section 2,5 19. What]s a micmcontroller,ar,d\that arc some differcnces between micrccon_ a troller anda microptocessot?

20. What is a programmable toeic controller?


You \vant to use a personalcomputer to contlol a simple robot arm. The arm has two Joinls, an elbow and a wrist. Eachjoint has a DC motor and a posirion sensor you atreaaly that outpursa DC votrage. havea ,'plain vani[a,,pC;make a lisr of what you would need to acquire to make this svstem work. 22. Compare and conrrasr following:a ,fli roprocesror. nicmconrmller,a pro. fie a grammable logic contfoller, anda personal computer.

You might also like