Embedded System Input/Outputcsce.uark.edu/~ahnelson/CSCE4114/lectures/lecture9.pdfEmbedded System...

24
Embedded System Input/Output Alexander Nelson October 8, 2018 University of Arkansas - Department of Computer Science and Computer Engineering

Transcript of Embedded System Input/Outputcsce.uark.edu/~ahnelson/CSCE4114/lectures/lecture9.pdfEmbedded System...

Page 1: Embedded System Input/Outputcsce.uark.edu/~ahnelson/CSCE4114/lectures/lecture9.pdfEmbedded System Input/Output Alexander Nelson October 8, 2018 University of Arkansas - Department

Embedded System Input/Output

Alexander Nelson

October 8, 2018

University of Arkansas - Department of Computer Science and Computer Engineering

Page 2: Embedded System Input/Outputcsce.uark.edu/~ahnelson/CSCE4114/lectures/lecture9.pdfEmbedded System Input/Output Alexander Nelson October 8, 2018 University of Arkansas - Department

General Purpose Input/Output

(GPIO)

Page 3: Embedded System Input/Outputcsce.uark.edu/~ahnelson/CSCE4114/lectures/lecture9.pdfEmbedded System Input/Output Alexander Nelson October 8, 2018 University of Arkansas - Department

GPIO

General Purpose Input/Output – Digital signal pin with behavior

definable at runtime

Behavior defined by direction (input/output), enabled/disabled,

interruptible, state of output (high, low, high-impedance)

1

Page 4: Embedded System Input/Outputcsce.uark.edu/~ahnelson/CSCE4114/lectures/lecture9.pdfEmbedded System Input/Output Alexander Nelson October 8, 2018 University of Arkansas - Department

GPIO Circuitry

Not included – 7 other bits to make a port2

Page 5: Embedded System Input/Outputcsce.uark.edu/~ahnelson/CSCE4114/lectures/lecture9.pdfEmbedded System Input/Output Alexander Nelson October 8, 2018 University of Arkansas - Department

GPIO – Output

GPIO Output Circuitry:

Two flip flops

Three tri-state buffers

DDxn – Direction of Port

(input/output)

PORTXn – Digital value of

Pin (0/1)

3

Page 6: Embedded System Input/Outputcsce.uark.edu/~ahnelson/CSCE4114/lectures/lecture9.pdfEmbedded System Input/Output Alexander Nelson October 8, 2018 University of Arkansas - Department

GPIO – Input

GPIO Input Circuitry:

Two flip flops

Four tri-state buffers

Schmitt Trigger (denoise

input)

Pull-up resistor (activated by

PORTxn high)

4

Page 7: Embedded System Input/Outputcsce.uark.edu/~ahnelson/CSCE4114/lectures/lecture9.pdfEmbedded System Input/Output Alexander Nelson October 8, 2018 University of Arkansas - Department

GPIO Circuitry

GPIO Circuity: Input/Ouput

Power Up/Down

Sleep

Clock synchronization

Fast Bit twiddling

5

Page 8: Embedded System Input/Outputcsce.uark.edu/~ahnelson/CSCE4114/lectures/lecture9.pdfEmbedded System Input/Output Alexander Nelson October 8, 2018 University of Arkansas - Department

Simplicity from Complexity

The circuitry provides a clean interface for digtally reading/writing

individual pins

In Atmel, these pins can be addressed at memory-mapped registers

PORTx, PINx, DDxn

MSP430 has PxDIR, PxIN, PxOUT, PxSEL

Arduino has PinMode, digitalWrite, digitalRead

6

Page 9: Embedded System Input/Outputcsce.uark.edu/~ahnelson/CSCE4114/lectures/lecture9.pdfEmbedded System Input/Output Alexander Nelson October 8, 2018 University of Arkansas - Department

Debouncing

Imperfect contact can create “glitches”

Use delays to verify signal is steady5

Page 10: Embedded System Input/Outputcsce.uark.edu/~ahnelson/CSCE4114/lectures/lecture9.pdfEmbedded System Input/Output Alexander Nelson October 8, 2018 University of Arkansas - Department

Measurement Circuits

Sensor manufacturers create elements that have a predictable

response to a stimulus

These responses modulate a quantity that can be sampled by a

digital system

Typical quantities:

• Resistance

• Capacitance

• Inductance

10

Page 11: Embedded System Input/Outputcsce.uark.edu/~ahnelson/CSCE4114/lectures/lecture9.pdfEmbedded System Input/Output Alexander Nelson October 8, 2018 University of Arkansas - Department

Analog to Digital – Voltage Divider

Resistor Sensors – Thermometers, Photoresistors, Force sensors,

etc...

Measure resistance through two known quantities

Derived from Ohm’s Law (w/ assumptions)

11

Page 12: Embedded System Input/Outputcsce.uark.edu/~ahnelson/CSCE4114/lectures/lecture9.pdfEmbedded System Input/Output Alexander Nelson October 8, 2018 University of Arkansas - Department

Analog to Digital – Wheatstone Bridge

Wheatstone Bridge – Voltage Measurement

Can allow differential measurement, non absolute references, and

can be extremely precise

12

