Você está na página 1de 5

Embedded Systems Design: A Unified

Introduction
Hardware/Software Introduction
Single-purpose processors
Performs specific computation task
Chapter 4 Standard Single Purpose Custom single-purpose processors
Designed by us for a unique task
Processors: Peripherals Standard single-purpose processors
Off-the-shelf -- pre-designed for a common task
a.k.a., peripherals
serial transmission
analog/digital conversions
Low NRE cost
Low unit cost

1 Embedded Systems Design: A Unified 2


Hardware/Software Introduction, (c) 2000 Vahid/Givargis

Timers, counters, watchdog timers Counters

Timer: measures time intervals - very common


To generate timed output events
e.g., hold traffic light green for 10 s Counter: like a timer, but counts Timer/counter
To measure input events Basic timer pulses on a general input signal Clk
2x1 16-bit up 16 Cnt
e.g., measure a cars speed Clk
16-bit up
counter
16 Cnt rather than clock mux counter

Based on counting clock pulses Top


e.g., count cars passing over a sensor Cnt_in Top

E.g., let Clk period be 10 ns Reset


Can often configure device as either a Reset
Mode
And we count 20,000 Clk pulses timer or counter
Then 200 microseconds have passed
16-bit counter would count up to 65,535*10 ns = 655.35
microsec., resolution = 10 ns
Top: indicates top count reached, wrap-around
Can be used to extend range with use of microprocessor

Embedded Systems Design: A Unified 3 Embedded Systems Design: A Unified 4


Hardware/Software Introduction, (c) 2000 Vahid/Givargis Hardware/Software Introduction, (c) 2000 Vahid/Givargis
Other timer structures Example: Reaction Timer
Interval timer 16/32-bit timer
indicator reaction
button
/* main.c */
light
Indicates when desired time Clk 16-bit up
counter 16 Cnt1 #define MS_INIT 63535
Timer with a terminal
interval has passed count
LCD time: 100 ms void main(void){
int count_milliseconds = 0;
Top1
We set terminal count to
desired interval
Clk 16-bit up
counter 16 Cnt Measure time between turning light on configure timer mode
set Cnt to MS_INIT

Number of clock cycles


16-bit up
counter
16 Cnt2 and user pushing button wait a random amount of time
turn on indicator light
= Desired time interval / Reset Top2
16-bit timer, clk period is 83.33 ns (12 start timer
Clock period MHz), counter increments every 6 cycles while (user has not pushed reaction button){
=
Cascaded counters Top Time with prescaler (once per instruction cycle - microcontroller if(Top) {
stop timer
specific) set Cnt to MS_INIT
Prescaler Clk Prescaler 16-bit up
counter Resolution = 6*83.33=0.5 microsec. start timer
Terminal count reset Top
Divides clock Range = 65535*0.5 microseconds = 32.77 count_milliseconds++;
}
Increases range, decreases milliseconds }
turn light off
resolution Mode Want program to count millisec., so initialize printf(time: %i ms, count_milliseconds);
}
counter to 65535 1000/0.5 = 63535
Embedded Systems Design: A Unified 5 Embedded Systems Design: A Unified 6
Hardware/Software Introduction, (c) 2000 Vahid/Givargis Hardware/Software Introduction, (c) 2000 Vahid/Givargis

Watchdog timer Serial Transmission Using UARTs


Must reset timer every UART: Universal Asynchronous
X time unit, else timer
osc
prescaler
clk
scalereg
overflow
timereg
overflow to system reset Receiver Transmitter embedded
or 0 device
1
generates a signal interrupt Takes parallel data and transmits 0
0 1
1 1
1
serially
Common use: detect checkreg
Receives serial data and
failure, self-reset converts to parallel 10011011 10011011
Another use: timeouts /* main.c */ watchdog_reset_routine(){
/* checkreg is set so we can load value into Parity: extra bit for simple error Sending UART Receiving UART
e.g., ATM machine main(){
wait until card inserted
timereg. Zero is loaded into scalereg and
11070 is loaded into timereg */
checking start bit end bit
data
16-bit timer, 2 call watchdog_reset_routine
checkreg = 1
Start bit (receiver continually
microsec. resolution while(transaction in progress){ scalereg = 0 monitors for it), stop bit
if(button pressed){ timereg = 11070
timereg value = 2*(216- perform corresponding action } Baud rate
1)X = 131070X call watchdog_reset_routine
} void interrupt_service_routine(){ signal changes per second
For 2 min., X = eject card
Bits shifted out of buffer
/* if watchdog_reset_routine not called every reset screen
120,000 microsec. < 2 minutes, interrupt_service_routine is
called */
} Speed of communication 1 0 0 1 1 0 1 1
} Configured via configuration
register
Embedded Systems Design: A Unified 7 Embedded Systems Design: A Unified 8
Hardware/Software Introduction, (c) 2000 Vahid/Givargis Hardware/Software Introduction, (c) 2000 Vahid/Givargis
Pulse width modulator Controlling a DC motor with a PWM
Generates pulses with specific clk_div counter Input Voltage
% of Maximum
RPM of DC Motor
clk Voltage Applied
high/low times pwm_o controls how
( 0 254)
0 0 0
fast the
Duty cycle: % time high clk counter 8-bit counter <
2.5 50 1840
increments comparator pwm_o cycle_high,
Square wave: 50% duty cycle pwm_o = 1
3.75 75 6900
25% duty cycle average pwm_o is 1.25V
counter >=
Common use: control average cycle_high cycle_high,
5.0 100 9200
pwm_o = 0
voltage to electric device pwm_o
Relationship between applied voltage and speed of
the DC Motor
Internal Structure of PWM
Simpler than DC-DC clk
converter or digital-analog void main(void){ The PWM alone cannot drive the
converter 50% duty cycle average pwm_o is 2.5V. DC motor, a possible way to 5V
/* controls period */ implement a driver is shown
DC motor speed, dimmer PWMP = 0xff; below using an MJE3055T NPN
/* controls duty cycle */ transistor.
lights pwm_o PWM1 = 0x7f; 5V From DC

Another use: encode clk while(1){};


processor MOTOR

commands, receiver uses timer } A


