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

Post on 19-Mar-2020

26 views 0 download

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

Embedded System Input/Output

Alexander Nelson

October 8, 2018

University of Arkansas - Department of Computer Science and Computer Engineering

General Purpose Input/Output

(GPIO)

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

GPIO Circuitry

Not included – 7 other bits to make a port2

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

GPIO – Input

GPIO Input Circuitry:

Two flip flops

Four tri-state buffers

Schmitt Trigger (denoise

input)

Pull-up resistor (activated by

PORTxn high)

4

GPIO Circuitry

GPIO Circuity: Input/Ouput

Power Up/Down

Sleep

Clock synchronization

Fast Bit twiddling

5

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

Debouncing

Imperfect contact can create “glitches”

Use delays to verify signal is steady5

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

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

Analog to Digital – Wheatstone Bridge

Wheatstone Bridge – Voltage Measurement

Can allow differential measurement, non absolute references, and

can be extremely precise

12

Analog to Digital – Capacitance Measurement

13

Analog to Digital – Capacitance Measurement

Capacitance can be measured by the voltage change over time

14

Parallel Interfaces

Parallel Interface – Many binary signals to represent word-length

values

D0-D7 represent a single byte to be transferred

15

Serial Interfaces

Series – a number of things coming one after another

Serial Interface – Bits transferred one after another

16

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

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

Serial Interfaces – SPI

2

SPI Timing Diagram

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

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

19

Serial Interfaces – I2C

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

Address-based 2-wire communication interface

20

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

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

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

Pulse Width Modulation

Applications of PWM:

• Sensor output

• Servo Input

• LED dimming

• Power Delivery

24