Sie sind auf Seite 1von 32

Embedded System Design

(Fall 2011)

Lecture 15
Osman Hasan

LCD Controller

Liquid Crystal Display: For text and images


Low cost Low power

Very commonly used in embedded systems (watches, fax and copy machines, calculators etc.)
Original source: Embedded Systems Design: A Unified Hardware/Software Introduction, (c) 2000 Vahid/Givargis Modified by: Osman Hasan, Assist. Prof., SEECS, NUST, Islamabad, Pakistan.

LCD Principle
Reflective LCD
Incoming light passes through a polarizing plate The polarized light encounters liquid crystal material If a region is excited, it allows the light to pass Light that has passed through hits a mirror and reflects back
The excited region appears to light up

Absorption LCD
Uses a black surface instead of a mirror The surface below the excited region appears darker than others
Original source: Embedded Systems Design: A Unified Hardware/Software Introduction, (c) 2000 Vahid/Givargis Modified by: Osman Hasan, Assist. Prof., SEECS, NUST, Islamabad, Pakistan.

LCD Types
7-Segment LCD
Each one of the seven segments can be activated
7 inputs Or 4 inputs to represent numbers 0 through 9

The LCD driver converts these inputs to the electrical signals necessary to excite the appropriate LCD segments

Dot-matrix LCD
Matrix of dots that can display alphanumeric characters as well as other symbols 5 columns and 8 rows for one character Again LCD driver is used to excite the appropriate LCD dots
Original source: Embedded Systems Design: A Unified Hardware/Software Introduction, (c) 2000 Vahid/Givargis Modified by: Osman Hasan, Assist. Prof., SEECS, NUST, Islamabad, Pakistan.

LCD controller
Provides interface from the Micrcontroller to the LCD
Control Words
Initialize the LCD Clear the Display Select the position of the cursor Brighten the Display

Data Words
ASCII character to be displayed at the current location

Original source: Embedded Systems Design: A Unified Hardware/Software Introduction, (c) 2000 Vahid/Givargis Modified by: Osman Hasan, Assist. Prof., SEECS, NUST, Islamabad, Pakistan.

LCD Controller
E R/W RS DB7 DB0 LCD controller communications bus

microcontroller

RS: low for control words, high for data words E bit is toggled whenever data or control words are sent
Original source: Embedded Systems Design: A Unified Hardware/Software Introduction, (c) 2000 Vahid/Givargis Modified by: Osman Hasan, Assist. Prof., SEECS, NUST, Islamabad, Pakistan.

LCD Controller: Control Words


RS 0 0 0 R/W 0 0 0 DB7 0 0 0 DB6 0 0 0 DB5 0 0 0 DB4 0 0 0 DB3 0 0 0 DB2 0 0 1 DB1 0 1 I/D DB0 1 * S Description

Clears all display, return cursor home Returns cursor home Sets cursor move direction and/or specifies not to shift display ON/OFF of all display(D), cursor ON/OFF (C), and blink position (B) Move cursor and shifts display Sets interface data length, number of display lines, and character font Writes Data
7

S/C

R/L

DL

WRITE DATA

Original source: Embedded Systems Design: A Unified Hardware/Software Introduction, (c) 2000 Vahid/Givargis Modified by: Osman Hasan, Assist. Prof., SEECS, NUST, Islamabad, Pakistan.

LCD Controller
CODES I/D = 1 cursor moves left I/D = 0 cursor moves right S = 1 with display shift S/C =1 display shift S/C = 0 cursor movement R/L = 1 shift to right R/L = 0 shift to left DL = 1 8-bit DL = 0 4-bit N = 1 2 rows N = 0 1 row F = 1 5x10 dots F = 0 5x7 dots

Original source: Embedded Systems Design: A Unified Hardware/Software Introduction, (c) 2000 Vahid/Givargis Modified by: Osman Hasan, Assist. Prof., SEECS, NUST, Islamabad, Pakistan.

Keypad
Set of buttons that may be pressed to provide input to an embedded system Very commonly used

N-column by M-row grid


N outputs: corresponding to the columns M outputs: corresponding to the rows

