electronics engineering
Course handbook · Fourth year
Digital Electronic Systems
Digital electronics: logic families, combinational and sequential circuits, memories and programmable logic.
- 8Topics
- 0Solved exercises
- 8Formula sheet
Free handbook generated from the lessons of the site and updated often, every time a lesson or an exercise changes: the latest version is always at www.electronics-engineering.com/handbook/digital-systems-electronic. Links work in the PDF too.
1Boolean algebra and logic minimisation
Digital circuits work with only two values, 0 and 1, and their behaviour is described by Boolean algebra. Designing a logic network means writing the function it must compute and simplifying it, because a shorter expression needs fewer gates, less area, less power and less delay. In this lesson we cover the axioms and theorems of Boolean algebra, canonical forms and the Karnaugh map method.
Operations and theorems
The basic operations are the logical product (AND,
or
), the logical sum (OR,
) and negation (NOT,
). The commutative, associative and distributive properties hold, with one surprise: in Boolean algebra both operations distribute, including
. Other useful identities:
| Name | OR form | AND form |
|---|---|---|
| identity | ||
| null element | ||
| idempotence | ||
| complement | ||
| absorption | ||
| De Morgan |
Every identity has a dual, obtained by swapping AND with OR and 0 with 1.
Theorem (De Morgan).
.
Proof. With two variables there are only four cases, and it is enough to check them all (proof by exhaustion, always possible in an algebra with finitely many values): for
both sides equal 1; in the other three cases at least one variable is 1, so
and the left side is 0, and so is the right side, because at least one of the two negated factors is 0. ∎
De Morgan has a fundamental practical consequence: with NAND gates alone (or NOR gates alone) any function can be built, and that is exactly how CMOS gates are made (Electronic Devices lesson on CMOS logic).
Canonical forms
Any function can be written starting from its truth table.
- Sum of products (SOP): for each row where the function is 1, write the product of the variables, negated where they are 0 (a minterm), and add them all. It is abbreviated with the list of row numbers:
. - Product of sums (POS): the dual, starting from the rows where the function is 0.
The canonical form is correct but long: a 4-variable function with 8 minterms needs 8 four-input AND gates and one eight-input OR.
Karnaugh maps
The simplification idea is the theorem
: two minterms differing in only one variable merge, and that variable disappears. The Karnaugh map lays out the truth table on a grid where adjacent cells differ in only one variable: rows and columns follow the Gray code (00, 01, 11, 10), and opposite edges are adjacent too, as if the map were wrapped on a torus.

The procedure.
- Enter the function’s 1s in the cells.
- Group the 1s into rectangles of 1, 2, 4, 8… adjacent cells, as large as possible; a 1 can belong to several groups.
- Each group of
cells eliminates
variables: those that do not change within the group remain. - The function is the sum of the group terms, chosen in minimum number to cover all the 1s.
Example.
. Minterms 5, 7, 13, 15 form a square in the middle of the map: in all of them
and
, while
and
change, so the group is
. Minterms 0, 2, 8, 10 are in the four corners, which are adjacent to each other: they have
and
, and give
. So
![]()
that is the function is 1 when
and
are equal: it is the complement of an XOR,
. Eight four-variable minterms reduce to a single XNOR gate.
Don’t-care conditions. Often some input combinations cannot occur (for example codes 10 to 15 in a circuit receiving BCD decimal digits). They are marked with an X on the map and can be treated as 1 or 0, whichever helps form larger groups.
Beyond maps
Maps work well up to 4 to 5 variables. For larger functions algorithms are used (Quine-McCluskey, Espresso), which today live inside logic synthesis tools: the designer describes the function in a language such as VHDL or Verilog (lesson on FPGAs) and the program finds the gate network, optimising area, delay and power.
2Logic levels, noise margins and delays
For Boolean algebra a signal is 0 or 1; for electronics it is a voltage, never exactly 0 or
, disturbed by noise, by drops along traces and by coupling with nearby lines. For a digital circuit to work you need to know which voltages are recognised as 0 and as 1, how much disturbance can be tolerated and how long a gate takes to respond. In this lesson we cover logic levels, noise margins, delays, power and the different kinds of output.
Logic levels
Every logic family specifies four voltages:
: the minimum voltage an output guarantees when high;
: the maximum voltage an output guarantees when low;
: the minimum voltage an input surely recognises as 1;
: the maximum voltage an input surely recognises as 0.
Between
and
is a forbidden zone: there the input may read anything, and a signal lingering there also makes both transistors of the CMOS input conduct, with abnormal current draw.

