U of U ECE 3720 - Lecture 5 - Interfacing Methods
Pages 14

Unformatted text preview:

Slide 1'&$%ECE/CE 3720: Embedded System DesignChris J. MyersLecture 5: Interfacing MethodsSlide 2'&$%Introduction1. Embedded systems often have many special I/O devices,so I/O interfacing is a critical task.2. I/O interfacing include both physical connections andsoftware routines that affect information exchange.3. Chapter 3 introduces basic interfacing methods.1Slide 3'&$%Performance Measures1. Latency is the delay from when an I/O device needsservice until the service is initiated.2. It includes both hardware and software delays.3. A real-time systems guarantees a worst-case latency.4. Throughput or bandwidth is maximum rate data can beprocessed by the system.5. Can be limited by I/O device or the software.6. Priority determines order of service when two or morerequests are made at the same time.7. Soft real time system is one that supports priority.Slide 4'&$%Synchronizing the Software with the State of the I/O1. Hardware is in 1 of 3 states: idle, busy, or done.2. When working, device alternates between busy and done.3. I/O devices usually much slower than software, sosynchronization is required for proper transmission.4. When an I/O device is slower than software, it is I/Obound, otherwise it is CPU bound.5. Interface can be buffered or unbuffered.2Slide 5'&$%Synchronizing Software with an Input Device(See Figures 3.1 and 3.2)Slide 6'&$%Synchronizing Software with an Output Device(See Figures 3.3 and 3.4)3Slide 7'&$%Synchronization Mechanisms1. Blind cycle - software simply waits a fixed amount oftime for the I/O to complete.2. Gadfly or busy waiting - software loops checking the I/Ostatus waiting for the done state.3. Interrupt - I/O device causes special software executionwhen it requires service.4. Periodic polling - clock interrupt periodically checks I/Ostatus.5. Direct memory access - I/O device directly transfers datato/from memory.Slide 8'&$%Parallel I/O Control Register (PIOC)• STAF - Strobe A Flag• STAI - Strobe A Interrupt Enable Bit• CWOM - Port C Wired-OR Mode Bit• HNDS - Handshake/Simple Strobe Mode Select Bit• OIN - Output/Input Handshake Select Bit• PLS - Strobe B Pulse Mode Select Bit• EGA - Edge Select for Strobe A Bit• INVB - Invert Strobe B Bit4Slide 9'&$%Blind Cycle Printer Interface(See Figures 3.11 and 3.12)Slide 10'&$%Idealized Timing for Strobe OutputINVB=1, PIOC=$015Slide 11'&$%Initialize and Output to a Printervoid Init(void){PIOC=0x00;}void Out(unsigned char value){unsigned int n;PORTB=value;for(n=0;n<2857;n++);}--------------------------Init clr PIOCrtsOut staa PORTBldd #2857 ;wait 10msOLoop subd #1bne OLooprtsSlide 12'&$%Accurate Time Delays• Counting cycles is tedious and must be redone when:– Software algorithm changes– Computer speed changes– Computer is upgraded– Compiler is upgraded• It is inaccurate when interrupts can occur.• 68HC11 includes fixed rate 16-bit counter, TCNT.• Operates correctly in presence of overflow.6Slide 13'&$%Accurate Time Delaysvoid Wait(short numCycles){short EndT; // TCNT at the end of the delayEndT=TCNT+numCycles;while(EndT-(short)TCNT>0);}---------------------------------------; Reg D is the number of cycles to wait; can range from 25 to 32767Wait addd TCNT time at the end of delayLoop cpd TCNT wait for Endt-TCNT>0bpl LooprtsSlide 14'&$%Blind Cycle ADC Interface(See Figures 3.13 and 3.14)7Slide 15'&$%Initialize and Read from an ADCvoid Init(void){PIOC=0x01; // GO=STRBDDRC=0;} // PORTC is dataunsigned char In(void){ int n;PORTB=value; // GO pulsefor(n=0;n<1;n++);return(PORTC);}------------------------Init ldaa #$01 ;INVB=1staa PIOCclr DDRCrtsIn staa PORTB ;GO pulsemul ;[10]ldaa PORTCrtsSlide 16'&$%Gadfly or Busy Waiting Synchronization(See Figures 3.7 and 3.8)8Slide 17'&$%Multiple Gadfly Outputs(See Figure 3.9)Slide 18'&$%Multiple Gadfly Inputs and Outputs(See Figure 3.10)9Slide 19'&$%Gadfly Keyboard Interface Using Latched Input(See Figures 3.15 and 3.16)Slide 20'&$%Idealized Timing for Latched InputEGA=1, PIOC=$0210Slide 21'&$%Initialize and Read from a Keyboardvoid Init(void){// PC6-0 is DATAunsigned char dummy;PIOC=0x02; // EGA=1DDRC=0x80; // STRA=STROBEPORTC=0x00; // PC7=0dummy=PIOC;dummy=PORTCL;}unsigned char In(void){while ((PIOC & STAF) == 0);return(PORTCL); }Slide 22'&$%Initialize and Read from a Keyboard; PortC=DATA, STRA=STROBEInit ldaa #$02 ;EGA=1staa PIOCldaa #$80 ;PC7=outputstaa DDRCldaa PIOC ;STAF=0ldaa PORTCLclr PORTC ;PC7=0rtsIn ldaa PIOC ; wait for STAFbpl Inldaa PORTCLrts11Slide 23'&$%Gadfly ADC Interface Using Simple Input(See Figures 3.17 and 3.18)Slide 24'&$%Initialize and Read from an ADCvoid Init(void){// PortC=DATA STRA=DONE STRB=GOunsigned char dummy;PIOC=0x03; // EGA=1 INVB=1DDRC=0x00; // PC inputsdummy=PIOC;dummy=PORTCL;} // clear STAFunsigned char In(void){PORTB=0; // GO pulsewhile ((PIOC & STAF) == 0);return(PORTCL); }12Slide 25'&$%Initialize and Read from an ADCInit ldaa #$03 ;EGA=1, INVB=1staa PIOCldaa #$00 ;PC=inputstaa DDRCldaa PIOC ;STAF=0ldaa PORTCLrtsIn staa PORTB ;GO pulseloop ldaa PIOC ;wait for STAFbita #$80beq loopldaa PORTCLrtsSlide 26'&$%Gadfly External Sensor Interface Using InputHandshake(See Figures 3.19 and 3.20)13Slide 27'&$%Idealized Timing for Full-Input HandshakeHNDS=1, OIN=1, PLS=0/1, EGA=1, INVB=1, PIOC=$13/$17Slide 28'&$%Initialize and Read from a Sensorvoid Init(void){// PortC=DATA STRA=READY STRB=ACKunsigned char dummy;PIOC=0x13; // EGA=1 INVB=1DDRC=0x00; // PC inputsdummy=PIOC;dummy=PORTCL;} // clear STAFunsigned char In(void){while ((PIOC & STAF) == 0);return(PORTCL); }14Slide 29'&$%Comment for PIOC Register; PortC ritual, Set PC7-PC0 inputs = sensor DATA; PIOC ($1002); 7 STAF Read Only Set on rise of STRA; 6 STAI 0 Gadfly, no interrupts; 5 CWOM 0 Normal outputs; 4 HNDS 1 Input handshake; 3 OIN 0; 2 PLS 0 ACK=STRB goes to 0 on rise of READY; 1 EGA 1 STAF set on rise of READY=STRA; 0 INVB 1 ACK=STRB goes to 1 on a ReadCL; STRB=ACK status 0 means busy,1 means done; STRA=READY rising edge when new data is readySlide 30'&$%Initialize and Read from a Sensor; PortC=DATA STRA=READY STRB=ACKInit ldaa #$13 ;Input hndshakestaa PIOCldaa #$00 ;PC=inputstaa DDRCldaa PIOC ;STAF=0ldaa PORTCLrtsIn ldaa PIOC ;wait for STAFbita #$80beq loopldaa PORTCL ;read DATArts15Slide 31'&$%Gadfly Printer Interface Using Output Handshake(See Figures 3.21 and 3.22)Slide 32'&$%Idealized Timing for Full-Output HandshakeHNDS=1, OIN=1, PLS=0/1, EGA=1, INVB=1, PIOC=$1B/$1F16Slide 33'&$%Initialize and Write to a Printervoid Init(void){// PortC=DATA STRA=READY


View Full Document

U of U ECE 3720 - Lecture 5 - Interfacing Methods

Course: Ece 3720-
Pages: 14
Download Lecture 5 - Interfacing Methods
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view Lecture 5 - Interfacing Methods and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Lecture 5 - Interfacing Methods 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?