Original source: Embedded Systems Design: A Unified Hardware/Software Introduction, (c) 2000 Vahid/Givargis Modified by: Osman Hasan, Assist. Prof., SEECS, NUST, Islamabad, Pakistan.

Keypad controller
N1 N2 N3 N4 M1 M2 M3 M4 key_code

k_pressed

4 key_code

keypad controller

N=4, M=4

Original source: Embedded Systems Design: A Unified Hardware/Software Introduction, (c) 2000 Vahid/Givargis Modified by: Osman Hasan, Assist. Prof., SEECS, NUST, Islamabad, Pakistan.

10

Keypad controller
Software that scans the column and row outputs When a button is pressed the controller stores its code into a register key_code It sets an output k_pressed high indicating that a button has been pressed The software polls this output every 100 ms or so and reads the register when it is high
Other option instead of polling?
Using an interrupt

Original source: Embedded Systems Design: A Unified Hardware/Software Introduction, (c) 2000 Vahid/Givargis Modified by: Osman Hasan, Assist. Prof., SEECS, NUST, Islamabad, Pakistan.

11

Standard Single Purpose Processors


LCD Controllers Keypad Controllers Timers/Counters Pulse Width Modulators UART A/D Converters Stepper Motor Controllers
Original source: Embedded Systems Design: A Unified Hardware/Software Introduction, (c) 2000 Vahid/Givargis Modified by: Osman Hasan, Assist. Prof., SEECS, NUST, Islamabad, Pakistan.

12

Pulse width modulator (PWM)


Generates an output signal that repeatedly switches between high and low values Duration of high/low values can be controlled by specifying
Desired period Duty Cycle (% of the time the signal is high compared to low)
A square wave has a duty cycle of 50%

Usage
Blink a light at a specific rate Control Average current/voltage to a device
Original source: Embedded Systems Design: A Unified Hardware/Software Introduction, (c) 2000 Vahid/Givargis Modified by: Osman Hasan, Assist. Prof., SEECS, NUST, Islamabad, Pakistan.

13

Pulse width modulator (PWM)


Controlling a DC motor
Rotates when a voltage is applied at its input Speed is proportional to the input voltage
Example: rpm is 100 times the input voltage 1.25 v 125 rpm 2.50 v 250 rpm

Using a PWM
DC motor does not come to an immediate stop when its input voltage is lowered to 0, but rather coasts Thus we set the average voltage to obtain the desired speed using the duty cycle of a PWM The period is set small enough for smooth operation of the motor
Original source: Embedded Systems Design: A Unified Hardware/Software Introduction, (c) 2000 Vahid/Givargis Modified by: Osman Hasan, Assist. Prof., SEECS, NUST, Islamabad, Pakistan.

14

Pulse width modulator (PWM)


Example:
Low voltage of PWM: 0v High voltage of PWM: 5v Average voltage of 1.25v can be obtained by a duty cycle of 25%
5 V * 0.25 = 1.25 V
pwm_o clk
25% duty cycle average pwm_o is 1.25V

Original source: Embedded Systems Design: A Unified Hardware/Software Introduction, (c) 2000 Vahid/Givargis Modified by: Osman Hasan, Assist. Prof., SEECS, NUST, Islamabad, Pakistan.

15

Pulse width modulator (PWM)


Example:
Low voltage of PWM: 0v High voltage of PWM: 5v
pwm_o clk
50% duty cycle average pwm_o is 2.5V.

pwm_o clk
75% duty cycle average pwm_o is 3.75V.

Original source: Embedded Systems Design: A Unified Hardware/Software Introduction, (c) 2000 Vahid/Givargis Modified by: Osman Hasan, Assist. Prof., SEECS, NUST, Islamabad, Pakistan.

16

Pulse width modulator (PWM)


Further Usage
Light Dimmers Control commands in a single signal
Control a radio-controlled car by sending pulses of different widths 1 ms width: Turn left 4 ms width: Turn right 8 ms width: Move forward
How would the receiver measure the widths to make decisions The receiver can use a timer to measure the pulse widths Start timer at the start of the pulse Stop timer when the pulse ends
Original source: Embedded Systems Design: A Unified Hardware/Software Introduction, (c) 2000 Vahid/Givargis Modified by: Osman Hasan, Assist. Prof., SEECS, NUST, Islamabad, Pakistan.