Noise margins
![]()
They are the largest disturbances that can be added to the signal without the next gate misreading it.
Example. For typical 3.3 V LVCMOS logic, with
V,
V,
V and
V:
V. A long trace picking up 0.5 V of disturbance from a nearby line is already out of specification.
Connecting different families. A 3.3 V output driving a 5 V input with
V is not safe: 3.3 V is below the threshold. Conversely a 5 V output can damage a 3.3 V input that is not tolerant. Level shifters are needed: dedicated chips, or a MOSFET with pull-up resistors for slow buses such as I²C.
Delays
A gate does not switch instantly. The propagation delay
is the time between the input crossing 50% of its swing and the output doing so;
and
are distinguished for the two transitions. The rise and fall times (between 10% and 90%) say how steep the edges are. As seen in the CMOS lesson, the delay is about
: it grows with the capacitance to be driven, that is with the number of inputs connected to the output (fan-out) and with trace length.
In modern integrated circuits gate delays are tens of picoseconds, and the interconnect often dominates: a long wire on the chip is a distributed RC line whose delay grows with the square of its length. That is why buffers are inserted along long connections.
Power
The power of a CMOS gate is almost entirely dynamic,
(proof in the CMOS logic lesson), plus a small static part due to leakage currents. Lowering the voltage is the most effective way to reduce power, which is why logic has moved from 5 V to 3.3, 1.8 V and below. Other techniques: stopping the clock of idle blocks (clock gating), cutting the supply of blocks that are off (power gating), lowering voltage and frequency when less computing power is needed.
Kinds of output
- Totem pole (push-pull): the normal CMOS output, which actively drives the line both to 0 and to 1. Two push-pull outputs tied together trying to force different values create a short circuit.
- Open drain (or open collector): the output can only pull the line to 0; an external pull-up resistor brings it to 1. Several outputs can share the same line: one going to 0 is enough to make the line 0 (a “wired” AND). This is the principle of the I²C bus and of shared interrupt lines. The price is a slow rising edge, set by the pull-up and the line capacitance.
- Three-state (tri-state): besides 0 and 1, the output can be disconnected (high impedance). Many outputs share a bus, and an enable signal decides who talks; the others must be in high impedance.
Inputs not to forget
A CMOS input left unconnected is neither 0 nor 1: it charges randomly and can oscillate, draw current and make the logic toggle. Every unused input must be tied to ground or to the supply, directly or through a resistor. Push-buttons need a pull-up or pull-down, and produce bounce (dozens of transitions in the first milliseconds), removed with a Schmitt trigger and an RC filter or in software.
3Combinational networks
A combinational network is a circuit whose output depends only on its inputs at that instant, with no memory. Some combinational blocks occur so often that they are standard components: multiplexers, decoders, encoders, adders, comparators. In this lesson we look at them and discover a problem that truth tables hide: spurious transitions caused by delays.
The multiplexer
A
:1 multiplexer (MUX) picks one of
inputs and routes it to the output, according to
select signals.

