Time Delay in Microprocessor YASH PAL, March 23, 2026March 23, 2026 Time Delay in Microprocessor – In real-time applications, such as traffic light control, digital clock, process control, and serial communication, it is important to keep track of time. In some applications, a time delay is required between the execution of two instructions. There are two techniques to design the time delay in a microprocessor.Hardware techniqueSoftware techniqueFor the hardware time delay technique, additional hardware like 8253/8254 (Programmable Interval Timer) is required. The hardware technique has the advantages like it is very accurate. It can be used for real-time applications and frees the microprocessor to perform other tasks at the same time. The fundamental limitation of the hardware technique is the cost.In the software time delay technique, no additional hardware is required, so it is cheaper than the hardware technique. But it has some limitations, like it is not accurate, makes the microprocessor busy for the entire delay period, etc. The tedious calculation is required to decide the count. The following methods are used to provide a time delay using a software technique.Using the NOP instructionUsing counterUsing a nested loopTime Delay using NOP InstructionMeaning of instruction NOP is NO operation. This instruction does nothing but simply makes the microprocessor busy for 4T states. So by executing a NOP instruction in between two instructions, a delay of 4T states may be provided. 1 1T-state = ___________________ Operating frequencyLet’s take an example question to understand the time delay using the NOP instructionQuestion – How many times does the instruction NOP have to be executed to provide a time delay of 1m sec? between two instructions. The crystal frequency is 4MHz.Solution – Given thatCrystal frequency = 4MHzHence, the operating frequency (f) = 1/2 (Crystal frequency)= 4/2 MHz= 2MHzTime required to execute NOP instruction = 4T= 4(1/f)= 4/(2 x 106) sec.= 2μ sec.Number of times the instruction NOP has to be executed to provide a time delay of 1m sec. between two instructions is (1m sec)/(2μ sec) = 500 times. From the above example solution, it is clear that the provided delay using the NOP instruction is not a good solution. This is because the programmer has to store a large number of NOP instructions in memory.Time Delay using CounterA counter can be used to provide the time delay. According to this technique, a counter is initialized with the desired value and decremented by one. This looping operation continues till the count value reaches zero. Since the execution times of the instructions used in a counting are known, the initial value of the counter can be determined. The counter can be designed by using a register (8-bit counter) or a register pair (16-bit counter). The figure below shows the flow chart for time delay using a counter.Flowchart for time delay using a counterUsing One Register (8-bit counter)LableInstructionOpcodeInstructionOperandCommentsMachineCyclesNo. of T-statesMMC, nLoad the count of register C.OF + MR4T + 3T = 7TLOOPDCRCDecrement counterOF4TJNZLOOPIf the count is not zero, go to the location loopOF + MR + MR10/7TUsing one Register (8-bit counter)Here, OF = Opcode Fetch and MR = Memory ReadThe instruction JNZ is a three-byte instruction. The number of T-states for the JNZ instruction is shown as 10/7 in the program. It means that the microprocessor 8085 requires 10T-states to execute the instruction when the condition is true. But when the condition is false, the loop is terminated, requiring only 7T states. Time delay in the 8-bit counter using one register is given as below:TDelay = 7T + (n-1)(4T + 10T) + (4T + 7T) = 7T + 14nT - 14T + 11T = 7T + 14nT - 3T TDelay = 4T + 14nTLet’s take an example question to understand the time delay using a one-register (8-bit Counter)Question – Find the maximum time delay that can be provided using one register. The operating frequency of the microprocessor is 2MHz.Solution – For the maximum time delay, the count value must be maximum. The maximum count value can be FFH or 25510 using one register. Therefore, the maximum time delay is given as follows:TDelay = 4T + 14nT= (4 x ( 1/(2×106)) + ((14×255)/(2×106)) sec.= 1.785m sec.Using Register Pair (16-bit Counter)The maximum time delay (1.785 sec.), which can be introduced between two instructions using one register, is not sufficient for some applications. In those applications, we need to initialize the counter more than FFH or 255. Hence, a counter using a register pair instead of one register is used.LabelInstructionOpcodeInstructionOperandCommentsMachineCyclesNo. of T-statesLXID, NLoad counter with 16-bit number NOF + MR + MR4T+3T+3T = 10TLOOPDCXDDecrement counterOF6TMOVA, ECopy the contents of register E to register AOF4TORADLogically OR the contents of register A and register D to check the counterOF4TJNZLOOPRepeat until the DE register pair reaches zero.OF + MR + MR10/7TUsing a register pair (16-bit counter)Here, OF = Opcode Fetch and MR = Memory Read.In the above program, the DCX instruction is used to decrement the contents of the DE register pair. This instruction has 6T states in its opcode fetch machine cycle and does not affect any flag. When the contents of the DE register pair reach zero, the zero flag remains unchanged. Therefore, another technique is used to affect the zero flag as shown in programming by performing an ORing operation between the lower and higher pair, as shown below:TDelay = 10T + (N-1)(6T + 4T + 4T + 10T) + (6T + 4T + 4T + 7T) = 10T + 24NT - 24T + 21T TDelay = 7T + 24NTLet’s take an example question to understand the time delay using the Register Pair (16-bit Counter)Question – Write a program to generate a delay of 0.4 sec. If the crystal frequency is 5MHz.Solution – In the 8085 microprocessor, the operating frequency is half of the crystal frequency, henceOperating frequency (f) = (5 x 106)/2 Hz = 2.5MHzTime for one T-state = 1/(2.5 x 106) sec = 0.4μ secNow, we know TDelay = 7T + 24NT for 16-bit counterN = ((TDelay – 7T)/24T) = (0.4 – 7 x 0.4 x 10-6)/(24 x 0.4 x 10-6) =4166610 or A2C2HThe value of count is 4166610 or A2C2H. The delay loop using a 16-bit counter will be as follows:LabelInstructionOpcodeInstructionOperandCommentLXID, A2C2HLoad the counter with a 16-bit number A2C2H.LOOPDCXDDecrement counter.MOVA, ECopy the contents of register E to register A.ORADLogically OR the contents of register A and register D to check the counter.JNZLOOPRepeat until the DE register pair reaches zero.Using nested LoopThis technique is also known as time delay using a loop within a loop. In this, there is more than one loop. The outer loop sets the count to repeat the delay provided by the inner loop. A flowchart for time delay using a nested loop is shown in the figure below.Time delay using a nested loopLabelInstructionOpcodeInstructionOperandCommentsMachineCyclesNo. of T-statesMMB, NoutLoad the outer counterOF + MR4T + 3T = 7TMMC, NinLoad the inner counterOF + MR4T + 3T = 7TLOOP2DCRCDecrement the inner counterOF4TLOOP1JNZLOOP1If not zero goto LOOP1OF + MR + MR10T / 7TDCRBDecrement the outer counterOF4TJNZLOOP2If not zero goto LOOP2OF + MR +MR10T/7TLet’s take an example program to understand time delay using a nested loop.Question – Write a program to count continuously in hexadecimal from FFH to 00H in a system with a 0.5μ sec. clock period. Use register C to set up a 1m sec. Delay between each count and display the numbers at one of the output ports. Also, show the delay calculation.Solution – The program has two parts; first is to design a given delay of 1m sec. between two counts, and the second is to set up a continuous down counter from FFH to 00H.Delay Calculation: The required delay is 1m sec. which is less than the maximum delay provided by using one register (1.785m sec.). Hence, the delay counter can be designed with one register.TDelay = 4T + 14nT= 1 x 10-3 = (4 + 14n) x 0.5 x 10-6= n = 142.610 ≃ 14310= 8FHLet the accumulator be used as a counter to display, and register C is used as a counter for the delay loop. The following algorithm is used to design the counter.Algorithm:Step 1: Initialize the counter (accumulator) with FFH to display.Step 2: Display the value of the accumulator.Step 3: Provide a desired delay.Step 4: Decrement the counter and go to step 2.The assembly language program is given below for this problem.MemoryAddressHexCodeLabelInstructionOpcodeInstructionOperandCommentsXX00HXX01H3EFFMMA, FFHInitialize the display counterXX02HXX03HD3Port #RPTOUTPort #Display the contents of the accumulator at port #XX04HXX05H0E8FMMC, 8FHInitialize the delay counterXX06H0DLOOPDCRCDecrement the delay counterXX07HXX08HXX09HC206XXJNZLOOPIf not zero, goto memory location LOOPXX0AH3DDCRADecrement the display counterXX0BHXX0CHXX0DHC302XXJMPRPTJump to location RPTAssembly Language Program engineering subjects Microprocessor microprocessor