Download as pdf or txt
Download as pdf or txt
You are on page 1of 17

Introduction to Embedded Systems

Peripherals
Courtesy to Prof. Vahid for the resources used in preparing this lecture note.

Getachew Teshome (Room 120-B)


Addis Ababa University, AAIT
School of Electrical and Computer Engineering
September, 2016
Peripherals
 Dedicated Hardware for specific task

 Common Peripherals
– Timer
– Analog-to-Digital Converter
– Pulse Width Modulator
– Serial Communication
Timer
• Timer: measures time intervals
– To generate timed output events
– To measure input events Basic timer

• Triggered by clock pulses Clk


16-bit up
counter
16 Cnt

• Top Count Top

• Clock Frequency Reset

– 10MHz
• Counter Size
– 16 bit
Counters
• Counter: like a timer, but
counts pulses on a general
input signal rather than clock Timer/counter

Clk
– e.g., count cars passing over a 2x1
mux
16-bit up
counter
16 Cnt

sensor Cnt_in Top

Reset
– Can often configure device as Mode

either a timer or counter


Watchdog timer
• If Timer is not reset every X time unit, generate
interrupt
• Common use: detect failure, self-reset
• e.g.
– ATM machine,
– Lock with Keypad

os clk overflow overflow to system


c prescale scalereg timereg
r reset
or
checkre interrupt
g
More timer structures
• Interval timer 16/32-bit timer

Clk 16-bit up
– terminal count Timer with a terminal counter 16 Cnt1
count
– Clock cycles Top1
Clk 16-bit up
= Desired time interval counter 16 Cnt
16-bit up
16 Cnt2
/ Clock period counter

Reset Top2
• Pre-scaler =
Top
– Divides clock Time with prescaler

Prescaler 16-bit up
– Increases range, Clk
counter
Terminal count
decreases resolution

Mode
Pulse width modulator
• Generates pulses with
pwm_o
adjustable duty cycle. clk
• control average voltage 25% duty cycle – average pwm_o is 1.25V

to electric device
pwm_o
– DC motor speed,
clk
dimmer lights
50% duty cycle – average pwm_o is 2.5V.
• REPLACES
pwm_o
– DC-DC converter
clk
– DAC
75% duty cycle – average pwm_o is 3.75V.
Stepper motor without
controller (driver)
8051
P2.4 GND/ +V 1, 1, 0, 0,
P2.3 0, 1, 1, 0,
P2.2
P2.1 0, 0, 1, 1,
P2.0
1, 0, 0, 1,
1, 1, 0, 0
Steppe
r
Motor

move_forward (){

1K
+V
move_backward (){
Q1
+V B
1K
A Q2 }
330
Controlling a DC
motor with a PWM
% of Maximum
clk clk_div counter Input Voltage RPM of DC Motor
Voltage Applied
( 0 – 254)
controls 0 0 0
how fast the
counter 8-bit 2.5 50 1840
increments comparator pwm_o
3.75 75 6900

5.0 100 9200


cycle_high
Relationship between applied voltage and
speed of the DC Motor
Internal Structure of PWM

void main(void){
5V
/* controls period */
PWMP = 0xff;
/* controls duty cycle */
PWM1 = 0x7f; From DC
process MOTOR
while(1){}; or
}
Analog-to-digital
converters
Vmax = 7.5V 1111 4 4
7.0V 1110
6.5V 1101

analog output (V)


3 3

analog input (V)


6.0V 1100
5.5V 1011
2 2
5.0V 1010
4.5V 1001
4.0V 1 1
1000
3.5V 0111
3.0V 0110 time time
t1 t2 t3 t4 t1 t2 t3 t4
2.5V 0101
2.0V 0100 0100 1000 0110 0101 0100 1000 0110 0101
1.5V 0011 Digital output Digital input
1.0V 0010
0.5V 0001
0V 0000

proportionality analog to digital digital to analog


DAC - successive approximation

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.
Serial Transmission Using
UARTs
• UART: Universal
embedde
Asynchronous Receiver d device
1 1 0 1
Transmitter 0
0 1
1

– Takes parallel data and


transmits serially
10011011 10011011
– Receives serial data and
converts to parallel Sending UART Receiving UART
start bit end bit
• Parity: extra bit for simple dat
a
error checking
• Start bit, stop bit
• Baud rate
– signal changes per second
– bit rate usually higher 1 0 0 1 1 0 1 1
LCD controller
E void WriteChar(char c){
communication
R/W s bus
RS = 1; /* indicate data being sent */
R
DATA_BUS = c; /* send data to LCD */
S
DB7–DB0 EnableLCD(45); /* toggle the LCD with appropriate
8
delay */
microcontroller LCD }
controller

CODES RS R/W DB7 DB6 DB5 DB4 DB3 DB2 DB1 DB0 Description
I/D = 1 cursor moves left DL = 1 8-bit
0 0 0 0 0 0 0 0 0 1 Clears all display, return cursor home
I/D = 0 cursor moves right DL = 0 4-bit
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)
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

1 0 WRITE DATA Writes Data


Keypad controller

N1
N2
N3 k_pressed
N4

M1
M2
M3
M4 4
key_code key_code

keypad controller

N=4, M=4
Stepper motor
controller
Sequence A B A’ B’
• Stepper motor: rotates fixed number 1 + + - -
of degrees when given a “step” signal 2 - + + -
3 - - + +
– In contrast, DC motor just rotates when 4 + - - +
power applied, coasts to stop 5 + + - -

• Rotation achieved by applying Vd 1 16 Vm


MC3479P 15
specific voltage sequence to coils
A’ 2 B
A 3 14 B’
4 13

• Controller greatly simplifies this GND

Bias’/Set
5
6
12
11
GND

Phase A’
Clk 7 10 CW’/CCW
O|C 8 9 Full’/Half Step

Red A
White A’
Yellow B
Black B’
Stepper motor with
controller (driver)
/* main.c */
void main(void){
MC3479P sbit clk=P1^1;
sbit cw=P1^0; */turn the motor forward */
Stepper Motor
cw=0; /* set direction
Driver 8051 */
void delay(void){
CW’/CCW int i, j; clk=0; /* pulse clock */
10 P1.0 delay();
CLK for (i=0; i<1000; i++)
7 P1.1 clk=1;
for ( j=0; j<50; j++)
i = i + 0;
2 A’ B 15 } /*turn the motor backwards */
3 A B’ 14 cw=1; /* set direction
*/
clk=0; /* pulse clock */
delay();
clk=1;

}
The output pins on the stepper motor driver
Stepper do not provide enough current to drive the +V
Motor stepper motor. To amplify the current, a 1K
Q1
buffer is needed. One possible
A B
implementation of the buffers is pictured to the
left. Q1 is an MJE3055T NPN transistor and Q2
Q2 is an MJE2955T PNP transistor. A is
1K
connected to the 8051 microcontroller and B
is connected to the stepper motor.

You might also like