Ci-dessous, les différences entre deux révisions de la page.
| Révision précédente | |||
| — | back2root:ibm-pc-ms-dos:hardware:8253 [2026/01/11 23:31] (Version actuelle) – ↷ Liens modifiés en raison d'un déplacement. 42.81.251.13 | ||
|---|---|---|---|
| Ligne 1: | Ligne 1: | ||
| + | ====== 8253/8254 PIT - Programmable Interval Timer ====== | ||
| + | |||
| + | The Intel 8253 and 8254 are programmable interval timers (PITs), which perform timing and counting functions using three 16-bit counters. | ||
| + | |||
| + | The 825x family was primarily designed for the Intel 8080/ | ||
| + | |||
| + | In PC compatibles, | ||
| + | |||
| + | The Intel 82c54 (c for CMOS logic) variant handles up to 10 MHz clock signals. | ||
| + | |||
| + | ===== Features of 8253 / 8254 ===== | ||
| + | |||
| + | The most prominent features of 8253/8254 are as follows: | ||
| + | |||
| + | * It has three independent **16-bit** down counters. | ||
| + | * It can handle clock up to 2.6 MHz (10 MHz for the **8254**). | ||
| + | * These three counters can be programmed for either //binary// or //BCD// count. | ||
| + | * It is compatible with almost all microprocessors. | ||
| + | * **8254** has a powerful command called **READ BACK** command, which allows the user to check the count value, the programmed mode, the current mode, and the current status of the counter. | ||
| + | |||
| + | |||
| + | ===== 8253/8254 IBM PC Ports description ===== | ||
| + | |||
| + | ^ Port ^ Model ^ Description | ||
| + | | 40h | ||
| + | | 41h | ||
| + | | 42h | ||
| + | | 43h | ||
| + | | 44h | ||
| + | | 47h | ||
| + | |||
| + | ===== Port 43h ===== | ||
| + | {{anchor: | ||
| + | ^ Bit ^ 8253 Mode Control Register | ||
| + | | 0 | Counter [[# | ||
| + | | 1-3 | Counter [[# | ||
| + | | 4-5 | read/ | ||
| + | | 6-7 | counter select bits (also 8254 read back command) | ||
| + | |||
| + | ==== Bits 0 - Counter format ==== | ||
| + | {{anchor: | ||
| + | | 0 |binary Counter| | ||
| + | | 1 |4 BCD counter| | ||
| + | |||
| + | ==== Bits 1-3 - Counter Mode Bits ==== | ||
| + | {{anchor: | ||
| + | ^ Bits ^ ^ | ||
| + | | 000 |mode 0, interrupt on terminal count; | ||
| + | | 001 |mode 1, programmable one-shot; countdown with optional restart; reloading the counter will not affect the countdown until after the following trigger | | ||
| + | | 010 |mode 2, rate generator; generate one pulse after ' | ||
| + | | 011 |mode 3, square wave rate generator; generate one pulse after ' | ||
| + | | 100 |mode 4, software triggered strobe; countdown with output high until counter zero; at zero output goes low for one CLK period; | ||
| + | | 101 |mode 5, hardware triggered strobe; countdown after triggering with output high until counter zero; at zero output goes low for one CLK period| | ||
| + | |||
| + | The 1-3 bits of the control word set the operating mode of the timer. There are 6 modes in total | ||
| + | |||
| + | <WRAP round box> | ||
| + | For modes 2 and 3, the bit 3 is ignored, so the missing modes 6 and 7 are aliases for modes 2 and 3. | ||
| + | </ | ||
| + | |||
| + | The OUT signal is linked to CPU (via Interrupt). | ||
| + | |||
| + | === 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. | ||
| + | |||
| + | {{back2root: | ||
| + | |||
| + | 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. | ||
| + | |||
| + | {{back2root: | ||
| + | |||
| + | The one-shot is retriggerable, | ||
| + | |||
| + | === 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' | ||
| + | |||
| + | <WRAP round box> | ||
| + | <m 17> | ||
| + | </ | ||
| + | |||
| + | {{back2root: | ||
| + | |||
| + | <WRAP round info> | ||
| + | Note that the values in the COUNT register range from < | ||
| + | </ | ||
| + | === 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 < | ||
| + | |||
| + | {{back2root: | ||
| + | === 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. | ||
| + | |||
| + | {{back2root: | ||
| + | |||
| + | === 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. | ||
| + | |||
| + | {{back2root: | ||
| + | ==== Bits 4-5 - Read/ | ||
| + | |||
| + | {{anchor: | ||
| + | ^ Bits ^ ^ | ||
| + | | 00 |latch present counter value| | ||
| + | | 01 |read/write of MSB only| | ||
| + | | 10 |read/write of LSB only| | ||
| + | | 11 |read/write LSB, followed by write of MSB| | ||
| + | |||
| + | ==== Bits 6-7 - Counter Select Bits ==== | ||
| + | {{tablelayout? | ||
| + | ^ Bits ^ ^ | ||
| + | | 00 | select counter 0 | | ||
| + | | 01 | select counter 1 | | ||
| + | | 10 | select counter 2 | | ||
| + | | 11 | read back command (8254 only, **illegal on 8253**, see [[# | ||
| + | |||
| + | ===== Read Back Command Status (8254 only) ====== | ||
| + | {{anchor: | ||
| + | Read from counter register | ||
| + | |||
| + | ^ Bit ^ Read Back Command Status ^ | ||
| + | | | ||
| + | | 1-3 | counter mode bits (see Mode Control Reg above)| | ||
| + | | 4-5 | read/ | ||
| + | | | ||
| + | | | ||
| + | |||
| + | |||
| + | * the 8253 is used on the PC & XT, while the 8254 is used on the AT+ | ||
| + | * all counters are decrementing and fully independent | ||
| + | * the PIT is tied to 3 clock lines all generating 1.19318 MHz. | ||
| + | * the value of 1.19318MHz is derived from (4.77/4 MHz) and has it's roots based on NTSC frequencies | ||
| + | * counters are 16 bit quantities which are decremented and then tested against zero.Valid range is (0-65535). | ||
| + | * reading by latching the count doesn' | ||
| + | * counter 0 is the time of day interrupt and is generated approximately 18.2 times per sec. The value 18.2 is derived from the frequency 1.10318/ | ||
| + | * counter 1 is normally set to 18 (dec.) and signals the 8237 to do a RAM refresh approximately every 15ms | ||
| + | * counter 2 is normally used to generate tones from the speaker but can be used as a regular counter when used in conjunction with the 8255 | ||
| + | * newly loaded counters don't take effect until after a an output pulse or input CLK cycle depending on the mode | ||
| + | * the 8253 has a max input clock rate of 2.6MHz, the 8254 has max input clock rate of 10MHz | ||
| + | |||
| + | ===== Programming considerations: | ||
| + | |||
| + | - load Mode Control Register | ||
| + | - let bus settle (jmp $+2) | ||
| + | - write counter value | ||
| + | - if counter 0 is modified, an INT 8 handler must be written to call the original INT 8 handler every 18.2 seconds. When it does call the original INT 8 handler it must NOT send and EOI to the [[back2root: | ||
| + | |||
| + | ==== Example code: ==== | ||
| + | |||
| + | <code asm> | ||
| + | countdown | ||
| + | |||
| + | cli | ||
| + | | ||
| + | ; bit 5,4 = (11) write LSB then MSB | ||
| + | ; bit 3-1 = (011) generate square wave | ||
| + | ; bit 0 = (0) binary counter | ||
| + | | ||
| + | | ||
| + | | ||
| + | ; interrupts when counter decrements to 0 | ||
| + | | ||
| + | | ||
| + | | ||
| + | | ||
| + | | ||
| + | | ||
| + | sti | ||
| + | </ | ||
| + | |||
| + | ===== Hardware informations ===== | ||
| + | |||
| + | |||
| + | ==== 8254 Architecture ==== | ||
| + | |||
| + | The architecture of 8254 looks as follows − | ||
| + | |||
| + | {{back2root: | ||
| + | |||
| + | ==== 8254 Pin Description ==== | ||
| + | |||
| + | Here is the pin diagram of 8254 − | ||
| + | |||
| + | {{back2root: | ||
| + | |||
| + | In the above figure, there are three counters, a data bus buffer, Read/Write control logic, and a control register. Each counter has two input signals - CLOCK & GATE, and one output signal - OUT. | ||
| + | |||
| + | ==== Data Bus Buffer ==== | ||
| + | |||
| + | It is a tri-state, bi-directional, | ||
| + | |||
| + | * Programming the modes of 8253/54. | ||
| + | * Loading the count registers. | ||
| + | * Reading the count values. | ||
| + | |||
| + | |||
| + | ==== Read/Write Logic ==== | ||
| + | |||
| + | It includes **5** signals, i.e. RD, WR, CS, and the address lines A0 & A1. In the peripheral I/O mode, the RD and WR signals are connected to IOR and IOW, respectively. In the memorymapped I/O mode, these are connected to MEMR and MEMW. | ||
| + | |||
| + | Address lines A0 & A1 of the CPU are connected to lines A0 and A1 of the 8253/54, and CS is tied to a decoded address. The control word register and counters are selected according to the signals on lines A0 & A1. | ||