Wize Electricity and Magnetism Textbook > Electronics

Logic Gates: Memory, Counting and Arithmetic

Combinational Logic, Stored State, and the Cost of Waiting

Digital logic divides into two families that behave quite differently. A combinational circuit's output depends only on its present inputs: it has no history. A sequential circuit's output depends on its inputs and on what it is already storing.


Adders are combinational; latches, flip-flops and counters are sequential. Almost every confusion in this topic comes from applying the reasoning of one family to the other.

Truth tables and simplification

A truth table is the definition of a combinational function; a Boolean expression is one of many ways to write it.


Simplification means finding a cheaper expression with the same table, and the identities that do the work are few: X + X′ = 1, X·1 = X, X + X = X, and the absorption rule X + X′Y = X + Y.


Work an example. Take F = A′B′C + A′BC + AB′C. Every term contains C, so factor it out: F = C(A′B′ + A′B + AB′).


Inside the bracket, the first two terms share A′ and their B factors are complementary, so they collapse to A′. That leaves A′ + AB′, which absorption turns into A′ + B′.


So F = C(A′ + B′), which by De Morgan is C·(AB)′, the function is true exactly when C is true and A and B are not both true.


Always confirm a simplification against the table rather than trusting the algebra.


Here the original has three true rows, all with C = 1 and (A, B) not both 1, and the simplified form reproduces exactly those; both forms are false on every remaining row, including C = 0 and the row A = B = C = 1. A simplification that changes even one row is not a simplification.

Arithmetic from gates

A half adder adds two bits. Its sum output is A ⊕ B and its carry is AB; the exclusive-or is the sum because the sum bit is 1 exactly when the inputs differ.


A half adder cannot directly serve a stage that must accept an incoming carry; the least-significant stage may use one when Cin is fixed at 0, and two half adders plus an OR gate can implement a full adder, the first adds A and B, the second adds Cin to that partial sum, and the OR gate combines the two carries.


A full adder fixes that with a third input. Its outputs are


Sum = A ⊕ B ⊕ Cin,     Cout = AB + Cin(A ⊕ B).


The carry expression reads directly: a carry leaves if both operand bits are 1, or if exactly one of them is 1 and a carry arrived. The equivalent form AB + ACin + BCin says the same thing as a majority function, the carry is 1 whenever at least two of the three inputs are 1.


Chaining n full adders, each stage's carry output feeding the next stage's carry input, gives a ripple-carry adder. It is simple and it is slow, because the most significant sum bit cannot be correct until a carry has propagated through every stage below it.

Storing one bit

Cross-coupling two NOR gates gives an SR latch: each gate's output feeds the other's input, so the pair has two stable configurations and will sit in either indefinitely. With S = R = 0 the latch holds whatever it holds; asserting S forces Q to 1 and asserting R forces Q to 0.


The arrangement has a defect that motivates everything built on top of it.


Asserting both inputs at once drives both outputs low, so Q and its supposed complement are equal, and when both inputs are released together, which of the two stable states the latch settles into depends on tiny differences in gate delay. That is a genuine race, not merely an undefined convention.


Excluding simultaneous assertion in settled Boolean logic and obtaining edge sensitivity take two distinct steps, and collapsing them is a common error.


First, a gated D latch derives both controls from a single data input qualified by an enable, commonly S = Enable·D and R = Enable·D′.


For settled ideal Boolean values, D and D′ are never both 1, so the two controls are not asserted together; and because the enable gates both, they can both be inactive, which gives the latch a hold state.


In physical circuits, inverter and gate delays can briefly assert both controls during a data transition; the implementation or input-timing constraints must address that hazard.


Driving R from a bare inverse of S would also exclude the forbidden combination, but it would force a write on every change of the data input and so destroy the hold, and it would not make the circuit edge-sensitive either.


