09 chapter 8 - human physical interface
TRANSCRIPT
-
7/31/2019 09 Chapter 8 - Human Physical Interface
1/53
Chapter8
Sections1 9
Dr.IyadJafar
TheHuman
and
Physical
Interface
-
7/31/2019 09 Chapter 8 - Human Physical Interface
2/53
Outline
Introduction
From
Switches
to
Keypads LEDDisplays
SimpleSensors
Actuators
Summary
2
-
7/31/2019 09 Chapter 8 - Human Physical Interface
3/53
Introduction
Humansneedto
interfacewith
embeddedsystems;
inputdataandseeresponse
Inputdevices:switches,
pushbuttons,keypads,sensors
Outputdevices:LEDs,
sevensegmentdisplays,liquidcrystaldisplays,
motors,actuators
3
EmbeddedComputer
Hardware
Software
Input
Variables
Output
Variables
Linktoother
systems
UserInteraction
-
7/31/2019 09 Chapter 8 - Human Physical Interface
4/53
Introduction Examples
FridgeControlPanel
PhotocopierControl4
-
7/31/2019 09 Chapter 8 - Human Physical Interface
5/53
Introduction
Examples
CarDashboard
5
-
7/31/2019 09 Chapter 8 - Human Physical Interface
6/53
MovingFromSwitchestoKeypads
Switchesaregoodforconveyinginformationofdigitalnature
Theycanbeusedinmultiples;eachconnectedtooneportpin
Incomplexsystems,itmightnotbefeasibletokeepadding
switches?! Usekeypads!
Canbeusedtoconveyalphanumericvalues
Agroupofswitchesarrangedinmatrixform
6
-
7/31/2019 09 Chapter 8 - Human Physical Interface
7/53
MovingFromSwitchestoKeypads
InternalStructureofKeypad
7
-
7/31/2019 09 Chapter 8 - Human Physical Interface
8/53
MovingFromSwitchestoKeypads
Howto
Determine
the
Pressed
Key
8
-
7/31/2019 09 Chapter 8 - Human Physical Interface
9/53
MovingFromSwitchestoKeypads
UsingKeypad
in
aMicrocontroller
9
-
7/31/2019 09 Chapter 8 - Human Physical Interface
10/53
MovingFromSwitchestoKeypads
Example
Aprogramtoreadaninputfroma4x3keypadanddisplaysthe
equivalentdecimalnumberon4LEDs.Ifthepressedkeyisnot
anumber,
then
the
LEDs
should
be
all
on.
ThekeypadwillbeconnectedtoMCasfollows
Rows0to3connectedtoRB7toRB4respectively.
Columns0to2connectedtoRB3toRB1
UseportBchangeinterrupt
connecttheLEDstoRA0RA3
basedonthepressedkey,converttherowandcolumnvaluesto
binaryusingalookuptable
10
-
7/31/2019 09 Chapter 8 - Human Physical Interface
11/53
KeypadInterfacingExample#INCLUDE PIC16F84A.INC
ROW_INDEX EQU 0X20COL_INDEX EQU 0X21
ORG 0X0000
GOTO START
ORG 0X0004GOTO ISR
START BSF STATUS,RP0
MOVLW B11110000
MOVWF TRISB ;SETRB1RB3ASOUTPUTAND;RB4RB7ASINPUT
MOVLW B00000000
MOVWF TRISA ;SETRA0RA3ASOUTPUT
BCF STATUS,RP0
CLRF PORTB ;INITIALIZEPORTBTOZERO
MOVF PORTB,W ;CLEARRBIFFLAG
BCF INTCON,RBIF
BSF INTCON,
RBIEBSF INTCON,GIE ;ENABLEPORTbCHANGEINTERRUPT
LOOP GOTO LOOP ;WAITFORPRESSEDKEY11
-
7/31/2019 09 Chapter 8 - Human Physical Interface
12/53
KeypadInterfacingExampleISR MOVF PORTB,W ;READROWNUMBER
MOVWF ROW_INDEX
BSF STATUS,RP0 ;READCOLUMNNUMBER
MOVLW B00001110
MOVWF TRISB
BCF STATUS,RP0CLRF PORTB
MOVF PORTB,W
MOVWF COL_INDEX
CALL CONVERT ;CONVERTHEROWANDCOLUMN
RST_PB_DIRC BSF STATUS,RP0 ;PUTTHEPORTBACKTOINITIALSETTINGS
MOVLW B11110000
MOVWF TRISB ;SETRB1RB3ASOUTPUTAND
MOVLW B00000000 ;RB4RB7ASINPUT
MOVWF TRISA ;SETRA0RA3ASOUTPUT
BCF STATUS,RP0
CLRF PORTB
MOVF PORTB,W ;REQUIREDTOCLEARRBIFFLAG
BCF INTCON,RBIFRETFIE
12
-
7/31/2019 09 Chapter 8 - Human Physical Interface
13/53
KeypadInterfacingExample
CONVERT BTFSS COL_INDEX,3 ; IF 1ST COLUMN,COL_INDEX=0MOVLW 0
BTFSS COL_INDEX,2; IF2ND COLUMN,COL_INDEX=1
MOVLW 1
BTFSS COL_INDEX,1;
IF3
RD
COLUMN,COL_INDEX=2
MOVLW 2
MOVWF COL_INDEX ; STORETHECOLUMNINDEX
FIND_ROW BTFSS ROW_INDEX,7 ; IF 1ST ROW,ROW_INDEX=0
MOVLW 0
BTFSS ROW_INDEX,6 ; IF 2ND ROW,ROW_INDEX=1
MOVLW 1
BTFSS ROW_INDEX,5 ; IF 3RD ROW,ROW_INDEX=2
MOVLW 2
BTFSS ROW_INDEX,4; IF 4TH ROW,ROW_INDEX=3
MOVLW 3
MOVWF ROW_INDEX
; CONTINUEDONNEXTPAGE13
-
7/31/2019 09 Chapter 8 - Human Physical Interface
14/53
KeypadInterfacingExample
COMPUTE_VALUE MOVF ROW_INDEX,W ; KEY#=ROW_INDEX*3+COL_INDEX
ADDWF ROW_INDEX,W
ADDWF ROW_INDEX,W
ADDWF COL_INDEX,W ;THEVALUEISINW
CALL TABLE
MOVWF PORTA ;DISPLAYTHENUMBERONPORTA
RETURN
14
-
7/31/2019 09 Chapter 8 - Human Physical Interface
15/53
KeypadInterfacingExample
TABLE ADDWF PCL,F
RETLW 0X01
RETLW 0X02
RETLW 0X03RETLW 0X04
RETLW 0X05
RETLW 0X06
RETLW 0X07
RETLW 0X08
RETLW 0X09
RETLW 0X0F ;ERRORCODE
RETLW 0X00
RETLW 0X0F ;ERRORCODE
END
15
-
7/31/2019 09 Chapter 8 - Human Physical Interface
16/53
LEDDisplays
Lightemittingdiodesaresimpleandeffectiveinconveyinginformation
However,incomplex
systems
itbecomes
hard
to
deal
with
individualLEDs
Alternatives Sevensegmentdisplays
Bargraph
Dotmatrix
Starburst
16
-
7/31/2019 09 Chapter 8 - Human Physical Interface
17/53
SevenSegmentDisplay
17
-
7/31/2019 09 Chapter 8 - Human Physical Interface
18/53
SevenSegmentDisplay
Multiplexingof
seven
segment
digits
18
Connection PortBit
Segment a RB7
Segment b RB6
Segment c RB5
Segment d RB4
Segment e RB3
Segment f RB2
Segment g RB1
Segment dp RB0
Digit1drive RA0
Digit2drive RA1
Digit3drive RA2
Digit4drive RA3
-
7/31/2019 09 Chapter 8 - Human Physical Interface
19/53
SevenSegmentDisplay
Multiplexingof
seven
segment
digits
19
-
7/31/2019 09 Chapter 8 - Human Physical Interface
20/53
SevenSegmentDisplay
Example
Aprogramtocountcontinuouslythenumbers0through99
anddisplaythemontwosevensegmentdisplays.Thecount
shouldbe
incremented
every
1sec.
Oscillator
frequency
is
3
MHz.
connectthesevensegmentinputsa throughg toRB0throughRB6
respectively
connectthegatesofthecontrollingtransistorstoRA0(LSD)andRA1
(MSD) themainprogramwillberesponsiblefordisplayandmultiplexing
every5ms
20
-
7/31/2019 09 Chapter 8 - Human Physical Interface
21/53
SevenSegmentDisplayExample
#INCLUDE PICF84A.INCLOW_DIGIT EQU 0X20
HIGH_DIGIT EQU 0X21
COUNT EQU 0X22
ORG
0X0000GOTO START
ORG 0X0004
ISR GOTO ISR
START BSF STATUS,RP0
MOVLW B00000000 ;setportBasoutput
MOVWF TRISB
MOVLW B0000000
MOVWF TRISA ;SETRA0RA1ASOUTPUT
BCF STATUS,RP0
CLRF PORTB
CLRF PORTA
CLRF LOW_DIGIT ;CLEARTHECOUNTVALUE
CLRF HIGH_DIGIT
CLRF COUNT21
-
7/31/2019 09 Chapter 8 - Human Physical Interface
22/53
SevenSegmentDisplayExample
DISPLAY BCF STATUS,RP0MOVF LOW_DIGIT,W ;DISPLAYLOWERDIGIT
CALL TABLE ;GETTHESEVENSEGMENTCODE
MOVWF PORTB
BCF PORTA,1 ;enabledigit0
BSF PORTA,0
CALL DELAY_5MS ;KEEPITONFOR5MS
MOVF HIGH_DIGIT,W ;DISPLAY HIGHDIGIT
CALL TABLE ;GETTHESEVENSEGMENTCODE
MOVWF PORTBBCF PORTA,0
BSF PORTA,1
CALL DELAY_5MS ;KEEPITONFOR5MS
22
-
7/31/2019 09 Chapter 8 - Human Physical Interface
23/53
SevenSegmentDisplayExample;CHECKIF 1SECELAPSED
INCF COUNT,F ;INCREMENTTHECOUNTVALUEIFTRUE
MOVF COUNT,W
SUBLW D100
BTFSS STATUS,Z
GOTO DISPLAY ;DISPLAYTHESAMECOUNT
INCF LOW_DIGIT,F ;INCREMENTLOWDIGITANDCHECKIF>9
MOVF LOW_DIGIT,W
SUBLW 0X0ABTFSS STATUS,Z
GOTO DISPLAY
CLRF LOW_DIGIT
INCF HIGH_DIGIT,F;INCREMENTHIGHDIGITANDCHECKIF>9
MOVF HIGH_DIGIT,W
SUBLW 0X0A
BTFSS STATUS,Z
GOTO DISPLAY
CLRF HIGH_DIGIT
GOTO DISPLAY23
-
7/31/2019 09 Chapter 8 - Human Physical Interface
24/53
SevenSegmentDisplayExample
DELAY_5MS MOVLW D250
MOVWF 0X40
REPEAT NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOPNOP
DECFSZ 0X40,1
GOTO REPEAT
RETURN
24
-
7/31/2019 09 Chapter 8 - Human Physical Interface
25/53
SevenSegmentDisplayExample
TABLE ADDWF PCL, 1
RETLW B'00111111' ;'0'
RETLW B'00000110' ;'1'
RETLW B'01011011' ;'2'
RETLW B'01001111' ;'3'
RETLW B'01100110' ;'4'
RETLW B'01101101' ;'5'
RETLW B'01111101' ;'6'
RETLW B'00000111' ;'7'
RETLW B'01111111' ;'8'
RETLW B'01101111' ;'9'
END
25
-
7/31/2019 09 Chapter 8 - Human Physical Interface
26/53
Embeddedsystemsneedtointerfacewiththe
physicalworld
Mustbeabletodetectthestateofthephysical
variablesandcontrolthem
Inputtransducersorsensorsareusedtoconvertphysicalvariablesintoelectricalvariables
Lightsensors
Temperaturesensors
Outputtransducersconvertelectricalvariablesto
physical;actuators
26
Sensors
-
7/31/2019 09 Chapter 8 - Human Physical Interface
27/53
27
Sensors
The
Microswitch
-
7/31/2019 09 Chapter 8 - Human Physical Interface
28/53
Alightdependentresistor(LDR)is
madefrom
apiece
of
exposed
semiconductormaterial
Whenlightfallsonit,itcreates
holeelectronpairsinthematerial,whichimprovesthe
conductivity.
28
Sensors
Light
dependent
Resistors
Illumination(lux) RLDR (Ohms) Vo
Dark 2M 5
10 9000 2.36
1000 400 0.19
-
7/31/2019 09 Chapter 8 - Human Physical Interface
29/53
Usefulinsensingthepresenceorclosenessofobjects
Thepresenceofobjectcanbedetected
Ifitbreaksthelightbeam
Ifitreflectsthelightbeam
29
Sensors
Optical
Object
Sensing
-
7/31/2019 09 Chapter 8 - Human Physical Interface
30/53
Usefulinmeasuringdistanceandspeed
30
Sensors
Opto
sensor
as
a
Shaft
Encoder
-
7/31/2019 09 Chapter 8 - Human Physical Interface
31/53
Basedonreflectiveprincipleofultrasonicwaves
Anultrasonictransmittersendsoutaburstof
ultrasonicpulsesandthenthereceiverdetectstheecho
Ifthetimetoechoismeasured,distancecanbe
measured
31
Sensors
Ultrasonic
Object
Sensor
-
7/31/2019 09 Chapter 8 - Human Physical Interface
32/53
Embeddedsystemsneedtocausephysicalmovement
Linearorrotarymotion
Mostactuatorsareelectricalinnature
Solenoids(linearmotion)
Servomotors(rotarymotion)
DCorsteppermotors(rotarymotion)
32
Actuators:motorsandservos
-
7/31/2019 09 Chapter 8 - Human Physical Interface
33/53
33
DCMotors
Rangefrom
the
extremely
powerful
to
the
very
small
Widespeedrange
Controllablespeed
Goodefficiency Canprovideaccurateangularpositioningwithangular
shafts
Onlythearmaturewindingneedstobedriven
http://en.wikipedia.org/wiki/File:Electric_motor_cycle_1.png -
7/31/2019 09 Chapter 8 - Human Physical Interface
34/53
34
StepperMotors
Asteppermotor (orstep
motor)isasynchronouselectric
motorthatcandivideafullrotationintoalargenumberof
steps.
-
7/31/2019 09 Chapter 8 - Human Physical Interface
35/53
35
StepperMotors
Features
Simpleinterfacewithdigitalsystems
Cancontrolspeedandposition Awkwardstartupcharacteristics
Losetorqueathighspeed
Limitedtopspeed
Lessefficient
Morecomplextodrive
-
7/31/2019 09 Chapter 8 - Human Physical Interface
36/53
36
ServoMotors
Allowspreciseangular
motion
Theoutputisashaftthat
cantakeanangular
positionoverarangeof
180o
Theinputtotheservois
apulsestreamwhose
widthdeterminesthe
angularpositionofthe
shaft
-
7/31/2019 09 Chapter 8 - Human Physical Interface
37/53
37
InterfacingtoActuators
Microcontrollerscandriveloadswithsmall
electricalrequirements
Somedevices,likeactuators,requirehighcurrents
or
supply
voltages
Useswitchingdevices
SimpleDCswitchingusingBJTsorMOSFETs
ReversibleDCswitchingusingHbridge
-
7/31/2019 09 Chapter 8 - Human Physical Interface
38/53
38
InterfacingtoActuators
SimpleDC
interfacing
-
7/31/2019 09 Chapter 8 - Human Physical Interface
39/53
39
InterfacingtoActuators
SimpleDC
interfacing
Resistiveload Inductiveload
-
7/31/2019 09 Chapter 8 - Human Physical Interface
40/53
40
InterfacingtoActuators
SimpleDC
interfacing
Characteristicsoftwopopularlogiccompatible
MOSFETs
-
7/31/2019 09 Chapter 8 - Human Physical Interface
41/53
41
Interfacing to ActuatorsDrivingPiezo SounderandOptosensors
Piezo sounderratings:9mA,320V
Theoptosensorfoundtooperatewellwith91Ohmresistor.Thediode
forwardvoltageis1.7V.Therequiredcurrentisabout17.6mA
-
7/31/2019 09 Chapter 8 - Human Physical Interface
42/53
42
Interfacing to ActuatorsReversibleDCSwitching
DCswitchingallowsdrivingloadswithcurrentflowinginone
direction
Someloadsrequirestheappliedvoltagetobereversible;DC
motorsrotationdependsondirectionofcurrent
UseHbridge!
-
7/31/2019 09 Chapter 8 - Human Physical Interface
43/53
43
Interfacing to ActuatorsReversibleDCSwitching
L293D
Dual
H
bridgePeakoutputcurrent1.2Aperchannel
-
7/31/2019 09 Chapter 8 - Human Physical Interface
44/53
-
7/31/2019 09 Chapter 8 - Human Physical Interface
45/53
45
More on Digital Input
Whenacquiringdigitalinputsintothemicrocontroller,itisessentialthattheinputvoltageiswithinthe
permissibleandrecognizablerangeoftheMC
Voltagerangedependsonthelogicfamily;TTL,CMOS,
Interfacingwithinthesamefamilyissafe
Whatforthecase Interfacingtodigitalsensors
Signalcorruption
Interference
-
7/31/2019 09 Chapter 8 - Human Physical Interface
46/53
46
More on Digital Input
PIC16F873APortCharacteristics
-
7/31/2019 09 Chapter 8 - Human Physical Interface
47/53
47
More on Digital Input
FormsofSignalCorruption
Spikesinthesignal
Slowedge DCOffsetinthesignal
-
7/31/2019 09 Chapter 8 - Human Physical Interface
48/53
48
More on Digital Input
ClampingVoltageSpikes
Allportsareusuallyprotectedbyapairof
diodes
Anoptionalcurrent
limitingresistorcanbe
addedifhighspikesare
expected
IfRprot =1K andthemaximumdiodecurrentis20mAwhenVd=0.3v,thenwhatisthemaximumpositivevoltagespikethatcanbesuppressed?
-
7/31/2019 09 Chapter 8 - Human Physical Interface
49/53
49
More on Digital Input
AnalogInput
Filtering
CanuseSchmitttriggerforspeedingupslowlogicedges.
SchmitttriggerwithRCfiltercanbeusedtofiltervoltage
spikes.
-
7/31/2019 09 Chapter 8 - Human Physical Interface
50/53
50
More on Digital Input
SwitchDebouncing
Mechanicalswitchesexhibitbouncingbehavior
Theswitchcontactbouncesbetweenopenandclosed
Aseriousproblemfordigitaldevices?!
Switchdebouncing!!
hardware
and/or
software
techniques
-
7/31/2019 09 Chapter 8 - Human Physical Interface
51/53
51
More on Digital Input
SwitchDebouncing
-
7/31/2019 09 Chapter 8 - Human Physical Interface
52/53
52
More on Digital Input
SwitchDebouncing
-
7/31/2019 09 Chapter 8 - Human Physical Interface
53/53