75% duty cycle average pwm_o is 3.75V.
to decode B

Embedded Systems Design: A Unified 9 Embedded Systems Design: A Unified 10


Hardware/Software Introduction, (c) 2000 Vahid/Givargis Hardware/Software Introduction, (c) 2000 Vahid/Givargis

LCD controller Keypad controller

E void WriteChar(char c){


communications
R/W bus
RS = 1; /* indicate data being sent */ N1
RS
DATA_BUS = c; /* send data to LCD */ N2
DB7DB0 EnableLCD(45); /* toggle the LCD with appropriate delay */ N3 k_pressed
8 } N4
microcontroller LCD
controller
M1
M2
M3
CODES RS R/W DB7 DB6 DB5 DB4 DB3 DB2 DB1 DB0 Description M4 4
I/D = 1 cursor moves left DL = 1 8-bit
I/D = 0 cursor moves right DL = 0 4-bit
0 0 0 0 0 0 0 0 0 1 Clears all display, return cursor home key_code key_code
S = 1 with display shift N = 1 2 rows 0 0 0 0 0 0 0 0 1 * Returns cursor home
S/C =1 display shift N = 0 1 row
Sets cursor move direction and/or
0 0 0 0 0 0 0 1 I/D S
S/C = 0 cursor movement F = 1 5x10 dots specifies not to shift display
R/L = 1 shift to right F = 0 5x7 dots ON/OFF of all display(D), cursor
0 0 0 0 0 0 1 D C B
ON/OFF (C), and blink position (B) keypad controller
R/L = 0 shift to left
0 0 0 0 0 1 S/C R/L * * Move cursor and shifts display

Sets interface data length, number of


0 0 0 0 1 DL N F * *
display lines, and character font
N=4, M=4
1 0 WRITE DATA Writes Data

Embedded Systems Design: A Unified 11 Embedded Systems Design: A Unified 12


Hardware/Software Introduction, (c) 2000 Vahid/Givargis Hardware/Software Introduction, (c) 2000 Vahid/Givargis
Stepper motor controller Stepper motor with controller (driver)

Stepper motor: rotates fixed number Sequence


1
A
+
B
+
A
-
B
-
/* main.c */
void main(void){

of degrees when given a step signal 2 - + + -


MC3479P
Stepper Motor
sbit clk=P1^1;
sbit cw=P1^0; */turn the motor forward */
cw=0; /* set direction */
In contrast, DC motor just rotates when 3 - - + + Driver 8051
void delay(void){ clk=0; /* pulse clock */
4 + - - + CW/CCW delay();
power applied, coasts to stop 5 + + - - 10 CLK
P1.0 int i, j;
clk=1;
P1.1 for (i=0; i<1000; i++)
7
Rotation achieved by applying for ( j=0; j<50; j++)
i = i + 0; /*turn the motor backwards */
cw=1; /* set direction */
specific voltage sequence to coils Vd
A
1
2
16
MC3479P 15
Vm
B
2 A B 15
3 A B 14
}
clk=0; /* pulse clock */
delay();
Controller greatly simplifies this
A 3 14 B
4 13
clk=1;
GND GND
5 12

If step is 7.5 degrees, but do entire Bias/Set 6 11 Phase A


}

sequence to rotate 7.5 degrees


Clk 7 10 CW/CCW
O|C 8 9 Full/Half Step
The output pins on the stepper motor driver do not
Stepper
Opposite order for opposite direction Motor
provide enough current to drive the stepper motor.
To amplify the current, a buffer is needed. One 1K
+V
Q1
Red A possible implementation of the buffers is pictured
Can use a driver chip or do in White
Yellow
A
B
to the left. Q1 is an MJE3055T NPN transistor
and Q2 is an MJE2955T PNP transistor. A is
A

Q2
B

software Black B
connected to the 8051 microcontroller and B is
connected to the stepper motor.
1K

Embedded Systems Design: A Unified 13 Embedded Systems Design: A Unified 14


