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

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, 2019
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

– Can often configure device as Mode


Reset

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

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

• Pre-scaler =
Reset Top2

– Divides clock Top Time with prescaler

– Increases range, Clk Prescaler 16-bit up


counter
decreases resolution
Terminal count

Mode
Pulse width modulator
• Generates pulses with
adjustable duty cycle. clk
pwm_o

• control average voltage 25% duty cycle – average pwm_o is 1.25V

to electric device
– DC motor speed,
pwm_o

dimmer lights
clk

• REPLACES
50% duty cycle – average pwm_o is 2.5V.

– DC-DC converter pwm_o

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
Asynchronous Receiver embedde
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
• Stepper motor: rotates fixed number Sequence
1
A
+
B
+
A’
-
B’
-
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’
A
2
3 14
B
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.
PROJECT – Elevator Management system
interfaces
• DFC1, DFC2 : DFC1 and DFC2 are the safety switches to prevent the elevator car from moving downwards beyond the Ground
or lowest floor.
• UR : Up Reed is a magnetic reed switch which is used to sense whenever the elevator car passes by a floor while moving
upwards. The UR signal is activated whenever the elevator car passes by the magnet attached at each floor.
• DR : Down Reed is a magnetic reed switch which is used to sense whenever the elevator car passes by a floor while moving
downwards. The DR signal is activated whenever the elevator car passes by the magnet attached at each floor.
• UR, DR are used to count the number of floors passed and keep track of the elevator car's current floor status.
• DRVSTOP : The Drive stop signal is used to stop and park the elevator car exactly aligned with the door of the elevator from
where the passengers get inside the car.
• CDP (Infrared sensor) : The CDP signal is generated by an infrared sensor fitted inside the elevator car doors. Whenever there
is a obstacle in between the doors it remains open, preventing someone from getting hurt while the door being closed with a
person in between. The elevator will not move until this signal is inactive and the door is properly closed.
• CAR Control panel : The CAR control panel is a set of buttons inside the elevator car. floor numbers like, 1, 2, 3 These buttons
when pressed indicate requests to the elevator car and are called CAR calls.
• The buttons DC(Door Close), DO(Door Open) are used to Close elevator door and Open elevator door respectively during
manual operation.
• The buttons FAN, STOP are used to turn on-off the fan inside the elevator and Stop the elevator car movement immediately.
• These are the elevator signals we need to take care of and use them to properly control the elevator movements.
MOTION CONTROL

• Start
• Stop
• Speed
• Alarm
• Emergency (Power Off, Motor Failure, Wrong
Floor Reading, …
MILESTONES
• Design and Specification December 2, 2019 23:59
– Features, Components
• Refined Design December 9, 2019 23:59
– Schematic, BoM, Selection
• Basic Implementation December 23, 2019 23:59
– Code V1
• Final Implementation January 6, 2020 23:59
– Code V2
• Documentation January 13, 2020 23:59
• Evaluation January 16, 2020 23:59
PROJECT – MP3 Voice Recorder/ Player
Context Diagram
interfaces
• Buttons
• Joystick (
• Keypads
• LCD
Use cases/ scenarios

• Record
• Playback
• File (Delete, rename, …
Spec
• Record quality
• Capacity
– Number of Message
– Directory Structure
– Storage
• CODEC
• Mp3 Encoder/ Decoder
MILESTONES
• Design and Specification December 6, 2019 23:59
– Features, Components
• Refined Design December 13, 2019 23:59
– Schematic, BoM, Selection
• Basic Implementation December 27, 2019 23:59
– Code V1 (Raw - wav)
• Final Implementation January 10, 2020 23:59
– Code V2 (CODEC – mp3)
• Documentation January 17, 2020 23:59
• Evaluation January 20, 2020 23:59

You might also like