You are on page 1of 53

TheHumanandPhysicalInterface

Chapter8 Sections1 9

Dr.IyadJafar

Outline
Introduction FromSwitchestoKeypads LEDDisplays SimpleSensors Actuators Summary

Introduction
Humansneedto interfacewith embeddedsystems; inputdataandsee response Inputdevices:switches, pushbuttons,keypads, sensors Outputdevices:LEDs, sevensegmentdisplays, liquidcrystaldisplays, motors,actuators
3
UserInteraction

Software
Input Variables

Embedded Computer Hardware

Output Variables

Linktoother systems

Examples

Introduction

FridgeControlPanel

PhotocopierControl

Introduction
Examples

CarDashboard
5

MovingFromSwitchestoKeypads
Switchesaregoodforconveyinginformationofdigitalnature Theycanbeusedinmultiples;eachconnectedtooneportpin Incomplexsystems,itmightnotbefeasibletokeepadding switches?! Usekeypads!
Canbeusedtoconveyalphanumericvalues Agroupofswitchesarrangedinmatrixform

MovingFromSwitchestoKeypads
InternalStructureofKeypad

MovingFromSwitchestoKeypads
HowtoDeterminethePressedKey

MovingFromSwitchestoKeypads
UsingKeypadinaMicrocontroller

MovingFromSwitchestoKeypads
Example
Aprogramtoreadaninputfroma4x3keypadanddisplaysthe equivalentdecimalnumberon4LEDs.Ifthepressedkeyisnot anumber,thentheLEDsshouldbeallon.
ThekeypadwillbeconnectedtoMCasfollows Rows0to3connectedtoRB7toRB4respectively. Columns0to2connectedtoRB3toRB1

UseportBchangeinterrupt connecttheLEDstoRA0RA3 basedonthepressedkey,converttherowandcolumnvaluesto binaryusingalookuptable

10

KeypadInterfacingExample
#INCLUDE ROW_INDEX COL_INDEX PIC16F84A.INC EQU EQU ORG 0X0000 GOTO START ORG 0X0004 GOTO ISR BSF MOVLW MOVWF MOVLW MOVWF BCF CLRF MOVF BCF BSF BSF GOTO 0X20 0X21

START

11

LOOP

STATUS,RP0 B11110000 TRISB ;SETRB1RB3ASOUTPUTAND ;RB4RB7ASINPUT B00000000 TRISA ;SETRA0RA3ASOUTPUT STATUS,RP0 PORTB ;INITIALIZEPORTBTOZERO PORTB,W ;CLEARRBIFFLAG INTCON,RBIF INTCON,RBIE INTCON,GIE;ENABLEPORTbCHANGEINTERRUPT LOOP ;WAITFORPRESSEDKEY

KeypadInterfacingExample
ISR MOVF MOVWF BSF MOVLW MOVWF BCF CLRF MOVF MOVWF CALL BSF MOVLW MOVWF MOVLW MOVWF BCF CLRF MOVF BCF RETFIE PORTB,W ;READROWNUMBER ROW_INDEX STATUS,RP0;READCOLUMNNUMBER B00001110 TRISB STATUS,RP0 PORTB PORTB,W COL_INDEX CONVERT ;CONVERTHEROWANDCOLUMN STATUS,RP0;PUTTHEPORTBACKTOINITIALSETTINGS B11110000 TRISB ;SETRB1RB3ASOUTPUTAND B00000000;RB4RB7ASINPUT TRISA ;SETRA0RA3ASOUTPUT STATUS,RP0 PORTB PORTB,W ;REQUIREDTOCLEARRBIFFLAG INTCON,RBIF

RST_PB_DIRC

12

KeypadInterfacingExample
CONVERT BTFSS MOVLW BTFSS MOVLW BTFSS MOVLW MOVWF BTFSS MOVLW BTFSS MOVLW BTFSS MOVLW BTFSS MOVLW MOVWF COL_INDEX,3 ;IF1ST COLUMN,COL_INDEX=0 0 COL_INDEX,2;IF2ND COLUMN,COL_INDEX=1 1 COL_INDEX,1;IF3RD COLUMN,COL_INDEX=2 2 COL_INDEX;STORETHECOLUMNINDEX ROW_INDEX,7 ;IF1ST ROW,ROW_INDEX=0 0 ROW_INDEX,6 ;IF2ND ROW,ROW_INDEX=1 1 ROW_INDEX,5 ;IF3RD ROW,ROW_INDEX=2 2 ROW_INDEX,4;IF4TH ROW,ROW_INDEX=3 3 ROW_INDEX

FIND_ROW

13

;CONTINUEDONNEXTPAGE

KeypadInterfacingExample
COMPUTE_VALUE MOVF ADDWF ADDWF ADDWF CALL MOVWF RETURN ROW_INDEX,W ;KEY#=ROW_INDEX*3+COL_INDEX ROW_INDEX,W ROW_INDEX,W COL_INDEX,W;THEVALUEISINW TABLE PORTA ;DISPLAYTHENUMBERONPORTA

14