17

Assignment
Chapter 1: Transaction Level Modeling And Brief Overview: pages 1-22 Book: Transaction-level modeling with SystemC: TLM concepts and applications for Embedded Systems, By Frank Ghenassia Available at Google Books Summarize the chapter in your 10-15 minute presentation.

Original source: Embedded Systems Design: A Unified Hardware/Software Introduction, (c) 2000 Vahid/Givargis Modified by: Osman Hasan, Assist. Prof., SEECS, NUST, Islamabad, Pakistan.

18

Example: Design a Pulse Width Modulator

clk

clk_div controls how fast the counter increments

counter ( 0 254) 8-bit comparator cycle_high pwm_o counter < cycle_high, pwm_o = 1 counter >= cycle_high, pwm_o = 0

Original source: Embedded Systems Design: A Unified Hardware/Software Introduction, (c) 2000 Vahid/Givargis Modified by: Osman Hasan, Assist. Prof., SEECS, NUST, Islamabad, Pakistan.

19

Example: Design a Pulse Width Modulator


Clk_div: clock divider whose output drives the clock of the counter
Determines the PWMs period

Comparator compares the values of the counter and the cycle_high register
cycle_high Determines the duty cycle of the PWM
If cycle_high = FF H then duty_cycle = 100% If cycle_high = 00 H then the output is always low duty_cycle = 0%

Original source: Embedded Systems Design: A Unified Hardware/Software Introduction, (c) 2000 Vahid/Givargis Modified by: Osman Hasan, Assist. Prof., SEECS, NUST, Islamabad, Pakistan.

20

Example: Controlling a DC Motor using a PWM


Input Voltage

Relationship between applied voltage and speed of the DC Motor

0 2.5 3.75 5.0

% of Maximum Voltage Applied 0 50 75 100

RPM of DC Motor 0 4,600 6900 9200

clk

clk_div controls how fast the counter increments

counter ( 0 254) 8-bit comparator cycle_high

Activity: Find the values of cycle high for the above 4 values
pwm_o counter < cycle_high, pwm_o = 1 counter >= cycle_high, pwm_o = 0

Original source: Embedded Systems Design: A Unified Hardware/Software Introduction, (c) 2000 Vahid/Givargis Modified by: Osman Hasan, Assist. Prof., SEECS, NUST, Islamabad, Pakistan.

21

Activity: Controlling a DC Motor using a PWM


Design Problem
Values of clk_div and cycle_high
For 4,600 rpm we need a duty cycle of 50%
254 * 0.5 = 127 cycle_high = 7F h

For 6,900 rpm we need a duty cycle of 75%


254 * 0.75 = 191 cycle_high = BF h

For 0 and 9,200 rpm ?


Original source: Embedded Systems Design: A Unified Hardware/Software Introduction, (c) 2000 Vahid/Givargis Modified by: Osman Hasan, Assist. Prof., SEECS, NUST, Islamabad, Pakistan.

22

Activity: Controlling a DC Motor using a PWM


The PWM alone cannot drive the DC motor, a possible way to implement a driver is shown below using an MJE3055T NPN transistor.
5V

5V

From processor

DC MOTOR

A B

Original source: Embedded Systems Design: A Unified Hardware/Software Introduction, (c) 2000 Vahid/Givargis Modified by: Osman Hasan, Assist. Prof., SEECS, NUST, Islamabad, Pakistan.

23

Standard Single Purpose Processors


Timers/Counters Pulse Width Modulators LCD Controllers Keypad Controllers

UART A/D Converters Stepper Motor Controllers


Original source: Embedded Systems Design: A Unified Hardware/Software Introduction, (c) 2000 Vahid/Givargis Modified by: Osman Hasan, Assist. Prof., SEECS, NUST, Islamabad, Pakistan.

24

Serial Transmission Using UARTs


UART: Universal Asynchronous Receiver Transmitter
Takes parallel data and transmits serially Receives serial data and converts to parallel Useful when we need to communicate bytes of data
between devices that are separated by long distances When devices have a limited number of pins
Original source: Embedded Systems Design: A Unified Hardware/Software Introduction, (c) 2000 Vahid/Givargis Modified by: Osman Hasan, Assist. Prof., SEECS, NUST, Islamabad, Pakistan.

