
COE305 LAB MANUAL
38
3.1 Background
It is often necessary to control how long certain actions last. This can be achieved
using software delays, or more accurately by the use of a timer (i.e. 8253 PIT chip). In
this experiment, you will learn how to generate time delays using both software delays
and 8253 PIT chip. Also, you will learn how to use time delays to control the operation
of some devices (e.g. LEDs and Relays), and to generate periodical waveforms of
different frequencies.
3.2 Software Delays
The easiest way to generate delays is a software delay. If we create a program which
loops around itself, and does this for a fixed number of times, for a given processor,
running at a given clock rate, this process will almost take the same time each time the
program is executed. All we have to do is to write this loop such that it takes 1 second.
Then, by calling this loop n times, we generate a delay of n seconds. Notice that the
time taken by the loop does not need to be 1 second. For example, a loop that takes
0.25 seconds to execute, can be called 4×n times (i.e. n/0.25) to generate a delay of n
seconds. The question now is how to determine the time taken by a loop. This can
be answered by the following example.
Example 3.1: Calculate the total time taken by the following loop.
MOV CX, 8000h; load CX with a fixed value 8000h (32768)
L1: DEC CX ; decrement CX, loop if not zero
JNZ L1
From the 8086 data sheets, we find that DEC CX requires 2 clock cycles and
JNZ requires 16 clock cycles. Thus, the total number of clock cycles required
by these two instructions is 18 clock cycles.
Since the FLIGHT-86 board is running at 14.7456/3 MHz, 1 clock cycle will
take 3/14.7456 microseconds, and 18 clock cycles will take 54/14.7456
microseconds. Thus, the total time taken by the loop is 32768 × (54/14.7456
× 10
-6
) = 0.12 seconds
The previous loop requires 0.12 seconds. Thus, this loop needs to be executed almost
8 times to generate a delay of 1 second. The following example shows how to use this
loop inside a program to turn ON/OFF an LED for specific amounts of time.
Comentários a estes Manuais