The D3, D2, and D1 bits of the control word set the operating mode of the timer. There are 6 modes in total; for modes 2 and 3, the D3 bit is ignored, so the missing modes 6 and 7 are aliases for modes 2 and 3. All modes are sensitive to the GATE input, with GATE high causing normal operation, but the effects of GATE low depend on the mode: • Modes 0 and 4: Counting is suspended while GATE is low, and resumed while GATE is high. • Modes 1 and 5: The rising edge of GATE starts counting. GATE may go low without affecting counting, but another rising edge will restart the count from the beginning. • Modes 2 and 3: GATE low forces OUT high immediately (without waiting for a clock pulse) and resets the counter (on the next clock falling edge). When GATE goes high again, counting restarts from the beginning.
Mode 0 (000): Interrupt on terminal count Mode 0 is used for the generation of accurate time delay under software control. In this mode, the counter will start counting from the initial COUNT value loaded into it, down to 0. Counting rate is equal to the input clock frequency. The OUT pin is set low after the Control Word is written, and counting starts one clock cycle after the COUNT is programmed. OUT remains low until the counter reaches 0, at which point OUT will be set high until the counter is reloaded or the Control Word is written. The counter wraps around to 0xFFFF internally and continues counting, but the OUT pin never changes again. The Gate signal should remain active high for normal counting. If Gate goes low, counting is suspended, and resumes when it goes high again. The first byte of the new count when loaded in the count register, stops the previous count.
Mode 1 (001): programmable one shot In this mode 8253 can be used as a
monostable multivibrator. GATE input is used as trigger input. OUT will be initially high. OUT will go low on the Clock pulse following a trigger to begin the one-shot pulse, and will remain low until the Counter reaches zero. OUT will then go high and remain high until the CLK pulse after the next trigger. After writing the Control Word and initial count, the Counter is armed. A trigger results in loading the Counter and setting OUT low on the next CLK pulse, thus starting the one-shot pulse. An initial count of N will result in a one-shot pulse N CLK cycles in duration. The one-shot is retriggerable, hence OUT will remain low for N CLK pulses after any trigger. The one-shot pulse can be repeated without rewriting the same count into the counter. GATE has no effect on OUT. If a new count is written to the Counter during a oneshot pulse, the current one-shot is not affected unless the counter is retriggered. In that case, the Counter is loaded with the new count and the oneshot pulse continues until the new count expires.
Mode 2 (X10): rate generator In this mode, the device acts as a divide-by-n counter, which is commonly used to generate a
real-time clock interrupt. Like other modes, the counting process will start the next clock cycle after COUNT is sent. OUT will then remain high until the counter reaches 1, and will go low for one clock pulse. The following cycle, the count is reloaded, OUT goes high again, and the whole process repeats itself. The time between the high pulses depends on the preset count in the counter's register, and is calculated using the following formula: Value to be loaded into counter = f_{\rm input}\over f_{\rm output} Note that the values in the COUNT register range from n to 1; the register never reaches zero.
Mode 3 (X11): square wave generator This mode is similar to mode 2. However, the duration of the high and low clock pulses of the output will be different from mode 2. Suppose n is the number loaded into the counter (the COUNT message), the output will be high for \left\lceil{n\over2}\right\rceil counts, and low for \left\lfloor{n\over2}\right\rfloor counts. Thus, the period will be n counts, and if n is odd, the extra half-cycle is spent with OUT high.
Mode 4 (100): Software Triggered Strobe After Control Word and COUNT is loaded, the output will remain high until the counter reaches zero. The counter will then generate a low pulse for 1 clock cycle (a strobe) – after that the output will become high again. GATE low suspends the count, which resumes when GATE goes high again.
Mode 5 (101): Hardware Triggered Strobe This mode is similar to mode 4. However, the counting process is triggered by the GATE input. After receiving the Control Word and COUNT, the output will be set high. Once the device detects a rising edge on the GATE input, it will start counting. When the counter reaches 0, the output will go low for one clock cycle – after that it will become high again, to repeat the cycle on the next rising edge of GATE. == IBM PC programming ==