For the 4:1:
![]()
Each term is active for a single combination of the selects. The multiplexer is a universal block: tying the data inputs to constants 0 and 1, a MUX with
selects implements any function of
variables, just by writing the truth table column on the inputs. This is exactly how the look-up tables (LUTs) of FPGAs work.
The demultiplexer does the reverse: it routes one input to one of
outputs.
Decoders and encoders
- An
-to-
decoder activates just one of its outputs, the one whose number is given by the inputs: each output is a minterm. It is used to select one of many devices (the right memory chip based on the address, the row of a memory array) and to drive seven-segment displays. - An encoder does the inverse: given which of
lines is active, it produces its number. The priority encoder also handles several active lines, returning the most important one: it is the heart of interrupt controllers.
Adders and comparators
The full adder and the ripple-carry and carry-lookahead adders are in the Computer Architecture lesson on arithmetic. An equality comparator between two
-bit words compares the bits in pairs with XNOR gates and ANDs the results:
if all bits match. A magnitude comparator (
) is obtained with a subtraction and a check of the sign or carry.
Spurious transitions
The truth table describes the network in steady state, but gates have delays, and different paths from input to output can have different delays.
Example.
, with
: the function is always 1, whatever
. When
goes from 1 to 0, the term
goes to 0 immediately, while
goes to 1 only after the delay of the inverter producing
. For an instant both terms are 0, and the output has a brief pulse to 0 (a glitch). This is a static hazard.
On the Karnaugh map the hazard is easy to see: the two groups
and
are adjacent but do not overlap, and the move from one to the other is not covered. Adding the consensus term
, which covers the transition, removes the hazard:
is logically identical but glitch-free.
In synchronous circuits (next lessons) combinational glitches are usually harmless, because flip-flops read the outputs only on the clock edge, once they have settled. They are dangerous, however, when the combinational output directly drives something edge-sensitive: a clock, an asynchronous reset input, an interrupt. Rule of thumb: never use the output of a combinational network as a clock.
Networks in practice
Today almost nobody draws combinational networks gate by gate. The behaviour is described in a hardware description language, for example assign y = sel[1] ? (sel[0] ? i3 : i2) : (sel[0] ? i1 : i0); in Verilog, and the synthesis tool chooses the implementation with the cells of the available technology, also checking the delays. Understanding the basic blocks is still essential to read the results, estimate area and delay and find bugs.
4Latches and flip-flops
A combinational network forgets everything as soon as its inputs change. To count, remember a state, build registers and processors, memory elements are needed: circuits that hold a bit until we decide to change it. In this lesson we see how feedback creates memory in the SR latch, the D latch, the edge-triggered D flip-flop, its timing constraints and the phenomenon of metastability.
The SR latch
Two NOR gates connected in a loop: the output of each is an input of the other.