Second, an edge-triggered D flip-flop adds the circuitry that edge sensitivity actually requires, a master–slave pair of gated latches enabled on opposite clock phases, or an equivalent edge-sensitive network, so that the stored value updates only at a clock transition.


Edge triggering is what makes large synchronous systems tractable: every element responds to the same clock edge, and the designer reasons about one clock period at a time.


Physical outputs still have finite clock-to-output delay and skew, so their transitions are near-simultaneous rather than perfectly simultaneous.

Counting

Wire a flip-flop to toggle on each clock edge and it divides the input frequency by two. Cascade the stages, each clocked by the previous stage's output, and you have a ripple counter whose stages divide by 2, 4, 8 and so on.


Feeding a 3-bit ripple counter at 8 MHz gives stage outputs at 4 MHz, 2 MHz and 1 MHz.


With n stages the counter passes through 2n states before repeating, so its modulus is a power of two unless it is deliberately truncated, usually by decoding an unwanted state and using it to clear every flip-flop at once.


The ripple counter's weakness is timing. Stages do not change together; each waits for the one below it, so after a clock edge the displayed value passes through intermediate codes that were never meant to appear.


If each flip-flop has a propagation delay of 9 ns, a three-stage ripple counter can take 27 ns to settle, and the counter presents transient intermediate codes during that window.


A sufficiently fast decoder can produce pulses for those codes; actual decoded outputs depend on decoder timing.


A synchronous counter clocks every flip-flop from the same signal and uses combinational logic to decide which should toggle. Its outputs therefore respond near-simultaneously to a common clock, removing cumulative stage-by-stage ripple delay.


Finite clock-to-output differences and clock skew remain, however, so combinational decoding can still glitch briefly; register or suitably strobe decoded outputs when glitch-free behaviour is required.

Errors worth guarding against

  • Verifying a simplified expression only on the rows that are convenient. Check the whole table, including rows where the original is false; checking only true rows cannot establish equivalence.
  • Treating a latch's hold condition as undefined. Holding is its normal, well-defined behaviour; the problematic input combination is the one that asserts both controls.
  • Assuming outputs of a ripple counter change simultaneously. They do not, and the difference is what limits the usable clock rate.
  • Quoting a maximum clock frequency without saying which delays were included. Propagation delay, gate delay in the toggle logic and flip-flop setup time are separate contributions.

A combinational network implements

F = A′B + AB + AB′

where a prime denotes complement. Which single gate produces the same output for every input combination?

Choose an answer

Create a free account to get started

Unlock full course notes by signing up

  • Video lessons taught by top educators
  • Practice questions with guided solutions
  • Written review notes for reference
  • Expert answers anytime from course tutors

Mark Yourself Question

  1. Grab a piece of paper and try this problem yourself.
  2. When you're done, check the "I have answered this question" box below.
  3. View the solution and report whether you got it right or wrong.

A four-bit ripple-carry adder is built from single-bit adder cells.

  1. Write the sum and carry expressions for a half adder, and explain in one sentence why a half adder cannot be used for every stage of the chain.
  2. Write the sum and carry-out expressions for a full adder, and state the majority-function reading of the carry.
  3. The chain is to be built as a uniform cascade of identical full-adder cells. How many full adders does it require, and what is applied to the carry input of the least significant stage?
  4. The adder is presented with A = 1011 and B = 0110, with the least significant carry input held at 0. Give the four-bit sum and the final carry-out, and show the carry at each stage boundary.

Create a free account to get started

Unlock full course notes by signing up

  • Video lessons taught by top educators
  • Practice questions with guided solutions
  • Written review notes for reference
  • Expert answers anytime from course tutors

An SR latch is built from two cross-coupled NOR gates, with outputs Q and Q′ and active-high inputs S and R.

Which input combination is disallowed, and for what reason?

Choose an answer

Create a free account to get started

Unlock full course notes by signing up

  • Video lessons taught by top educators
  • Practice questions with guided solutions
  • Written review notes for reference
  • Expert answers anytime from course tutors