Lecture#5 Chapter4 Peripherals
Lecture#5 Chapter4 Peripherals
Lecture#5 Chapter4 Peripherals
Hardware/Software Introduction
Masadeh
Introduction
• Single-purpose processors
– Performs specific computation task
– Custom single-purpose processors
• Designed by us for a unique task
– Standard single-purpose processors
• “Off-the-shelf” -- pre-designed for a common task
• a.k.a., peripherals
• serial transmission
• analog/digital conversions
– Increases range by
decreasing resolution Mode
(increase period),
Embedded Systems Design: A Unified
Hardware/Software Introduction, (c) 2000 Vahid/Givargis
• Timer’s range: MAX time interval the timer can
measure.
• Timer’s resolution: MIN interval it can measure
• Prescaler: A configurable clock-divider circuit
• Reaction timer is an application that measures the time a person takes to respond
to a visual or audio stimulus.
• For example, turn a LED ON then the user press a button, the LCD display the
time (in ms) between seeing the Light and pressing the button (reaction of
seconds).
• This timer has No pre-scaler or terminal count register, but have a top signal.
• This timer allow to load an initial value
• We want to extend the range.
• Load the timer with initial value, such that an overflow will happen after 1ms.
• Record the number of overflows= the number of milliseconds
– 1 instruction cycle= 6*83.33=0.5 microsec.
– X instruction cycle= 1 ms X= 2000 intial timer value = 65535-2000=63535
• Measure time between turning light on and user pushing configure timer mode
set Cnt to MS_INIT
button
wait a random amount of time
– 16-bit timer, Freq= 12 MHZ, clk period is 83.33 ns, turn on indicator light
start timer
counter increments every 6 cycles (1 instruction
cycle = 6 clock cycles) while (user has not pushed reaction button){
if(Top) {
– Resolution = 1 instruction cycle= 6*83.33=0.5 stop timer
set Cnt to MS_INIT
microsec. start timer
reset Top
– Range = 65535*0.5 microseconds = 32.77 count_milliseconds++;
}
milliseconds }
– Want program to count millisec., so initialize turn light off
printf(“time: %i ms“, count_milliseconds);
counter to 65535 – 1000/0.5 = 63535 }
failure, self-reset
• Another use: timeouts /* main.c */ watchdog_reset_routine(){
/* checkreg is set so we can load value into
– e.g., ATM machine main(){ timereg. Zero is loaded into scalereg and
wait until card inserted 11070 is loaded into timereg */
– 16-bit timer, 2 call watchdog_reset_routine
checkreg = 1
microsec. resolution while(transaction in progress){ scalereg = 0
if(button pressed){ timereg = 11070
– timereg value = 2*(216- perform corresponding action }
1)–X = 131070–X call watchdog_reset_routine
} void interrupt_service_routine(){
– For 2 min., X = eject card
120,000 microsec. /* if watchdog_reset_routine not called every reset screen
< 2 minutes, interrupt_service_routine is }
called */
}
useful for
– Long distances
– When I/O pins are few
• UART requires a Timer to
shift at appropriate rate
1 0 0 1 1 0 1 1
pwm_o
clk
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
Red A
White A’
Yellow B
Black B’
Successive-approximation method