Operation.
: the lower gate has an input at 1, so
; the upper gate has both inputs at 0, so
. The latch is set.
: by symmetry
: the latch is reset.
: each gate acts as an inverter of the other. The combinations
and
are both stable, and the latch holds whichever it was in. This is memory.
: both outputs at 0, and when the two inputs return to 0 together the final state is unpredictable. It is the forbidden combination.
The principle is deep: two inverters in a loop have two stable equilibrium states, and the state they are in is the stored information. An SRAM memory cell is exactly this, plus two transistors to read and write it.
The D latch
To remove the forbidden combination and control when data is stored: a single data input
and an enable input
. With
the latch is transparent:
follows
. With
the latch is closed and holds the last value. The problem with transparency is that, while
stays at 1, every change of
reaches the output, and in a circuit with feedback the signal could go round several times in the same period.
The D flip-flop
The D flip-flop changes state only at the instant of the clock’s rising edge:
takes the value
has at that moment and holds it for the whole period, whatever
does meanwhile. It is built from two D latches in cascade (master-slave) enabled by opposite clock phases: with the clock low the first is transparent and follows
, the second is closed; on the rising edge the first closes, freezing the value, and the second opens and passes it to the output. There is never a transparent path from
to
.
The D flip-flop is the memory element of almost all synchronous digital circuits. The other types (JK, T) are derived from it with a little logic: for example a T flip-flop, which toggles its state on every edge, is a D with
, that is a divide-by-two frequency divider.
Timing constraints
For the flip-flop to capture the data correctly,
must be stable:
- for a time
before the edge (the setup time); - for a time
after the edge (the hold time).
After the edge, the output changes with a delay
(clock to output). These three parameters, tens of picoseconds in modern integrated circuits, set the maximum frequency of a synchronous circuit, as we will see in the lesson on timing.
Metastability
What happens if
changes right inside the setup and hold window? The internal latch can stop at an unstable equilibrium point halfway between 0 and 1, like a ball on top of a hill, and stay there for an unpredictable time before falling one way or the other. This is metastability.
It cannot be avoided when sampling an asynchronous signal (a push-button, data arriving from another device with a different clock), because sooner or later it will change at the wrong moment. It can, however, be made extremely unlikely. The probability that the metastable state lasts longer than a time
decreases as
, with
a flip-flop constant of tens of picoseconds, and the mean time between failures is
![]()
Example. With
ps,
ps, a 100 MHz clock and data changing at 1 MHz: allowing
ns to resolve, the MTBF is about
s, less than three days; with
ns it becomes
s, almost four million years. The exponential makes every extra nanosecond enormously effective.
Hence the universal rule: an asynchronous signal goes through a synchroniser, two (or three) flip-flops in cascade on the same clock, before being used. The first may go metastable, but it has a whole period to resolve before the second reads it.
5Sequential networks and state machines
Flip-flops are used to build sequential networks: circuits whose output depends not only on the current inputs but on past history, summarised in a state. Registers, counters, protocol controllers, a processor’s control unit are all synchronous sequential networks. In this lesson we cover registers and counters and the general method for designing a finite state machine, with a complete example.
Registers and shift registers
An
-bit register is made of
D flip-flops on the same clock: at each edge it stores a word. Connecting each flip-flop’s output to the next one’s input gives a shift register: at each edge the bits move one position. It converts data from parallel to serial and back (it is the heart of UART, SPI and all serial links), delays a signal by a precise number of cycles, and generates pseudo-random sequences (with XOR feedback, the LFSR, used for GPS codes and for chip testing).
Counters
An
-bit synchronous binary counter is a register whose input is the current value plus 1: it counts from 0 to
and starts again. The least significant bit changes at every edge, the next every two, and so on: each bit halves the frequency. A modulo-N counter resets when it reaches
: counting the seconds of a clock needs 6 bits (
).
Asynchronous (ripple) counters, in which each flip-flop is clocked by the previous one’s output, use less logic but the bits do not change together: for an instant the counter passes through wrong values. Modern designs almost always use synchronous counters.
Finite state machines
A finite state machine (FSM) is described by:
- a finite set of states, stored in a register;
- a next-state function, which computes the next state from the current state and the inputs (combinational logic);
- an output function.
In a Moore machine the output depends only on the state; in a Mealy machine it also depends on the inputs. Moore machines are easier to verify and have outputs stable for the whole cycle; Mealy machines react one cycle earlier and often need fewer states.
A complete example: recognising the sequence 101
We want a circuit with a serial input
, one bit per clock cycle, and an output
that is 1 when the last three bits received are 1, 0, 1 (overlapping too: in 10101 the sequence appears twice).
1. The state diagram. Each state remembers how much of the sequence has already arrived:
: nothing useful;
: the last bit was 1;
: the last two were 1, 0;
: the last three were 1, 0, 1, output 1 (Moore machine).

