Professional Documents
Culture Documents
Lecture 5 - Peripherals
Lecture 5 - Peripherals
Peripherals
Courtesy to Prof. Vahid for the resources used in preparing this lecture note.
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
– 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
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
Mode
Pulse width modulator
• Generates pulses with
adjustable duty cycle. clk
pwm_o
to electric device
– DC motor speed,
pwm_o
dimmer lights
clk
• REPLACES
50% duty cycle – average pwm_o is 2.5V.
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
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
Successive-approximation method
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
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 + + - -
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