25

Serial Transmission Using UARTs


Simple UART
Configuration Registers
Transmit Buffer Shift register Holds data to be sent 10011011 Receiver Buffer Sending UART Another shift register Receives serially and reads in parallel
1 0 0 1 1 0 1 1 embedde d device

10011011 Receiving UART

To shift at the appropriate rate the UART requires a timer


Original source: Embedded Systems Design: A Unified Hardware/Software Introduction, (c) 2000 Vahid/Givargis Modified by: Osman Hasan, Assist. Prof., SEECS, NUST, Islamabad, Pakistan.

26

Serial Transmission Using UARTs Transmitter Operation


Host writes a byte to the transmit buffer of the UART The transmitter sends a start bit over tx Transmits data at tx one by one at a predetermined rate Parity bit is transmitted
Error detection capability
10011011 Sending UART 1 0 0 1 1 0 1 embedde d device 1

10011011 Receiving UART

UART signals the host that it is ready to transmit more bits


Original source: Embedded Systems Design: A Unified Hardware/Software Introduction, (c) 2000 Vahid/Givargis Modified by: Osman Hasan, Assist. Prof., SEECS, NUST, Islamabad, Pakistan.

27

Serial Transmission Using UARTs


Error Detection
Odd Parity
Number of 1s in the received data add up to an even number Parity bit is 1 (valid data) Parity bit is 0 (invalid data)
1 0 0 1 1 0 1 1 embedde d device

10011011 Sending UART

10011011 Receiving UART

Even Parity
Exactly opposite

Original source: Embedded Systems Design: A Unified Hardware/Software Introduction, (c) 2000 Vahid/Givargis Modified by: Osman Hasan, Assist. Prof., SEECS, NUST, Islamabad, Pakistan.

28

Serial Transmission Using UARTs Receiver Operation


The receiver is constantly monitoring the receive pin (rx) for a start bit
High to low transition
1 embedde d device 1

Sampling on the rx pin starts at predetermined intervals shifting each sampled bit into the receive shift register
If configured to do so, the receiver also samples the parity bit Once data is received the UART signals its host processor to read the byte

0 1

1 0 1

10011011 Sending UART

10011011 Receiving UART

Original source: Embedded Systems Design: A Unified Hardware/Software Introduction, (c) 2000 Vahid/Givargis Modified by: Osman Hasan, Assist. Prof., SEECS, NUST, Islamabad, Pakistan.

29

Transmission Protocol
Two serially connected UARTs must agree on a Transmission start bit end bit protocol data

Determines the rate at which bits are sent and received


Baud Rate

The number of bits of data Parity Minimum number of bits used to separate two consecutive data transmissions
Original source: Embedded Systems Design: A Unified Hardware/Software Introduction, (c) 2000 Vahid/Givargis Modified by: Osman Hasan, Assist. Prof., SEECS, NUST, Islamabad, Pakistan.

Baud Rate
Determines the speed at which data is exchanged between two UARTs Common baud rates
2400, 4800, 9600 and 19.2K

Difference between bit-rate and baud rate


Bit rate: number of bits sent per sec. Baud rate: number of symbols per sec
A symbol may have more than two states, so it may represent more than one binary bit

Original source: Embedded Systems Design: A Unified Hardware/Software Introduction, (c) 2000 Vahid/Givargis Modified by: Osman Hasan, Assist. Prof., SEECS, NUST, Islamabad, Pakistan.

Configuring the Baud Rate


Write to the configuration register Not as simple as writing 4800 to a register For 8051
Baud rate = (2smod/32)*oscfreq/(12 * (256 TH1)) smod: 2-bits in a special function register oscfreq: frequency of the oscillator TH1: 8-bit rate register of a built-in timer

TH1= 256 - (2smod *oscfreq)/(12 * 32 * Baud Rate)


Original source: Embedded Systems Design: A Unified Hardware/Software Introduction, (c) 2000 Vahid/Givargis Modified by: Osman Hasan, Assist. Prof., SEECS, NUST, Islamabad, Pakistan.

Das könnte Ihnen auch gefallen