KeypadInterfacingExample
TABLE ADDWF RETLW RETLW RETLW RETLW RETLW RETLW RETLW RETLW RETLW RETLW RETLW RETLW END PCL,F 0X01 0X02 0X03 0X04 0X05 0X06 0X07 0X08 0X09 0X0F 0X00 0X0F

;ERRORCODE ;ERRORCODE

15

LEDDisplays
Lightemittingdiodesaresimpleandeffectiveinconveying information However,incomplexsystemsitbecomeshardtodealwith individualLEDs Alternatives
Sevensegmentdisplays Bargraph Dotmatrix Starburst

16

SevenSegmentDisplay

17

SevenSegmentDisplay
Multiplexingofsevensegmentdigits
Connection Segmenta Segmentb Segmentc Segmentd Segmente Segmentf Segmentg Segmentdp Digit1drive Digit2drive Digit3drive Digit4drive PortBit RB7 RB6 RB5 RB4 RB3 RB2 RB1 RB0 RA0 RA1 RA2 RA3

18

SevenSegmentDisplay
Multiplexingofsevensegmentdigits

19

SevenSegmentDisplay
Example
Aprogramtocountcontinuouslythenumbers0through99 anddisplaythemontwosevensegmentdisplays.Thecount shouldbeincrementedevery1sec.Oscillatorfrequencyis3 MHz.
connectthesevensegmentinputsa throughg toRB0throughRB6

respectively connectthegatesofthecontrollingtransistorstoRA0(LSD)andRA1 (MSD) themainprogramwillberesponsiblefordisplayandmultiplexing every5ms


20

SevenSegmentDisplayExample
#INCLUDE LOW_DIGIT HIGH_DIGIT COUNT PICF84A.INC EQU EQU EQU ORG 0X0000 GOTO START ORG 0X0004 GOTO ISR BSF MOVLW MOVWF MOVLW MOVWF BCF CLRF CLRF CLRF CLRF CLRF 0X20 0X21 0X22

ISR START

21

STATUS,RP0 B00000000;setportBasoutput TRISB B0000000 TRISA ;SETRA0RA1ASOUTPUT STATUS,RP0 PORTB PORTA LOW_DIGIT;CLEARTHECOUNTVALUE HIGH_DIGIT COUNT

SevenSegmentDisplayExample
DISPLAY BCF MOVF CALL MOVWF BCF BSF CALL STATUS,RP0 LOW_DIGIT,W;DISPLAYLOWERDIGIT TABLE ;GETTHESEVENSEGMENTCODE PORTB PORTA,1 ;enabledigit0 PORTA,0 DELAY_5MS ;KEEPITONFOR5MS

MOVF CALL MOVWF BCF BSF CALL

HIGH_DIGIT,W;DISPLAYHIGHDIGIT TABLE ;GETTHESEVENSEGMENTCODE PORTB PORTA,0 PORTA,1 DELAY_5MS;KEEPITONFOR5MS

22

SevenSegmentDisplayExample
;CHECKIF1SECELAPSED INCF COUNT,F ;INCREMENTTHECOUNTVALUEIFTRUE MOVF COUNT,W SUBLW D100 BTFSS STATUS,Z GOTO DISPLAY;DISPLAYTHESAMECOUNT INCF MOVF SUBLW BTFSS GOTO CLRF INCF MOVF SUBLW BTFSS GOTO CLRF GOTO LOW_DIGIT,F;INCREMENTLOWDIGITANDCHECKIF>9 LOW_DIGIT,W 0X0A STATUS,Z DISPLAY LOW_DIGIT HIGH_DIGIT,F;INCREMENTHIGHDIGITANDCHECKIF>9 HIGH_DIGIT,W 0X0A STATUS,Z DISPLAY HIGH_DIGIT DISPLAY

23

SevenSegmentDisplayExample
DELAY_5MS REPEAT MOVLW MOVWF NOP NOP NOP NOP NOP NOP NOP NOP NOP NOP NOP NOP DECFSZ GOTO RETURN D250 0X40

0X40,1 REPEAT

24

SevenSegmentDisplayExample
TABLE

ADDWFPCL, 1 RETLW B'00111111' RETLW B'00000110' RETLW B'01011011' RETLW B'01001111' RETLW B'01100110' RETLW B'01101101' RETLW B'01111101' RETLW B'00000111' RETLW B'01111111' RETLW B'01101111'

;'0' ;'1' ;'2' ;'3' ;'4' ;'5' ;'6' ;'7' ;'8' ;'9'

END

25

Sensors
Embeddedsystemsneedtointerfacewiththe physicalworld Mustbeabletodetectthestateofthephysical variablesandcontrolthem Inputtransducersorsensorsareusedtoconvert physicalvariablesintoelectricalvariables
Lightsensors Temperaturesensors

Outputtransducersconvertelectricalvariablesto physical;actuators
26

Sensors
TheMicroswitch

27

Sensors
LightdependentResistors
Alightdependentresistor(LDR)is madefromapieceofexposed semiconductormaterial Whenlightfallsonit,itcreates holeelectronpairsinthe material,whichimprovesthe conductivity.
Illumination(lux) Dark 10 1000
28

