---
title: Problem set
heading: "Problem set: digital design, timing and FPGAs"
eyebrow: D10 · Problem set
type: problems
---

::: hook
These problems draw on lessons 1 to 11: concurrency, FPGA fabric, datapaths and controllers, Verilog modules and always blocks, state machines, testbenches, timing and clock domains, pipelining, memories and FIFOs, and the UART. Each takes several steps; work them out on paper before entering the answers.
:::

::: pool
pick: 12

::: check
kind: parts
given: w = 1280 | 1920 | 3840; h = 720 | 1080 | 2160; f = 30 | 60; m = 9 | 25; c = 100 | 200

## A video filter processes {w} × {h} pixels at {f} frames per second, with {m} multiplications per pixel, on a {c} MHz FPGA.

::: part
answer: w*h*f*m/1e9
tolerance: 0.5%

### How many billion multiplications per second does it need?

::: misses
- [any] Pixels × frames × multiplies.
:::
:::

::: part
answer: ceil(w*h*f*m/(c*1e6))
tolerance: 0

### How many multipliers working in parallel?

::: misses
- [any] Rate ÷ clock, rounded up.
:::
:::
:::

::: check
kind: parts
given: n = 8 | 16 | 32; t = 50 | 100; L = 2 | 4

## An {n}-bit ripple-carry adder passes the carry through each bit in {t} ps, plus {L} levels of gates at each end costing {t} ps each.

::: part
answer: (n + 2*L)*t
unit: ps
tolerance: 0.5%

### What is its worst-case delay?

::: misses
- [any] n carry stages plus the end logic.
:::
:::

::: part
answer: (log(n)/log(2) + 2*L)*t
unit: ps
tolerance: 0.5%

### What would a lookahead adder with $\log_2 n$ carry levels take?

::: misses
- [any] Replace n with $\log_2 n$.
:::
:::
:::

::: check
kind: parts
given: n = 12 | 20 | 40; k = 4 | 6

## A {n}-input function that only ANDs its inputs is built from {k}-input LUTs; the device has 50,000 LUTs.

::: part
answer: ceil((n - 1)/(k - 1))
tolerance: 0

### How many LUTs does it take?

::: misses
- [any] $\lceil(n - 1)/(k - 1)\rceil$.
:::
:::

::: part
answer: 50000*2^k/8/1024
unit: KB
tolerance: 0.5%

### How much LUT configuration memory does the device hold?

::: misses
- [any] LUTs × $2^k$ bits.
:::
:::
:::

::: check
kind: parts
given: s = 6 | 11 | 25

## A controller has {s} states.

::: part
answer: ceil(log(s)/log(2))
tolerance: 0

### How many flip-flops does binary encoding need?

::: misses
- [any] $\lceil\log_2 s\rceil$.
:::
:::

::: part
answer: 2^ceil(log(s)/log(2)) - s
tolerance: 0

### How many codes are unused?

::: misses
- [any] $2^b - s$.
:::
:::

::: part
answer: s - ceil(log(s)/log(2))
tolerance: 0

### How many more flip-flops does one-hot use?

::: misses
- [any] s less the binary count.
:::
:::
:::

::: check
kind: parts
given: t = 5 | 20 | 100; f = 27 | 50 | 125

## A debounce counter must wait {t} ms on a {f} MHz clock, and a shift register of 32 stages runs on the same clock.

::: part
answer: ceil(log(t/1000*f*1e6)/log(2))
unit: bits
tolerance: 0

### How wide is the debounce counter?

::: misses
- [any] $\lceil\log_2(tf)\rceil$.
:::
:::

::: part
answer: 32*1000/f
unit: ns
tolerance: 0.5%

### How long does a bit take to pass through the shift register?

::: misses
- [any] 32 periods.
:::
:::
:::

::: check
kind: parts
given: b = 8 | 12 | 16; r = 10 | 1000; N = 1000 | 100000

## A {b}-bit × {b}-bit multiplier can be simulated at {r} thousand tests a second. A random testbench runs {N} tests.

::: part
answer: 2^(2*b)/(r*1000)
unit: s
tolerance: 0.5%

### How long would exhaustive testing take?

::: misses
- [any] $2^{2b}$ tests.
:::
:::

::: part
answer: (1 - exp(-N/2^(2*b)))*100
unit: %
tolerance: 1%

### What is the chance the random testbench hits one particular input pair?

::: misses
- [any] $1 - e^{-N/2^{2b}}$.
:::
:::
:::

::: check
kind: parts
given: c = 0.2 | 0.4; l = 2.5 | 4 | 7; s = 0.1 | 0.3; h = 0.1 | 0.2; w = 0.05 | 0.25

## A path has {c} ns clock-to-output, {l} ns of logic and {s} ns setup. A second, short path has the same {c} ns clock-to-output and a {w} ns wire into a flip-flop that needs {h} ns of hold.

::: part
answer: 1000/(c + l + s)
unit: MHz
tolerance: 0.5%

### What is the long path's maximum clock?

::: misses
- [any] 1 ÷ total.
:::
:::

::: part
answer: c + w - h
unit: ns
tolerance: 0.5%

### What is the short path's hold slack (negative for a violation)?

::: misses
- [any] Arrival after the edge less the hold time.
:::
:::
:::

::: check
kind: parts
given: t = 0.5 | 1 | 2; f = 100 | 250; d = 1 | 10

## A one-flip-flop synchronizer leaves {t} ns of settling time; τ = 50 ps, $T_0$ = 0.1 ns, the clock is {f} MHz and data changes {d} million times a second.