Page 13: Embedded System Input/Outputcsce.uark.edu/~ahnelson/CSCE4114/lectures/lecture9.pdfEmbedded System Input/Output Alexander Nelson October 8, 2018 University of Arkansas - Department

Analog to Digital – Capacitance Measurement

13

Page 14: Embedded System Input/Outputcsce.uark.edu/~ahnelson/CSCE4114/lectures/lecture9.pdfEmbedded System Input/Output Alexander Nelson October 8, 2018 University of Arkansas - Department

Analog to Digital – Capacitance Measurement

Capacitance can be measured by the voltage change over time

14

Page 15: Embedded System Input/Outputcsce.uark.edu/~ahnelson/CSCE4114/lectures/lecture9.pdfEmbedded System Input/Output Alexander Nelson October 8, 2018 University of Arkansas - Department

Parallel Interfaces

Parallel Interface – Many binary signals to represent word-length

values

D0-D7 represent a single byte to be transferred

15

Page 16: Embedded System Input/Outputcsce.uark.edu/~ahnelson/CSCE4114/lectures/lecture9.pdfEmbedded System Input/Output Alexander Nelson October 8, 2018 University of Arkansas - Department

Serial Interfaces

Series – a number of things coming one after another

Serial Interface – Bits transferred one after another

16

Page 17: Embedded System Input/Outputcsce.uark.edu/~ahnelson/CSCE4114/lectures/lecture9.pdfEmbedded System Input/Output Alexander Nelson October 8, 2018 University of Arkansas - Department

Serial Interfaces – UART

UART – Universal Asynchronous Receiver-Transmitter

Asynchronous – No shared clock

Data transfer is unidirectional

Transmission Speed – Usually given in baud (bits per second)

Receiver & transmitter have foreknowledge of transmission speed

Data frame – Data transferred byte-by-byte

Each frame is bordered by start & stop bit(s)

17

Page 18: Embedded System Input/Outputcsce.uark.edu/~ahnelson/CSCE4114/lectures/lecture9.pdfEmbedded System Input/Output Alexander Nelson October 8, 2018 University of Arkansas - Department

Serial Interfaces – SPI

SPI – Serial Peripheral Interface

Synchronous unidirectional master–slave data transfer

Master device configures clock, clock polarity, and when

communication occurs

Data frame – Frame started by a logic 0 on the Source Select line

Determines which slave device is to listen

Data is transferred bit-by-bit, latched at either rising or falling

edges

18

Page 19: Embedded System Input/Outputcsce.uark.edu/~ahnelson/CSCE4114/lectures/lecture9.pdfEmbedded System Input/Output Alexander Nelson October 8, 2018 University of Arkansas - Department

Serial Interfaces – SPI

2

SPI Timing Diagram

2https://en.wikipedia.org/wiki/Serial Perip-

heral Interface Bus#/media/File:SPI timing diagram2.svg

19

Page 20: Embedded System Input/Outputcsce.uark.edu/~ahnelson/CSCE4114/lectures/lecture9.pdfEmbedded System Input/Output Alexander Nelson October 8, 2018 University of Arkansas - Department

Serial Interfaces – I2C

I2C – Inter-Integrated Circuit (I-squared-C)

Address-based 2-wire communication interface

20

Page 21: Embedded System Input/Outputcsce.uark.edu/~ahnelson/CSCE4114/lectures/lecture9.pdfEmbedded System Input/Output Alexander Nelson October 8, 2018 University of Arkansas - Department

Serial Interfaces – I2C – Data Transfer

1. Data transfer initiated(S) – SDA pulled low, SCL stays high.

2. SCL is pulled low, and SDA sets the first data bit level while

keeping SCL low (during blue bar time).

3. The data are sampled (received) when SCL rises for the first

bit (B1). For a bit to be valid, SDA must not change between

a rising edge of SCL and the subsequent falling edge.

4. This process repeats, SDA transitioning while SCL is low, and

the data being read while SCL is high (B2, ...Bn).

5. The final bit is followed by a clock pulse, during which SDA is

pulled low in preparation for the stop bit.

6. Stop bit (P) signaled when SCL rises, followed by SDA rising 21

Page 22: Embedded System Input/Outputcsce.uark.edu/~ahnelson/CSCE4114/lectures/lecture9.pdfEmbedded System Input/Output Alexander Nelson October 8, 2018 University of Arkansas - Department

Serial Interfaces – I2C – Addresses

I2C has only 2 data lines

Uses addresses to specify which chip listens

Address is 7 bits followed by a write bit

Write bit specifies if action is to read or write at register address

22

Page 23: Embedded System Input/Outputcsce.uark.edu/~ahnelson/CSCE4114/lectures/lecture9.pdfEmbedded System Input/Output Alexander Nelson October 8, 2018 University of Arkansas - Department

Pulse Width Modulation

Pulse Width Modulation – Encoding message through pulsing

signal

3

3By Zureks - Own work, CC BY-SA 3.0,

https://commons.wikimedia.org/w/index.php?curid=1835361

23

Page 24: Embedded System Input/Outputcsce.uark.edu/~ahnelson/CSCE4114/lectures/lecture9.pdfEmbedded System Input/Output Alexander Nelson October 8, 2018 University of Arkansas - Department

Pulse Width Modulation

Applications of PWM:

• Sensor output

• Servo Input

• LED dimming

• Power Delivery

24