The transitions are found by asking, for each state and each input, which is the longest prefix of the sequence that matches the end of what has been received. For example in
(last bits 101) a 0 gives …1010, which ends with 10: we go to
, not
.
2. The state table.
| State | |||
|---|---|---|---|
| 0 | |||
| 0 | |||
| 0 | |||
| 1 |
3. Encoding. Four states need 2 flip-flops. With the binary encoding
,
,
,
(bits
), the next-state functions follow from the table and are simplified with Karnaugh maps:
![]()
Check row by row: for example from
(
) with
:
,
, that is
, correct. (Here
has a simple meaning:
remembers the last bit received.)
4. The circuit. Two D flip-flops, the gates implementing
and
, and one AND gate for the output.
Other encodings are possible: one-hot uses one flip-flop per state (4 here), with simpler, faster logic; it is the usual choice in FPGAs, where flip-flops are plentiful. Synthesis tools choose the encoding themselves, starting from the description in a hardware description language.
Reset
Every state machine must start from a known state: at power-up the flip-flop contents are random. A reset signal brings the state register to the initial state. If the reset is asynchronous, its release must still be synchronised with the clock (with the same synchroniser seen for metastability), otherwise different flip-flops might leave reset in different cycles and the machine would start from an unexpected state.
6Timing and clock domains
In a synchronous circuit all flip-flops change state together, on the edge of a single clock, and between one edge and the next the combinational networks have time to compute the new values. This discipline makes huge designs manageable, but it imposes precise timing constraints. In this lesson we derive a circuit’s maximum frequency, the hold constraint, the effect of clock skew, pipelining and passing data between different clock domains.
The path between two flip-flops

On edge
the first flip-flop changes its output after
; the new value goes through the logic in at most
; it must reach the second flip-flop at least
before edge
.
Theorem (setup constraint). The circuit works if
![]()
The proof is the reasoning just made: data launched on one edge must be stable at the next flip-flop’s input before the following edge.
Example.
ns,
ns,
ns:
ns,
MHz. The path with the largest sum is the critical path, and it sets the frequency of the whole circuit: it does not matter how fast all the others are.
The hold constraint
There is also the opposite risk: that the new data arrives too early and overwrites the value the next flip-flop is still capturing on the same edge. The data at the second flip-flop must stay stable for
after the edge:
![]()
The hold constraint does not depend on frequency: if it is violated, the circuit does not work even with a very slow clock. It typically happens with two flip-flops connected directly, with no logic in between, and with the clock reaching the second one late. Design tools fix it by inserting delay buffers on paths that are too short.
Clock skew
The clock does not arrive at all flip-flops at the same instant: the distribution network has different delays to different points of the chip. The difference is the skew
. If the clock reaches the receiving flip-flop later, the setup constraint improves and the hold constraint worsens; if earlier, the opposite:
![]()
Then there is jitter, the random variation of the period from cycle to cycle, which always eats into the margin. In processors the clock network is designed as a balanced tree or a grid, and it consumes a significant share of the chip’s power.
Pipelining
If the critical path is too slow for the desired frequency, it is broken by inserting registers in the middle: this is pipelining, the same seen for processors in Computer Architecture. A 4 ns logic split into two 2 ns stages runs at twice the frequency: each data item takes two cycles (the latency grows) but a new one enters every cycle (the throughput doubles). It is the main technique for high frequencies in FPGAs and signal-processing circuits.
The reverse is possible when an operation is too long but rare: a multicycle path is declared, allowed two or more periods, and the verification tools take it into account.
Timing verification
A chip has millions of paths. They are not verified by simulation, but with static timing analysis: a program computes the maximum and minimum delays of every path, including process, voltage and temperature variations (the “corners”), and reports any negative margins (slack). The designer declares the constraints: the frequency of each clock, input and output delays, exceptions.
Clock domains
Different systems have different clocks: a USB interface, the memory, the processor. A signal passing from one domain to another is, for the receiving domain, asynchronous, and must be handled as seen in the lesson on flip-flops:
- a single bit goes through a two-flip-flop synchroniser;
- a multi-bit word cannot be synchronised bit by bit, because the bits might be captured in different cycles and form a value that never existed. So an asynchronous FIFO is used, with its pointers in Gray code (only one bit changes at each increment, so a value captured mid-transition is still either the old or the new one), or a handshake protocol that holds the data still until the other side confirms it has read it.
Clock domain crossing errors are among the most insidious in digital electronics: they do not show up in simulation, appear rarely and only on some devices, which is why dedicated verification tools exist.
7Semiconductor memories
Semiconductor memories are the most-produced integrated circuits: the RAM of computers, the flash of phones and USB sticks, the caches inside processors. They are regular arrays of millions or billions of identical cells, and the cell type decides speed, density, power and whether data survive with the power off. In this lesson we look at the organisation of a memory and at SRAM, DRAM and flash cells.
Organisation