::: part
answer: exp(t/0.05)/(1e-10*f*1e6*d*1e6)
unit: s
tolerance: 1%

### What is its MTBF?

::: misses
- [any] $e^{t/\tau}/(T_0f_cf_d)$.
:::
:::

::: part
answer: 1000/f/0.05/ln(10)
tolerance: 0.5%

### How many powers of ten does a second flip-flop add (one more clock period of settling)?

::: misses
- [any] $T/(\tau\ln 10)$.
:::
:::
:::

::: check
kind: parts
given: L = 8 | 12 | 20; k = 4 | 6 | 10; o = 0.3 | 0.5; N = 20 | 100

## A {L} ns job is split into {k} equal stages, each with {o} ns of register overhead, and {N} items flow through.

::: part
answer: L/k + o
unit: ns
tolerance: 0.5%

### What is the clock period?

::: misses
- [any] L/k + overhead.
:::
:::

::: part
answer: (k + N - 1)*(L/k + o)/1000
unit: µs
tolerance: 0.5%

### How long do all {N} items take?

::: misses
- [N*(L/k + o)/1000] The first item takes k cycles to emerge.
- [any] $(k + N - 1)$ cycles.
:::
:::

::: part
answer: N*(L + o)/((k + N - 1)*(L/k + o))
tolerance: 0.5%

### What speedup is that over an unpipelined design (period L + {o} ns)?

::: misses
- [any] Unpipelined time ÷ pipelined time.
:::
:::
:::

::: check
kind: parts
given: l = 15 | 25; b = 10 | 20; p = 1 | 2 | 3

## In a five-stage processor, {l}% of instructions are loads followed by a dependent use (1 stall), and {b}% are taken branches costing {p} cycle(s) each.

::: part
answer: 1 + l/100 + b/100*p
tolerance: 0.5%

### What is the CPI?

::: misses
- [any] 1 + stall contributions.
:::
:::

::: part
answer: (b/100*p)/(l/100 + b/100*p)*100
unit: %
tolerance: 0.5%

### What share of the lost cycles comes from branches?

::: misses
- [any] Branch cycles ÷ all stall cycles.
:::
:::
:::

::: check
kind: parts
given: w = 2048 | 8192 | 32768; b = 9 | 18 | 36

## A memory holds {w} words of {b} bits.

::: part
answer: ceil(w*b/36864)
tolerance: 0

### How many 36-kilobit block RAMs at least?

::: misses
- [any] Bits ÷ 36,864, rounded up.
:::
:::

::: part
answer: round(log(w)/log(2))
unit: bits
tolerance: 0

### How many address bits?

::: misses
- [any] $\log_2 w$.
:::
:::
:::

::: check
kind: parts
given: B = 64 | 300 | 2000; r = 40 | 75 | 90; D = 32 | 128 | 512

## Bursts of {B} words arrive at 100 MHz into a FIFO of {D} words, drained at {r} MHz.

::: part
answer: B*(1 - r/100)
unit: words
tolerance: 0.5%

### How many words pile up?

::: misses
- [any] Burst × (1 − r/100).
:::
:::

::: part
answer: step(D - B*(1 - r/100))
tolerance: 0

### Does the FIFO hold them (1 for yes)?

::: misses
- [any] Compare with its depth.
:::
:::

::: part
answer: round(log(D)/log(2)) + 1
unit: bits
tolerance: 0

### How wide are its pointers, with the extra wrap bit?

::: misses
- [any] $\log_2 D + 1$.
:::
:::
:::

::: check
kind: parts
given: f = 12 | 27 | 100; b = 9600 | 57600 | 115200

## A {f} MHz FPGA runs a UART at {b} baud with 16× oversampling.

::: part
answer: round(f*1e6/(16*b))
tolerance: 0

### What divisor for the 16× tick?

::: misses
- [round(f*1e6/b)] That's without oversampling.
- [any] Clock ÷ (16 × baud), rounded.
:::
:::

::: part
answer: (f*1e6/(16*round(f*1e6/(16*b))) - b)/b*100
unit: %
tolerance: 2%

### What is the rate's error?

::: misses
- [any] (actual − wanted)/wanted.
:::
:::
:::

::: check
kind: parts
given: x = 5440307 | 10650259 | 11863347

## A RISC-V instruction is {x:hex8}.

::: part
answer: x - 128*floor(x/128)
tolerance: 0

### What is its opcode (bits 6 to 0), in decimal?

::: misses
- [any] The low 7 bits.
:::
:::

::: part
answer: floor(x/128) - 32*floor(x/4096)
tolerance: 0

### What is rd (bits 11 to 7)?

::: misses
- [any] Shift right 7, keep 5 bits.
:::
:::

::: part
answer: floor(x/32768) - 32*floor(x/1048576)
tolerance: 0

### What is rs1 (bits 19 to 15)?

::: misses
- [any] Shift right 15, keep 5 bits.
:::
:::
:::

::: check
kind: parts
given: k = 3 | 4 | 6; n = 5 | 10 | 50; f = 25 | 50

## A loop of {k} instructions runs {n} times between 3 setup and 6 closing instructions, on a single-cycle core at {f} MHz.

::: part
answer: 3 + k*n + 6
tolerance: 0

### How many instructions run?

::: misses
- [any] Setup + loop + closing.
:::
:::

::: part
answer: (3 + k*n + 6)/f
unit: µs
tolerance: 0.5%

### How long does it take?

::: misses
- [any] Instructions ÷ clock.
:::
:::
:::
:::
