During normal execution of a program, instructions are read from memory and executed sequentially by the processor. The processor uses a special register called the instruction pointer to keep track of the next instruction to be executed. A set of general-purpose registers are used for manipulation and temporary storage of any data used by the program.
An interrupt is a special input to the processor. When the processor is signalled that an interrupt has occurred, the processor finishes the instruction currently being executed and saves the instruction pointer and a status word to the stack. The stack is a special block of memory used to keep track of information during function calls and interrupts. The processor uses a special register called the stack pointer to keep track of the location of the top of the stack, which is where the last item was added to the stack.
After the processor saves this information to the stack, the processor branches to a special routine called an interrupt service routine or interrupt handler. If needed, this routine can determine the source of the interrupt and then service the device that requested the interrupt. This process may involve reading a character from the keyboard and updating the monitor, or moving data from an adapter board into computer memory. After handling the interrupt, the last instruction executed in the interrupt service routine is an interrupt return instruction. This instruction causes the processor to restore the instruction pointer and status register with the values that were saved to the stack at the time of the interrupt and to resume execution.
Many data acquisition applications can benefit greatly from the interrupt capability of the processor. Interrupts can be used for immediate communication between the data acquisition hardware and the computer. They can be used to time or synchronize data acquisition with external events or to respond promptly to external events and alarm conditions. However, interrupts are not always the best approach in data acquisition applications. You must consider the advantages and disadvantages of various data acquisition methods before deciding to use interrupt-driven acquisition.
Data acquisition involves the monitoring of one or several sources of physical data at a regular rate, which is often determined by a clock signal. Commonly, the data originates from analog-to-digital converters (ADCs), counter/timer devices, or switches. In general, there are three approaches to acquiring data from an external device or synchronizing communication between devices. These three approaches are described as follows:
Polling : This
method involves periodically reading the status of the device to determine
whether the device needs attention.
Direct Memory Access (DMA) : A dedicated processor, the DMA controller, transparently transfers data from the device to computer memory, or vice versa.
Interrupts : The device is configured to interrupt the processor whenever the device requires attention.
For some applications, polling a device can be a very effective way to service a data acquisition operation. The polling method is simple, easy to understand, and easy to debug. If the processor can be dedicated to the single task of monitoring and servicing the device, high acquisition rates can be realized. However, dedication to a single task is often not possible. Other devices may also require timely monitoring, or the processor may be required to do other work, such as handling previously acquired data. DMA or interrupts would then be a better approach.
DMA uses a DMA controller to move data from one location to another, making fast data transfers of large blocks of data possible. DMA is fast because dedicated hardware transfers the data and requires only one or two read/write bus cycles per transfer. In addition, the processor is free for other activities (such as processing acquired data) because the DMA controller proceeds with the data acquisition in the background. However, the processor may need to access the data on a point-by-point basis as it is being acquired. DMA is not well-suited for this type of application, and interrupts or polling may be preferable. Furthermore, the number of DMA channels in a PC is limited, and a dedicated DMA channel is required for each unique data acquisition source.
With interrupts, the processor can respond quickly to an event (such as a clock signal) to transfer data or to synchronize different events. Unlike DMA, an interrupt-driven system has the advantage of being able to process the data on a point-by-point basis, which can be particularly inportant in control applications. Consider a typical control application synchronized with a clock signal, for example. The application may require that, with every pulse of a clock, the processor read the result of an A/D conversion, read the state of several digital lines, use these results to compute a new control value, and write this value to a digital-to-analog converter (DAC). DMA would not be useful for such an application, and a polling routine would not directly provide synchronization with the clock signal. Interrupts, however, make it easier to synchronize the input and output with the clock signal and for the processor to perform other general processing tasks in the foreground, if needed.
One disadvantage of interrupts, however, is that they require processor
time, and there can be a significant amount of software overhead time
associated with the interrupt service routine. When designing a data
acquisition system, you must estimate the amount of this overhead time,
which consists of the time required by the processor to vector to the
proper interrupt service routine, known as interrupt latency, and the time
necessary to perform the task required within the service routine. If the
overhead is too large for the required acquisition rate, then DMA or a
very efficient polling routine must be used. In applications that are time
critical, the interrupt service routine must be written to be as fast as
possible. As a result, interrupt service routines for data acquisition
applications are often written in assembly language.
Interrupts can be a powerful mechanism for servicing data acquisition and control operations. With interrupts, the processor can respond quickly and efficiently to data acquisition hardware. Besides simply transferring acquired data, interrupts can be used to synchronize different events, or process data as it is acquired. However, interrupts are not always the best method for data acquisition. DMA is useful for moving blocks of data at high rates with minimal processor intervention. Polling is the most straightforward technique, but not very effective for multiple devices or high throughput rates.