Digital Logic · Registers and Counters
Need for Counters and Modular Counting
Overview
A counter is a sequential device that counts clock cycles, where the clock is a periodic square wave alternating 1, 0, 1, 0 .... Counters are needed to know how many clock cycles have occurred so far, to count in a repeating (modular) manner, and to generate control signals in Computer Organization.
Key concepts
- Counter: a sequential device that counts clock cycles; the clock is the input signal provided to the circuit.
- Clock: a periodic signal alternating between 1 and 0 (1, 0, 0, 1 ...).
- Modular counting: counting in a repeating manner — after reaching a fixed value, the count restarts from the beginning.
- Round-robin CPU allocation: one CPU is shared among several devices, each given the CPU for one cycle in turn; after the last device, the first device is served again.
- mod N counter: with N devices served in round-robin, the counter wraps around after every N counts, so a mod N counter is required (e.g. 4 devices → mod 4).
How it works
- A clock is a periodic signal alternating between 1 and 0 (1, 0, 1, 0 ...). A counter counts how many clock pulses have occurred up to the present time.
- Sometimes counting must be modular: after reaching a fixed value, the count restarts from the beginning.
- In round-robin CPU allocation, one CPU is shared among several devices, each given the CPU for one cycle in turn:
- 1st clock → device 1
- 2nd clock → device 2
- 3rd clock → device 3
- 4th clock → device 4
- 5th clock → device 1 again (restart)
- With four devices, the count sequence is 1, 2, 3, 4, 1, 2, 3, 4, ... — the 5th clock behaves like the 1st, the 6th like the 2nd, the 7th like the 3rd, the 8th like the 4th.
This is mod 4 counting: the counter wraps around after every 4 counts. - Counters are also used in Computer Organization to generate control signals.
- Counters come in various types; the theoretical points come first, and the practical points (with examples and problems) follow afterwards.
Formulas
- Count sequence for N devices in round-robin: — the count repeats every N clocks, so the required counter is a mod N counter.
- For 4 devices: (mod 4 counting).
Worked examples
Round-robin scheduling with 4 devices (mod 4 counter):
| Clock pulse | Device given CPU | Counter value (mod 4) |
|---|---|---|
| 1 | Device 1 | 1 |
| 2 | Device 2 | 2 |
| 3 | Device 3 | 3 |
| 4 | Device 4 | 4 (0) |
| 5 | Device 1 | 1 |
| 6 | Device 2 | 2 |
| 7 | Device 3 | 3 |
| 8 | Device 4 | 4 (0) |
The count repeats every 4 clocks, so the required counter is a mod-4 counter.
Revision summary
- A counter counts clock cycles; the clock is the input to the counter.
- Counters are needed for (i) counting clock cycles, (ii) modular counting, and (iii) generating control signals (seen later in CO).
- Modular counting means the count restarts after a fixed number of clocks.
- With N devices served in round-robin, the counter is a mod N counter (e.g. 4 devices → mod 4).
- In round-robin allocation, each successive clock goes to the next device, and after the last device the first device is served again.
- The 5th clock behaves like the 1st, the 6th like the 2nd, the 7th like the 3rd, the 8th like the 4th.
Previous-year exam insights
- The number of flip-flops needed for a modulo-N (mod-N) counter is ceil(); a mod-N counter has N states and requires at least that many flip-flops.
Asked inGATE 2011GATE 1994UGC NET 2015UGC NET 2007 - A counter that counts up to a maximum value M (i.e., M+1 distinct states 0..M) needs ceil() flip-flops; for a ripple counter counting up to a value, the number of flip-flops is the number of bits needed to represent that value.
Asked inUGC NET 2013 - When counters are cascaded, the overall modulus is the product of the individual moduli (a mod-M counter followed by a mod-N counter gives mod M×N).
Asked inUGC NET 2019 - For a counter with a non-standard or repeated sequence, the minimum number of flip-flops is ceil(), not the length of the sequence.
Asked inGATE 2016GATE 2015 - A mod-N counter using n flip-flops has unused states; these must be handled (self-starting design) so the counter cannot lock into an invalid state.
Asked inGATE 2016GATE 2007 - In a synchronous counter with clear/load/count control inputs, the next state is determined by priority of the control signals (typically Clear > Load > Count > No change), and the sequence depends on the feedback/decoding logic connected to the counter.
Asked inGATE 2007