Prerequisite – 8254 Programmable Interval Timer
After power-up, the state of the 8254 is undefined. The Mode, count value, and output of all Counters are undefined. How each counter operates is determined when it is programmed. Each counter must be programmed before it can be used. Unused counters need not be programmed. Counters are programmed by writing a Control Word and then an initial count.
Control Word of 8254 –
The format of Control Word of 8254 is:
Here by using the value of SC1 and SC0 we select a specific counter:
|1||1||Read back status|
The values of RW1 and RW0 are used to decide the Read – Write operation:
|0||0||Counter Latch Command|
|0||1||Read/Write lower byte|
|1||0||Read/Write higher byte|
|1||1||Read/Write lower byte followed by higher byte|
The values of M2, M1, M0 are used to decide the operating modes of 8254:
|X (0/1)||1||0||MODE 2|
|X (0/1)||1||1||MODE 3|
The LSB of Control Word is used to select whether the counter is Binary or BCD. If the bit is 0 it works as binary counter and if its value is 1 it works as BCD coounter.
Operating Modes of 8254:
- Mode 0 (Interrupt on Terminal Count) – Mode 0 is typically used for event counting. After the Control Word is written, OUT is initially low, and will remain low until the counter reaches zero it is decremented by 1 after every clock cycle. OUT then goes high and remains high until a new count or a new Mode 0 Control Word is written into the counter. GATE = 1 enables counting, GATE = 0 disables counting.
- Mode 1 (Hardware Retriggreable One Shot) – OUT will be initially high. OUT will go low on the CLK pulse following a trigger to begin the one-shot pulse, and will remain low until the counter reaches zero.
- Mode 2 (Rate Generator) – Initially value of OUT is low. When counting is enabled, it becomes high and this process repeats periodically. Value of count = Input Frequency / Output Frequency. This mode works as a frequency divider.
- Mode 3 (Square Wave Generator) – Counting is enabled when GATE = 1 and disabled when GATE = 0. This mode is used to generate square waveform and time period (equal to count) is generated.
If N is count and is even then ontime of wave = N/2 and offtime = N/2
If N is odd the ontime = (N + 1) / 2 and offtime = (N – 1) / 2
- Mode 4 (Software Triggered Strobe) – In this mode counting is enabled by using GATE = 1 and disabled by GATE = 0. Initially value of OUT is high and becomes low when value of count is at last stage. Count is reloaded again for subsequent clock pulse.
- Mode 5 (Hardware Triggered Strobe) – OUT will initially be high. Counting is triggered by a rising edge of GATE. When the initial count has expired, OUT will go low for one clock pulse and then go high again. After writing the Control Word and initial count, the counter will not be loaded until the clock pulse after a trigger.
- Microprocessor | 8254 programmable interval timer
- Interface 8254 PIT with 8085 microprocessor
- 8255 microprocessor operating modes
- Addressing modes in 8086 microprocessor
- Process control instructions in 8086 microprocessor
- Machine Control Instructions in Microprocessor
- Control Signals in 8155 Microprocessor
- Types of Program Control Instructions
- Instruction Word Size in Microprocessor
- Computer Organization and Architecture | Computer Organization and Architecture | Question 1
- fork() and Binary Tree
- Static and Dynamic Libraries | Set 1
- Zombie and Orphan Processes in C
- C program to demonstrate fork() and pipe()
- Zombie Processes and their Prevention
- fork() and memory shared b/w processes created using it
- dup() and dup2() Linux system call
- Difference between fork() and exec()
- getppid() and getpid() in Linux
- Calculation in parent and child process using fork()
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.