RTES Chapter 3
RTES Chapter 3
1
Timers, Counters and Interrupts
2
Timing functions are vital in real-time
embedded systems.
A timer is a specialized type of clock that
is used to measure time intervals.
3
A timer or countdown timer is a type of clock
that starts from a specified time duration and
stops when reaching zero.
Commonly, a timer would raise an alarm when
it ends. It can be implemented as hardware or
software.
Stopwatches operate in the opposite direction,
upwards from zero, measuring elapsed time
since a given time instant.
Time switches are timers that control an electric
switch.
4
A clock or chronometer is a device that measures
and displays time.
Clocks have different ways of displaying the time.
Analog clocks indicate time with a traditional clock
face and moving hands.
Digital clocks display a numeric representation of
time.
Two numbering systems are in use: 12-hour time
notation and 24-hour notation. Most digital clocks
use electronic mechanisms and LCD, LED, or VFD
displays.
5
6
Real-Time Clock ( RTC) is a system component
responsible for keeping track of time.
RTC holds information like current time (In hours,
minutes and seconds) in 12 hour/24 hour format,
date, month, year, day of the week, etc. and
supplies timing reference to the system.
7
RTC is intended to function even in the absence of
power.
RTCs are available in the form of Integrated Circuits
from different semiconductor manufacturers like
Maxim/Dallas, ST Microelectronics etc.
8
The RTC chip contains a microchip for holding the
time and date related information and backup
battery cell for functioning in the absence of
power, in a single IC package.
The RTC chip is interfaced to the processor or
controller of the embedded system.
9
A counter counts the number of external events
occurring on its external event pin.
Embedded systems often require mechanisms for
counting the occurrence of events and for
performing tasks at regular intervals.
Embedded processors are often equipped with
hardware support for this functionality.
By providing this support, we can ensure that
events are not missed (within limits, of course) and
that timing of behavior occurs at regular intervals.
10
Counters, as the name suggests, are hardware
mechanisms for counting some form of event.
At the heart of the counter is a special purpose
register that stores the current value of the counter.
Any time that a certain event occurs, the value of
this counter is incremented (+1 is added to the
value).
The type of event that causes this increment is
typically configurable through other special
purpose registers.
11
Because the counter value is stored in a special
purpose register, this implies that the value can also
be read from or written to by the executing code.
Once the counter reaches this maximum value,
and a new event occurs, the counter resets back
to zero.
From here, the counter continues to increment with
each event.
12
As the name implies, an interrupt is some
event which interrupts normal program
execution.
13
Interrupts are a mechanism which enables
Microcontroller to respond to some events,
regardless of what Microcontroller is doing at that
time.
Each interrupt changes the program flow,
interrupts it and after executing an interrupt
routine, it continues from that same point on.
14
Interrupts are events that are detected by the
microprocessor hardware that cause the processor
(under the right conditions) to:
1. stop executing the code in the main program,
2. execute a special piece of code called an
interrupt service routine (ISR) that deals with the
event in some way, and
3. return to the main program and continue
execution.
15
When things are done properly, the main program
will not even know that this interruption has
occurred, except that a small amount of time has
gone by that it cannot account for.
16
Program flow is always sequential, being altered
only by those instructions which expressly cause
program flow to deviate in some way.
However, interrupts give us a mechanism to “put
on hold” the normal program flow, execute a
subroutine, and then resume normal program flow
as if we had never left it.
This subroutine, called an interrupt handler, is only
executed when a certain event (interrupt) occurs.
17
The event may be one of the timers “overflowing”,
receiving a character via the serial port,
transmitting a character via the serial port, or one
of two “external events”.
The 8051 may be configured so that when any of
these events occur the main program is
temporarily suspended and control passed to a
special section of code which presumably would
execute some function related to the event that
occured.
18
Once complete, control would be returned to the
original program.
The main program never even knows it was
interrupted.
The ability to interrupt normal program execution
when certain events occur makes it much easier
and much more efficient to handle certain
conditions.
19
If it were not for interrupts we would have to
manually check in our main program whether the
timers had overflown, whether we had received
another character via the serial port, or if some
external event had occured.
Besides making the main program ugly and hard to
read, such a situation would make our program
inefficient since we’d be burning precious
“instruction cycles” checking for events that usually
don’t happen.
20
Any Question
21
Thank You!
22