• Timing is significant in computer controlled processes. If we think of a simple example, a fixed sample period means that the computer program must arrange to read the analog value at a consistent time.
• Various schemes for timing include,
- interrupts - fairly efficient, but requires some timing hardware inside
• by computer clock - a regular interrupt for the operating system
• programmable timer - a timer that is told to call an interrupt after some time
• by external trigger - asynchronous timing, potentially unstable
• by external clock - an external synchronous clock
- delay loops - consumes a large number of clock cycles
• wait for clock value - reasonable time, but prone to software problems
• count cycles - quite stable, but the computer cannot do anything else
- whenever possible - this ‘non-real-time’ approach can become unstable
• trigger and scan - a special input board can be set to read one or more values when timing or triggering conditions met
• Values are simply read from/written to locations in memory for both analog and digital values. When the process takes more than a single CPU cycle there will be a flag set to indicate when the operation is done. One example is reading analog values. This process may take hundreds of CPU cycles. We have three options,
1. continually check the ‘done’ flag/bit in memory
2. have the A/D converter trigger an interrupt when done
3. have the program perform other tasks for a period of time longer than the longest scan time.
• There are three fundamental properties of interrupts used for timing,
Hardware - These are actual pins on the outside of the CPU. When a change occurs the CPU will save its current status, and go to a subroutine. When done the system status is restored, and the computer programs resumes where it was interrupted. The number of hardware interrupts is often severely limited, but extra hardware can be added to expand the hardware interrupts. A computer keyboard and mouse typically use hardware interrupts.
Software - These are similar to hardware interrupts, except they are started by a call in software. These are plentiful, and used in all aspects of modern operating systems. MS-Dos makes extensive use of these software interrupts.
Maskable - These interrupts can be turned off by software. When running a critical process we may not want an interrupt to occur (and stop our program temporarily).
Non-Maskable - these interrupts cannot be disabled and will always cause the processor to stop.
We can set priorities for interrupts. If multiple interrupts occur at the same time the highest priority interrupt will be executed first. This allows critical processes to be addressed first.