the human and physical interface - ucoz · the human and physical interface. outline y introduction...
TRANSCRIPT
Chapter 8Sections 1 ‐ 9
Dr. Iyad Jafar
The Human and Physical Interface
Outline
Introduction
From Switches to Keypads
LED Displays
Simple Sensors
Actuators
Summary
2
IntroductionHumans need to interface with embedded systems ; input data and see response Input devices: switches, pushbuttons, keypads, sensors Output devices: LEDs, seven‐segment displays, liquid crystal displays, motors, actuators
3
Embedded Computer Hardware
Software Input
VariablesOutput Variables
Link to other systems
User Interaction
IntroductionExamples
Fridge Control Panel
Photocopier Control Panel 4
IntroductionExamples
Car Dashboard
5
Moving From Switches to KeypadsSwitches are good for conveying information of digital natureThey can be used in multiples; each connected to one port pinIn complex systems, it might not be feasible to keep addingswitches ?!Use keypads !
Can be used to convey alphanumeric values A group of switches arranged in matrix form
6
Moving From Switches to KeypadsInternal Structure of Keypad
7
Moving From Switches to KeypadsHow to Determine the Pressed Key
8
Moving From Switches to KeypadsUsing Keypad in a Microcontroller
9
Moving From Switches to KeypadsExample 1
A program to read an input from a 4x3 keypad and display the equivalent decimal number on 4 LEDs. If the pressed key is not a number, then all LEDs are turned on.
• The keypad will be connected to MC as follows • Rows 0 to 3 connected to RB7 to RB4, respectively. • Columns 0 to 2 connected to RB3 to RB1, respectively.
• Use PORTB on‐change interrupt • Connect the LEDs to RA0‐RA3• Based on the pressed key, convert the row and column values to binary using a lookup table
10
Keypad Interfacing Example#include P16F84A.INC
ROW_INDEX EQU 0X20COL_INDEX EQU 0X21
ORG 0X0000GOTO STARTORG 0X0004GOTO ISR
START BSF STATUS, RP0MOVLW B’11110000’MOVWF TRISB ; SET RB1‐RB3 AS OUTPUT AND
; RB4‐RB7 AS INPUTMOVLW B’00000000’ MOVWF TRISA ; SET RA0‐RA3 AS OUTPUT BCF STATUS, RP0CLRF PORTB ; INITIALIZE PORTB TO ZEROMOVF PORTB,W ; CLEAR RBIF FLAGBCF INTCON, RBIF BSF INTCON, RBIEBSF INTCON, GIE ; ENABLE PORT b CHANGE INTERRUPT
LOOP GOTO LOOP ; WAIT FOR PRESSED KEY11
Keypad Interfacing ExampleISR MOVF PORTB, W ; READ ROW NUMBER
MOVWF ROW_INDEXBSF STATUS, RP0 ; READ COLUMN NUMBERMOVLW B’00001110’MOVWF TRISBBCF STATUS, RP0CLRF PORTBMOVF PORTB, WMOVWF COL_INDEXCALL CONVERT ; CONVER THE ROW AND COLUMN
RST_PB_DIRC BSF STATUS, RP0 ; PUT THE PORT BACK TO INITIAL SETTINGSMOVLW B’11110000’MOVWF TRISB ; SET RB1‐RB3 AS OUTPUT AND MOVLW B’00000000’ ; RB4‐RB7 AS INPUTMOVWF TRISA ; SET RA0‐RA3 AS OUTPUT BCF STATUS, RP0CLRF PORTBMOVF PORTB, W ; REQUIRED TO CLEAR RBIF FLAGBCF INTCON, RBIFRETFIE
12
Keypad Interfacing ExampleCONVERT BTFSS COL_INDEX,3 ; IF 1ST COLUMN, COL_INDEX=0
MOVLW 0BTFSS COL_INDEX,2 ; IF 2ND COLUMN, COL_INDEX=1MOVLW 1BTFSS COL_INDEX,1 ; IF 3RD COLUMN, COL_INDEX=2MOVLW 2MOVWF COL_INDEX ; STORE THE COLUMN INDEX
FIND_ROW BTFSS ROW_INDEX,7 ; IF 1ST ROW, ROW_INDEX=0MOVLW 0BTFSS ROW_INDEX,6 ; IF 2ND ROW, ROW_INDEX=1MOVLW 1BTFSS ROW_INDEX,5 ; IF 3RD ROW, ROW_INDEX=2MOVLW 2BTFSS ROW_INDEX,4 ; IF 4TH ROW, ROW_INDEX=3MOVLW 3MOVWF ROW_INDEX
; CONTINUED ON NEXT PAGE13
Keypad Interfacing ExampleCOMPUTE_VALUE MOVF ROW_INDEX, W ; KEY # = ROW_INDEX*3 + COL_INDEX
ADDWF ROW_INDEX, WADDWF ROW_INDEX, WADDWF COL_INDEX, W ; THE VALUE IS IN W
; CHECK IF VALUE IS GREATER THAN 11. THIS HAPPENS WHEN THE BUTTON IS RELEASED ; LATER, AN INTERRUPT OCCURS WITH ALL SWITCHES OPEN, SO THE MAPPED VALUE IS ; ; ABOVE 11
MOVWF 0X30 ; COPY THE BUTTON NUMBER MOVLW 0X0CSUBWF 0X30,W BTFSC STATUS, C ; WILL NOT WORK CORRECTLY, OVERFLOW OCCURS
GOTO LLMOVF 0X30, WCALL TABLEMOVWF PORTA ; DISPLAY THE NUMBER ON PORTA
LL RETURN
14
Keypad Interfacing ExampleTABLE ADDWF PCL, F
RETLW 0X01RETLW 0X02RETLW 0X03RETLW 0X04RETLW 0X05RETLW 0X06RETLW 0X07RETLW 0X08RETLW 0X09RETLW 0X0F ; ERROR CODERETLW 0X00RETLW 0X0F ; ERROR CODE
END
15
LED DisplaysLight emitting diodes are simple and effective in conveying information
However, in complex systems it becomes hard to deal with individual LEDs
Alternatives Seven segment displays BargraphDot matrix Star‐burst
16
Seven Segment Display
17
Seven Segment DisplayMultiplexing of seven segment digits
18
Connection Port Bit
Segment a RB7
Segment b RB6
Segment c RB5
Segment d RB4
Segment e RB3
Segment f RB2
Segment g RB1
Segment dp RB0
Digit 1 drive RA0
Digit 2 drive RA1
Digit 3 drive RA2
Digit 4 drive RA3
Seven Segment DisplayMultiplexing of seven segment digits
19
Seven Segment DisplayExample 2
A program to count continuously the numbers 0 through 99and display them on two seven segment displays. The countshould be incremented every 1 sec. Oscillator frequency is 3MHz.
Connect the seven segment inputs a through g to RB0through RB6, respectively
Connect the gates of the controlling transistors to RA0 (LSD)and RA1 (MSD)
The main program will be responsible for display andmultiplexing every 5 ms
20
Seven Segment Display Example#INCLUDE PICF84A.INC
LOW_DIGIT EQU 0X20HIGH_DIGIT EQU 0X21COUNT EQU 0X22
ORG 0X0000GOTO STARTORG 0X0004
ISR GOTO ISRSTART BSF STATUS, RP0
MOVLW B’00000000’ ; set port B as output MOVWF TRISBMOVWF TRISA ; SET RA0‐RA1 AS OUTPUT BCF STATUS, RP0CLRF PORTBCLRF PORTACLRF LOW_DIGIT ; CLEAR THE COUNT VALUE CLRF HIGH_DIGITCLRF COUNT
21
Seven Segment Display ExampleDISPLAY BSF PORTA , 0
BCF PORTA, 1MOVF LOW_DIGIT, W ; DISPLAY LOWER DIGIT CALL TABLE ; GET THE SEVEN SEGMENT CODEMOVWF PORTBCALL DELAY_5MS ; KEEP IT ON FOR 5 MSBCF PORTA, 0BSF PORTA, 1MOVF HIGH_DIGIT, W ; DISPLAY HIGH DIGIT CALL TABLE ; GET THE SEVEN SEGMENT CODE\MOVWF PORTBCALL DELAY_5MS ; KEEP IT ON FOR 5 MS; CHECK IF 1 SEC ELAPSED INCF COUNT,F ; INCREMENT THE COUNT VALUE IF TRUE
MOVF COUNT, WSUBLW D’100’BTFSS STATUS, ZGOTO DISPLAY ; DISPLAY THE SAME COUNT
22
Seven Segment Display Example; TIME TO INCREMENT THE COUNTCLRF COUNTINCF LOW_DIGIT, F ; INCREMENT LOW DIGIT AND CHECK IF > 9
MOVF LOW_DIGIT, WSUBLW 0X0ABTFSS STATUS, ZGOTO DISPLAYCLRF LOW_DIGIT
INCF HIGH_DIGIT, F ; INCREMENT HIGH DIGIT AND CHECK IF > 9
MOVF HIGH_DIGIT, WSUBLW 0X0ABTFSS STATUS, ZGOTO DISPLAYCLRF HIGH_DIGITGOTO DISPLAY
23
Seven Segment Display ExampleDELAY_5MS MOVLW D’250’
MOVWF 0X40REPEAT NOP
NOPNOPNOPNOPNOPNOPNOPNOPNOPNOPNOPDECFSZ 0X40,1GOTO REPEATRETURN
24
Seven Segment Display Example
TABLE ADDWF PCL, 1RETLW 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
Embedded systems need to interface with thephysical world and must be able to detect thestate of the physical variables and control them
Input transducers or sensors are used to convertphysical variables into electrical variables.Examples are the light, temperature and pressuresensors
Output transducers convert electrical variables tophysical variables.
26
Sensors
A light‐dependent resistor (LDR) ismade from a piece of exposedsemiconductor materialWhen light falls on it, it createshole–electron pairs in thematerial, which improves theconductivity.
27
SensorsLight‐dependent Resistors
Illumination (lux) RLDR (Ohms) Vo
Dark 2M 5
10 9000 2.36
1000 400 0.19
Useful in sensing the presence or closeness of objectsThe presence of object can be detectedIf it breaks the light beamIf it reflects the light beam
28
SensorsOptical Object Sensing
Useful in measuring distance and speed
29
SensorsOpto‐sensor as a Shaft Encoder
Based on reflective principle of ultrasonic wavesAn ultrasonic transmitter sends out a burst ofultrasonic pulses and then the receiver detects theechoIf the time‐to‐echo is measured, distance can bemeasured
30
SensorsUltrasonic Object Sensor
Embedded systems need to cause physical movement Linear or rotary motion Most actuators are electrical in natureSolenoids (linear motion) DC MotorsStepper motors Servo motors
31
Actuators: motors and servos
32
DC MotorsRange from the extremely powerful to the very smallWide speed rangeControllable speedGood efficiencyCan provide accurate angular positioning with angular shaftsOnly the armature winding needs to be driven
33
Stepper MotorsA stepper motor (or step motor) is a synchronous electricmotor that can divide a full rotation into a large number ofsteps.
34
Stepper MotorsFeatures Simple interface with digital systemsCan control speed and positionMore complex to driveAwkward start‐up characteristicsLose torque at high speedLimited top speedLess efficient
35
Servo MotorsAllows precise angularmotion
The output is a shaft thatcan take an angularposition over a range of180o
The input to the servo isa pulse stream whosewidth determines theangular position of theshaft
36
Interfacing to Actuators
Microcontrollers can drive loads with smallelectrical requirements
Some devices, like actuators, require high currentsor supply voltages
Use switching devicesSimple DC switching using BJTs or MOSFETsReversible DC switching using H‐bridge
37
Interfacing to Actuators Simple DC interfacing
38
Interfacing to Actuators Simple DC interfacing
Resistive load Inductive load
39
Interfacing to Actuators Simple DC interfacing
Characteristics of two popular logic‐compatible MOSFETs
40
Interfacing to Actuators Driving Piezo Sounder and Opto‐sensors
Piezo sounder ratings: 9mA, 3‐20 VThe opto‐sensor found to operate well with 91 Ohm resistor. The diode forward voltage is 1.7V. The required current is about 17.6 mA
41
Interfacing to Actuators Reversible DC Switching
DC switching allows driving loads with current flowing in onedirectionSome loads requires the applied voltage to be reversible; DCmotors rotation depends on direction of currentUse H‐bridge !
42
Interfacing to Actuators Reversible DC Switching
L293D Dual H‐bridgePeak output current 1.2 A per channel
43
Interfacing to Actuators Reversible DC Switching
Driving three motors using L293D
44
More on Digital InputWhen acquiring digital inputs into the microcontroller,it is essential that the input voltage is within thepermissible and recognizable range of the MC
Voltage range depends on the logic family; TTL, CMOS,…Interfacing within the same family is safe
What for the caseInterfacing to digital sensorsSignal corruptionInterference
45
More on Digital InputPIC16F873A Port Characteristics
46
More on Digital InputForms of Signal Corruption
Spikes in the signal
Slow edge DC Offset in the signal
47
More on Digital InputClamping Voltage Spikes
• All ports are usuallyprotected by a pair ofdiodes
• An optional currentlimiting resistor can beadded if high spikes areexpected
Question? Let Rprot = 1KΩ and the maximum diode current is 20 mA whenVd = 0.3v, then what is the maximum positive voltage spike that can besuppressed?
48
More on Digital InputAnalog Input Filtering
Can use Schmitt trigger for speeding up slow logic edges.Schmitt trigger with RC filter can be used to filter voltage spikes.
49
More on Digital InputSwitch Debouncing
• Mechanical switches exhibit bouncing behavior • The switch contact bounces between open and closed • A serious problem for digital devices ?!
• Switch debouncing!! hardware and/or software techniques
50
More on Digital InputSwitch Debouncing
51
More on Digital InputSwitch Debouncing
Summary
Microcontrollers must be able to interface with thephysical world and possibly the human world
Switches, keypads and displays represent typical examplesfor interfacing embedded systems with the humans
Microcontrollers must be able to interface with a range ofinput and output transducers.
Interfacing with sensors requires a reasonable knowledgeof signal conditioning techniques
Interfacing with actuators requires a reasonableknowledge of power switching techniques
52