To find out the time interval between two consecutive events using the 8086, or any other processor or programming language for that matter, you observe some time reference when you see the two events, and you subtract the time references from each other to calculate elapsed time.
Unfortunately, the 8086 does not have an interval timer, so you either have to program one using some kind of periodic clock, or you have to measure time using a hard coded loop.
Method One: Interrupts for both
The periodic clock, for instance running at 1 kHz, generates a 1 mS interrupt. In the interrupt service routine, you increment a variable that represents time in mS. The monitored event also generates an interrupt. On the first interrupt, you note the interval time so far. On the second interrupt, you note and compute the time difference. In this example, you have a resolution of 1 mS.
If you were to use an original IBM PC, you would have a clock interrupt available with a frequency of 55 Hz, giving you a resolution of about 18.2 mS.
Method Two: Interrupts for one
The periodic clock runs as an interrupt, as described before. In a loop, you monitor the event, noting the interval time between susequent events, and calculate the time difference. The loop consumes all CPU time while running, which might be a problem.
Method Three: External clock
You have an external counter, perhaps running at 1 mHz. Either hard coded or in an interrupt service routine, you monitor the event, read the clock twice, and calculate the time. In this example, you have a resolution of 1 uS.
Method Four: Brute force
You have a loop that counts iterations in some variable, noting how many iterations there are between events.
While this method requires the least amount of hardware, it is the poorest method, both from the standpoint of overall system threading, and from the standpoint of accuracy.
The loop consumes all processing time. You cannot do anything else during that time, otherwise the results will be wrong. If you are designing a system with multiple processes and threads, this will not work.
The loop also does not have an easily predictable period. Memory latency, cache hit/miss ratio, and other ongoing interrupts will disturb the results. In a single threaded system, and that includes whatever operating system you use, it can work, and it can have repeatable results - and you will need to spend some time calibrating it.
Copyright © 2026 eLLeNow.com All Rights Reserved.