Sie sind auf Seite 1von 38

Meeting real time constraints

M Anbuselvi
AP/ECE
Time critical application
Problem 1:
Wait for a debounce period to confirm that the
switch is pressed
Wait through software delay no precise timing Wait through software delay no precise timing
Problem 2:
Cause the system to wait- indefinitely for the
user to release the switch
Hardware delays using timers
8051 Timers 12 MHZ
Two 16 bit Hardware Timers can be used to produce accurate delays
incremented every 12 oscillator cycles
the timers were incremented 1 million times per second
Count starts at 0 Count starts at 0
Reaches maximum value 65535 ( after 65.535ms )
Timer will overflow
Hardware flag is set
Change the initial value from zero to get shorter delays say 50 ms,1 ms
TCON SFR
TMOD SFR
THx and TLx registers
Calculation of hardware delays
Calculate the required starting value for the timer.
Load this value into the timer.
Start the timer.
Timer will be incremented, without software
intervention, at a rate determined by the oscillator intervention, at a rate determined by the oscillator
frequency;
wait for the timer to reach its maximum value and roll
over.
The timer signals the end of the delay by changing the
value of a flag variable.
TCON SFR
TR0, TR1 Timer run control bits
These bits need to be set to 1 (by the programmer) to run the
corresponding timer (TR0 controls Timer 0, TR1 controls Timer 1). If set to corresponding timer (TR0 controls Timer 0, TR1 controls Timer 1). If set to
0, the corresponding timer will not run.
Default value (after reset) is 0.
TF0, TF1 Timer overflow flags
These bits are set to 1 (by the microcontroller) when the corresponding
timer overflows. They need to be manually cleared (set to 0) by the
programmer. Default value (after reset) is 0.
For completeness we will briefly explain the purpose of the remaining bits
in TCON:
IE0, IE1 Interrupt flags
Set by hardware when an (external) interrupt is detected on Pin 12 or Pin
13, respectively.
These features are not related to Timer 0 or Timer 1 and are not used in
this book (these bits can be left at their default value).
IT0, IT1 Interrupt type control bit
Used to determine with the external interrupt flags (above) are set in
response to a falling edge (edge triggered) or a low-level (level
triggered) input on the relevant port pins.
These features are not related to Timer 0 or Timer 1 and are not used in
this book (these bits can be left at their default value).
Interrupts
Timer overflow
Generates interrupts
Gating control Gating control
Bit clear timer 0 & 1 enabled, control bit
TR0/TR1 is set in TCON
Timer 1 to generate the delays
values loaded into TL1 and TH1 at the start of the delay
routine will determine the delay duration.
12 oscillator cycles are required to perform 1 timer increment
Timer is incremented at 1 MHz rate
1 increment takes 1 micro seconds
i.e 1 sec => 1000000 increments
(1000msec)
Number of increments required for making 15ms delay
Timer overflows when it is incremented from its maximum Timer overflows when it is incremented from its maximum
count of 65535
Initial value to be loaded to produce 15 ms delay is
Delay value = 50 ms
Number of increments :
Initial value to be loaded to produce 50 ms delay:
Creating a portable hardware delay
Oscillator freq is not always 12 MHz
Battery powered appln. minimum safe operating frequency
Serial interface 11.059 MHz costly
Issue on system maintenance
Need for timeout mechanisms
Goat count problem
Problem 2 switch not released
Processor power wasted in idle loop
If the ADC has been incorrectly initialized, we cannot be sure
that a data conversion will be carried out.
If the ADC has been subjected to an excessive input voltage,
then it may not operate at all.
If the variable ADCON or ADCI were not correctly initialized,
they may not operate as required.
Solution
To avoid hanging function
1. Loop Timeouts
2. Hardware Timeouts
Creating loop timeout
We cannot easily determine how long this delay will be.
We do know that the loop will eventually time out.
Vary the duration of the loop timeout by changing the
initial value assigned to the loop variable.
A more reliable switch interface
Creating hardware timeouts
For shorter delays
With precise timing
Improvement in performance
Portable delay
Testing hardware timeout
Summary
Use of hardware timers for real time constraints
Configuring hardware timers
Designing portable timers Designing portable timers
Time out mechanism
Loop time out
Hardware time out

Das könnte Ihnen auch gefallen