The cells are arranged in a square array, more compact than a long row. The address splits into two parts:
- the row address goes to a decoder (lesson on combinational networks) that activates a single word line: all the cells of that row connect to their bit lines;
- the column address drives a multiplexer that picks, among all the bit lines, those of the requested data.
The signals on the bit lines are tiny (the cell is minuscule and the line long and capacitive), so at the bottom of each column there is a sense amplifier, usually a latch that amplifies a difference of a few millivolts up to the logic level.
SRAM
The SRAM (static) cell is made of six transistors: two CMOS inverters in a loop, the latch seen in the lesson on flip-flops, and two access transistors connecting it to the two bit lines (true and complement) when the word line is active. As long as it is powered it holds the data with no further help, reads non-destructively and very quickly: it is the memory of caches and registers. Its drawback is area: six transistors per bit. That is why caches are a few megabytes even in the largest processors.
DRAM
The DRAM (dynamic) cell is as simple as can be: one transistor and one capacitor. The bit is the capacitor’s charge, a few tens of femtofarads. To read it, the word line is activated and the capacitor shares its charge with the bit line, moving its voltage by a few millivolts; the sense amplifier detects the shift.
Two consequences:
- reading is destructive: after reading, the amplifier must write the row back;
- the capacitor slowly discharges through transistor and junction leakage: every cell must be periodically read and rewritten (refresh), typically every 64 ms. With 8192 rows to refresh, one refresh command every 7.8 µs.
DRAM is dense and cheap, and it is the main memory of every computer and phone. Modern DRAMs (DDR4, DDR5, LPDDR) are organised in many independent banks and transfer data on both clock edges, at thousands of megatransfers per second, but the time to access a new row is still around 15 ns: that is why caches are needed.
Flash
Non-volatile memories keep data without power. In flash each cell is a MOSFET with a second gate, the floating gate, completely insulated in the oxide. Applying high voltages (10 to 20 V) pushes electrons into the floating gate by tunnelling, or removes them; the trapped charge shifts the transistor’s threshold voltage, and reading whether it conducts at an intermediate voltage gives the bit. The electrons stay trapped for years.
- NOR flash connects cells in parallel: fast random reads, used for microcontroller code, which is executed directly from it.
- NAND flash connects cells in series in strings: much denser and cheaper, read and written by pages (a few kilobytes) and erased by blocks (hundreds of kilobytes). It is the memory of SSDs, cards and phones.
To increase density each cell stores several bits by distinguishing several charge levels (MLC 2 bits, TLC 3, QLC 4) and cells are stacked vertically, more than two hundred layers (3D NAND). The price is endurance: every program and erase cycle damages the oxide a little, and a cell withstands from a few thousand to a hundred thousand cycles. The SSD controller spreads writes over all cells (wear levelling) and corrects errors with powerful codes.
Comparison
| Memory | Cell | Volatile | Speed | Density | Use |
|---|---|---|---|---|---|
| SRAM | 6 transistors | yes | highest | low | caches, registers |
| DRAM | 1 transistor + 1 capacitor | yes, with refresh | high | high | main memory |
| NOR flash | 1 floating-gate transistor | no | fast read, slow write | medium | microcontroller code |
| NAND flash | cells in series, several bits per cell | no | by pages | highest | SSDs, phones, cards |
| EEPROM | 2 transistors | no | slow | low | small configuration data |
New technologies try to combine speed and non-volatility: magnetic (MRAM), phase-change and resistive memories. MRAM is already used in some microcontrollers and in the caches of low-power systems.
8Programmable logic and HDLs
A custom integrated circuit (ASIC) is the most efficient way to implement a digital function, but designing and producing it costs millions and takes months, and once made it cannot be fixed. FPGAs (Field Programmable Gate Arrays) are chips full of programmable logic blocks and connections, configured in a few seconds to become any digital circuit. In this lesson we see how they are built, how a circuit is described with a hardware description language and the design flow.
The logic block

