How Clocks Turn Manual Logic into Automated Calculation?

Published: (January 5, 2026 at 08:22 AM EST)
6 min read
Source: Dev.to

Source: Dev.to

How We Perform Addition

To understand how a computer works, let’s first look at how we add a list of numbers, such as [24, 34, 77].

  1. Add the first two numbers:
    24 + 34 = 58.
  2. Store the intermediate result (58) in memory or write it down.
  3. Add the final number to the intermediate result:
    58 + 77 = 135.

In this process we used our mind as a “memory” to hold the number 58.

Designing a Simple Circuit

Circuit Components

  • 8‑bit switch – why do we need it?
  • Adder – performs the addition.
  • Latch (memory) – holds the intermediate result.

Addition Sequence Using the Circuit

StepLatch (memory)InputAdder CalculationAction
Start0240 + 24 = 24Store 24 in the latch by pressing the switch (closes the circuit).
Next243424 + 34 = 58Store 58 in the latch.
Next587758 + 77 = 135Store 135 in the latch.

In theory this looks perfect, but a real circuit won’t work this way.

The Problem: Feedback‑Loop Error

Electricity travels incredibly fast. When you press a manual switch, the gate stays open for as long as your finger is on the button. Even a tiny press (e.g., 0.1 s) is seen by the CPU as a “High” signal for thousands of nanoseconds.

Because the latch output is fed back into the adder, a feedback loop occurs:

TimeSituationResult
0 sButton pressed.0 (memory) + 24 (input) = 24.
0.1 s (still pressing)Latch sees the High signal, adds the same 24 again.24 + 24 = 48.
0.2 sRepeats.48 + 24 = 72.

Before you can even lift your finger, the circuit has added the same number hundreds of times, producing a giant, incorrect number. This is the Feedback Loop Error.

Root cause: the circuit stays “open” for too long. We need it to open only once per click, regardless of how long the button is held.

Understanding the Button Press (Scenarios)

Press #Hold TimeRelease Time
11 s2 s
23 s1 s
30.5 s

If plotted, the waveform looks like this:

  • High State (top) – button pressed.
  • Low State (bottom) – button not pressed.

The Four Stages of a Signal

  1. Rising Edge – the exact moment the button is pressed (0 → 1).
  2. High Level – duration while the button is held down.
  3. Falling Edge – the exact moment the button is released (1 → 0).
  4. Low Level – duration while the button is not pressed.

The Rising Edge and Falling Edge occur only once per press, no matter how long the button is held. If we make the circuit react only to the Rising Edge, we get exactly one addition per click.

Latch vs. Flip‑Flop

FeatureLatch (Level‑Triggered)Flip‑Flop (Edge‑Triggered)
ActivationActive for the entire High levelActivates only on the Rising Edge
ControlHard to control (continuous)Precise, single‑pulse operation

Solution: replace the latch with a Flip‑Flop and drive it with the button’s CLK (clock) pin.

The Solution: Edge Triggering

Redesigning the Circuit

  1. Replace the latch with a Flip‑Flop.
  2. Connect the adder’s output directly to the Flip‑Flop’s data input.
  3. Connect the button to the Flip‑Flop’s CLK pin.

Operation Sequence

StepFlip‑Flop StateInputAdder CalculationAction
Start0240 + 24 = 24On the Rising Edge, the Flip‑Flop captures 24 and ignores the rest of the press.
Next243424 + 34 = 58Capture 58 on the next Rising Edge.
Next587758 + 77 = 135Capture 135 on the next Rising Edge.

Some CPU circuits (e.g., counters) are built from flip‑flops.

Automating with a Clock Signal

Clock Cycle Overview

CycleStageDescription
1Adder StageRising Edge – inputs are presented to the adder.
High Level – adder performs the addition.
Falling Edge – adder finishes computation (propagation delay).
Low Level – circuit waits, allowing the result to stabilize.
2Capture StageRising Edge – flip‑flop latches the adder’s result and the system moves to the next number.
High/Falling/Low Levels – preparation for the next addition.

The Brain: Control Unit

In a real CPU, the Control Unit acts like a conductor. Using an internal counter, it tracks clock cycles and tells every part of the computer exactly when to push data and when to save it.

Why an Adder Is Not Edge‑Triggered

Unlike latches or flip‑flops, an adder has no clock pin. It does not wait for a signal to start adding; it is always “on.” As soon as any input changes, the output (sum) begins changing immediately.

Delay – the only timing consideration for an adder is its propagation delay, the time it takes for the new sum to become stable after the inputs change. This delay is why we need separate clocked stages (adder → capture) to ensure reliable operation.

Propagation Delay and Clock Speed

The output isn’t “instant” because of propagation delay – the physical time it takes electricity to travel through all the transistors inside the adder.
We must make sure our clock isn’t too fast, or the flip‑flop might try to store the result before the adder has finished the calculation!

Adding the Numbers [24, 34, 77]

The computer breaks the work into cycles. Each cycle follows the “heartbeat” of the clock.

CyclePhaseWhat Happens
1 – The WorkRising edgeThe flip‑flop starts at 0. The system pushes 0 and the first input (24) into the adder.
High / Falling / Low levelsThe adder performs the addition. The system waits during the Low level to ensure the propagation delay is over and the result (24) is stable.
2 – The SaveRising edgeThe flip‑flop captures the 24 from the adder. The control unit then selects the next number (34) for the next step.
High / Falling / Low levelsNothing (the data is simply stored).
3 – The WorkRising edgeThe flip‑flop (now holding 24) and the new input (34) are sent to the adder.
High / Falling / Low levelsThe adder works through the addition. By the end of the Low level, the result 58 is ready.
4 – The SaveRising edgeThe flip‑flop captures 58. The control unit selects the final number (77).
5 – The Final WorkRising edgeThe flip‑flop sends 58 and the input 77 to the adder.
High / Falling / Low levelsThe adder completes the calculation.
6 – The Final ResultRising edgeThe flip‑flop captures the final total: 135.

Controlled Automation

By the end of these cycles, the addition is perfectly finished. This is controlled automation: every step has its own specific “moment” on the clock wave, so operations never collide or interfere with each other.

The primary job of the clock is synchronization.

  • Clock speed must be chosen based on the slowest circuit in the system. In our example, the adder is the most complex part.
  • If the clock is set too fast, the flip‑flop might try to capture data before the adder has finished its work.
  • The Low level of the clock must be long enough to cover the adder’s propagation delay, guaranteeing that every captured result is 100 % accurate.

Controlled Automation (Repository)

The above description outlines the timing and synchronization strategy used in the repository.

Back to Blog

Related posts

Read more »

The RGB LED Sidequest 💡

markdown !Jennifer Davishttps://media2.dev.to/dynamic/image/width=50,height=50,fit=cover,gravity=auto,format=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%...

Mendex: Why I Build

Introduction Hello everyone. Today I want to share who I am, what I'm building, and why. Early Career and Burnout I started my career as a developer 17 years a...