Delay routines are subroutines used for maintaining the timings of various operations in microprocessor.
In control applications, certain equipment needs to be ON/OFF after a specified time delay. In some applications, a certain operation has to be repeated after a specified time interval. In such cases, simple time delay routines can be used to maintain the timings of the operations.
DELAY ROUTINE PROCESS
A delay routine is generally written as a subroutine (It need not be a subroutine always. It can be even a part of main program). In delay routine a count (number) is loaded in a register of microprocessor. Then it is decremented by one and the zero flag is checked to verify whether the content of register is zero or not. This process is continued until the content of register is zero. When it is zero, the time delay is over and the control is transferred to main program to carry out the desired operation.
The delay time is given by the total time taken to execute the delay routine. It can be computed by multiplying the total number of T-states required to execute subroutine and the time for one T-state of the processor. The total number of T-states can be computed from the knowledge of T-states required for each instruction. The time for one T-state of the processor is given by the inverse of the internal clock frequency of the processor.
For example, if the 8085 microprocessor has 5 MHz quartz crystal then,
The internal clock frequency = 5 / 2 = 2.5 MHz
Time for one T-state= 1 / 2.5 x 106 = 0.4µsec
• For small time delays (< 0.5 msec) an 8- bit register can be used.
• For large time delays (< 0.5 Sec) l6-bit register should be used.
• For very large time delays (> 0.5 sec), a delay routine can be repeatedly called in the main program.
The disadvantage in delay routines is that the processor time is wasted. An alternate solution is to use dedicated timer like 8253/8254 to produce time delays or to maintain timings of various operations.
Two example delay routines are presented in this section with details of timing calculations.
EXAMPLE DELAY ROUTINE -1
Write a delay routine to produce a time delay of 0.5 msec in 8085 processor-based system whose clock source is 6 MHz quartz crystal.
Solution
The delay required is 0.5 msec, hence an 8-bit register of8085 can be used to store a Count value and then decrement to zero. The delay routine is written as a subroutine as shown below.
Delay routine
MVI D, N ; Load the count value, N in D-register.
Loop: DCR D ; Decrement the count.
JNZ Loop ; If count is zero go to
RET ; Return to main program.
PROGRAMMING EXAMPLES:
No comments:
Post a Comment