The heart of an FPGA is the look-up table (LUT): a small memory of
bits and a multiplexer with
select inputs. As seen in the lesson on combinational networks, a multiplexer with the right constants on its data inputs implements any function of its select variables: a 4-input LUT can be any of the
functions of 4 variables, by writing the truth table column into the memory. Modern FPGAs use 6-input LUTs.
Each LUT is followed by a flip-flop, which can be used or bypassed: with thousands or millions of these blocks, combinational and sequential networks of any size are built.
The rest of the FPGA
- Programmable interconnect: a network of lines and switches, controlled by memory cells, linking the blocks together. It takes most of the chip’s area and delay.
- Input and output blocks, configurable for different electrical standards (levels, impedances, serial transceivers at tens of gigabits per second).
- Dedicated blocks, far more efficient than LUTs for their tasks: block memories, multiply-accumulate units (DSP) for signal processing, clock generators (PLLs), and in some models entire ARM processors.
The configuration sits in SRAM cells and is lost at power-off: at power-up the FPGA loads it from an external flash memory. There are also FPGAs with internal flash configuration, which start instantly.
When to use them. FPGAs are used for ASIC prototypes, for low-volume products (instruments, telecom equipment, aerospace systems), when standards change and the circuit must be updated in the field, and when massively parallel processing with deterministic latency is needed: dozens of simultaneous filtering channels, video processing, high-speed motor control, computation acceleration in data centres. Compared with an ASIC they use more power, cost more per unit and are slower; compared with a processor they do in parallel and in one cycle what software would do in sequence.
Hardware description languages
A circuit with millions of gates is not drawn: it is described in a language such as VHDL or Verilog (and its successor SystemVerilog). They look like programming languages, but they describe hardware, in which everything happens in parallel. An 8-bit counter with reset and enable, in Verilog:
module counter (
input wire clk,
input wire rst, // synchronous reset
input wire en, // enable
output reg [7:0] q
);
always @(posedge clk) begin
if (rst)
q <= 8'd0;
else if (en)
q <= q + 8'd1;
end
endmoduleThe always @(posedge clk) block describes flip-flops changing on the rising edge; the <= (non-blocking) assignment means that all registers update together, as in real hardware. The synthesis tool recognises in these lines a register of 8 flip-flops, an adder and two multiplexers.
The design flow
- Description of the behaviour in HDL.
- Simulation: a testbench, also written in HDL, applies inputs and checks outputs. This is where most bugs are found, and where most time is spent.
- Synthesis: the tool translates the description into a network of LUTs, flip-flops and dedicated blocks.
- Place and route: each element is assigned to a physical block of the chip and the connections are routed.
- Static timing analysis (lesson on timing): checking that every path meets the required frequency.
- Programming the chip with the configuration file (bitstream) and testing on hardware, with integrated logic analysers recording internal signals.
The same flow, with cell libraries in place of LUTs and extra steps for fabrication, is used to design ASICs and processors. The decisive difference is that on an FPGA a bug is fixed in minutes, while on a chip already produced it can cost months and millions: that is why ASIC designs are almost always tried out first on large FPGAs.
∑Formula sheet
Boolean algebra and logic minimisation
Karnaugh maps
![]()
Logic levels, noise margins and delays
Noise margins
![]()
Combinational networks
The multiplexer
![]()
Latches and flip-flops
Metastability
![]()
Sequential networks and state machines
A complete example: recognising the sequence 101
![]()
Timing and clock domains
The path between two flip-flops
![]()
The hold constraint
![]()
Clock skew
![]()