Hardware/Software Introduction, (c) 2000 Vahid/Givargis Hardware/Software Introduction, (c) 2000 Vahid/Givargis

Stepper motor without controller (driver) Analog-to-digital converters


8051 /*main.c*/ /* counter clockwise movement */
sbit notA=P2^0; if(dir==0){
P2.4 GND/ +V
sbit isA=P2^1; for(y=0; y<=step; y++){ Vmax = 7.5V 1111 4 4
sbit notB=P2^2; for(z=19; z>=0; z - 4){
P2.3
sbit isB=P2^3; isA=lookup[z]; 7.0V 1110
P2.2 6.5V
P2.1
sbit dir=P2^4; isB=lookup[z-1]; 1101 3 3

analog output (V)


analog input (V)
notA=lookup[z -2]; 6.0V
P2.0 1100
void delay(){ notB=lookup[z-3];
5.5V 1011
int a, b; delay( ); 2 2
for(a=0; a<5000; a++) } 5.0V 1010
Stepper for(b=0; b<10000; b++) } 4.5V 1001
Motor a=a+0; } 1 1
} } 4.0V 1000
void main( ){ 3.5V 0111
void move(int dir, int steps) { int z;
3.0V 0110 time time
A possible way to implement the buffers is located int y, z; int lookup[20] = { t1 t2 t3 t4 t1 t2 t3 t4
below. The 8051 alone cannot drive the stepper motor, so /* clockwise movement */ 1, 1, 0, 0, 2.5V 0101
several transistors were added to increase the current going if(dir == 1){ 0, 1, 1, 0, 2.0V 0100 0100 1000 0110 0101 0100 1000 0110 0101
to the stepper motor. Q1 are MJE3055T NPN transistors for(y=0; y<=steps; y++){ 0, 0, 1, 1, 1.5V Digital output Digital input
for(z=0; z<=19; z+4){ 1, 0, 0, 1, 0011
and Q3 is an MJE2955T PNP transistor. A is connected to
isA=lookup[z]; 1, 1, 0, 0 }; 1.0V 0010
the 8051 microcontroller and B is connected to the stepper
motor. +V isB=lookup[z+1]; while(1){ 0.5V 0001 analog to digital digital to analog
1K notA=lookup[z+2]; /*move forward, 15 degrees (2 steps) */ 0V
Q1
notB=lookup[z+3]; move(1, 2); 0000
+V B
delay(); /* move backwards, 7.5 degrees (1step)*/
1K
} move(0, 1); proportionality
A Q2
} }
330 } }

Embedded Systems Design: A Unified 15 Embedded Systems Design: A Unified 16


Hardware/Software Introduction, (c) 2000 Vahid/Givargis Hardware/Software Introduction, (c) 2000 Vahid/Givargis
DAC/ADC conversion ADC
e = present analog voltage
Using ratio: e/Vmax = d / (2n-1) d = digital encoding ADCs may contain DACs
n = number of bits
ADC guesses at encoding and then evaluates its guess
Assume Vmin - 0
using the DAC
Resolution is the number of volts between successive So how do we guess the correct encoding?
digital encodings Sequential search? Too slow with 2n encodings
DACs are easy: input d for digital encoding and max Binary search?
voltage and output analog e using resistors and op-amp
ADCs take a bit of time to get correct encoding
ADCs are hard: Given Vmax and e how does converter
know the binary value to assign to satisfy the ratio?
No simple analog circuit
Embedded Systems Design: A Unified 17 Embedded Systems Design: A Unified 18
Hardware/Software Introduction, (c) 2000 Vahid/Givargis Hardware/Software Introduction, (c) 2000 Vahid/Givargis

Digital-to-analog conversion using


successive approximation
Given an analog input signal whose voltage should range from 0 to 15 volts, and an 8-bit digital encoding, calculate the correct encoding for
5 volts. Then trace the successive-approximation approach to find the correct encoding.
5/15 = d/(28-1)
d= 85 Encoding: 01010101
Successive-approximation method

!(Vmax Vmin) = 7.5 volts 0 0 0 0 0 0 0 0 !(5.63 + 4.69) = 5.16 volts 0 1 0 1 0 0 0 0


Vmax = 7.5 volts. Vmax = 5.16 volts.

!(7.5 + 0) = 3.75 volts 0 1 0 0 0 0 0 0 !(5.16 + 4.69) = 4.93 volts 0 1 0 1 0 1 0 0


Vmin = 3.75 volts. Vmin = 4.93 volts.

!(7.5 + 3.75) = 5.63 volts 0 1 0 0 0 0 0 0 !(5.16 + 4.93) = 5.05 volts 0 1 0 1 0 1 0 0


Vmax = 5.63 volts Vmax = 5.05 volts.

!(5.63 + 3.75) = 4.69 volts 0 1 0 1 0 0 0 0 !(5.05 + 4.93) = 4.99 volts 0 1 0 1 0 1 0 1


Vmin = 4.69 volts.

Embedded Systems Design: A Unified 19


Hardware/Software Introduction, (c) 2000 Vahid/Givargis

Você também pode gostar