RLDR (Ohms) 2M 9000 400

Vo 5 2.36 0.19

Sensors
OpticalObjectSensing
Usefulinsensingthepresenceorclosenessofobjects Thepresenceofobjectcanbedetected
Ifitbreaksthelightbeam Ifitreflectsthelightbeam

29

Sensors
OptosensorasaShaftEncoder
Usefulinmeasuringdistanceandspeed

30

Sensors
UltrasonicObjectSensor
Basedonreflectiveprincipleofultrasonicwaves Anultrasonictransmittersendsoutaburstof ultrasonicpulsesandthenthereceiverdetectsthe echo Ifthetimetoechoismeasured,distancecanbe measured

31

Actuators:motorsandservos
Embeddedsystemsneedtocausephysicalmovement Linearorrotarymotion Mostactuatorsareelectricalinnature
Solenoids(linearmotion) Servomotors(rotarymotion) DCorsteppermotors(rotarymotion)

32

DCMotors
Rangefromtheextremelypowerfultotheverysmall Widespeedrange Controllablespeed Goodefficiency Canprovideaccurateangularpositioningwithangular shafts Onlythearmaturewindingneedstobedriven

33

StepperMotors
Asteppermotor (orstepmotor)isasynchronouselectric motorthatcandivideafullrotationintoalargenumberof steps.

34

StepperMotors
Features
Simpleinterfacewithdigitalsystems Cancontrolspeedandposition Awkwardstartupcharacteristics Losetorqueathighspeed Limitedtopspeed Lessefficient Morecomplextodrive

35

ServoMotors
Allowspreciseangular motion Theoutputisashaftthat cantakeanangular positionoverarangeof 180o Theinputtotheservois apulsestreamwhose widthdeterminesthe angularpositionofthe shaft
36

InterfacingtoActuators
Microcontrollerscandriveloadswithsmall electricalrequirements Somedevices,likeactuators,requirehighcurrents orsupplyvoltages Useswitchingdevices SimpleDCswitchingusingBJTsorMOSFETs ReversibleDCswitchingusingHbridge
37

InterfacingtoActuators
SimpleDCinterfacing

38

InterfacingtoActuators
SimpleDCinterfacing

Resistiveload
39

Inductiveload

InterfacingtoActuators
SimpleDCinterfacing Characteristicsoftwopopularlogiccompatible MOSFETs

40

Interfacing to Actuators
DrivingPiezo SounderandOptosensors

Piezo sounderratings:9mA,320V Theoptosensorfoundtooperatewellwith91Ohmresistor.Thediode forwardvoltageis1.7V.Therequiredcurrentisabout17.6mA


41

Interfacing to Actuators
ReversibleDCSwitching
DCswitchingallowsdrivingloadswithcurrentflowinginone direction Someloadsrequirestheappliedvoltagetobereversible;DC motorsrotationdependsondirectionofcurrent UseHbridge!

42

Interfacing to Actuators
ReversibleDCSwitching

43

L293DDualHbridge Peakoutputcurrent1.2Aperchannel

Interfacing to Actuators
ReversibleDCSwitching DrivingthreemotorsusingL293D

44

More on Digital Input


Whenacquiringdigitalinputsintothemicrocontroller, itisessentialthattheinputvoltageiswithinthe permissibleandrecognizablerangeoftheMC Voltagerangedependsonthelogicfamily;TTL,CMOS, Interfacingwithinthesamefamilyissafe Whatforthecase Interfacingtodigitalsensors Signalcorruption Interference

45

More on Digital Input


PIC16F873APortCharacteristics

46

More on Digital Input


FormsofSignalCorruption

Spikesinthesignal

47

Slowedge

DCOffsetinthesignal

More on Digital Input


ClampingVoltageSpikes

Allportsareusually

protectedbyapairof diodes Anoptionalcurrent limitingresistorcanbe addedifhighspikesare expected


IfRprot =1K andthemaximumdiodecurrentis20mAwhenVd=0.3v, thenwhatisthemaximumpositivevoltagespikethatcanbesuppressed?

48

More on Digital Input


AnalogInputFiltering

CanuseSchmitttriggerforspeedingupslowlogicedges. SchmitttriggerwithRCfiltercanbeusedtofiltervoltage spikes.


49

More on Digital Input


SwitchDebouncing Mechanicalswitchesexhibitbouncingbehavior Theswitchcontactbouncesbetweenopenandclosed Aseriousproblemfordigitaldevices?!

Switchdebouncing!!hardwareand/orsoftware
50

techniques

More on Digital Input


SwitchDebouncing

51

More on Digital Input


SwitchDebouncing

52

Summary
Microcontrollersmustbeabletointerfacewiththe physicalworldandpossiblythehumanworld Switches,keypadsanddisplaysrepresenttypicalexamples forinterfacingembeddedsystemswiththehumans Microcontrollersmustbeabletointerfacewitharangeof inputandoutputtransducers. Interfacingwithsensorsrequiresareasonableknowledge ofsignalconditioningtechniques Interfacingwithactuatorsrequiresareasonable knowledgeofpowerswitchingtechniques

53

You might also like