---
title: Problem set 8
heading: "Problem set 8: state machines, datapaths and clock domains"
eyebrow: C7 · Problem set 8
type: problems
---

::: hook
These problems use lessons 37 to 42: finite state machines, their analysis and their design, register-transfer design, crossing clock domains, and the state machine lab.
:::

::: pool
pick: 12

::: check
kind: parts
given: s = 5 | 9 | 17 | 30; i = 1 | 2

## A state machine has {s} states and {i} input bits.

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

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

::: misses
- [any] $\lceil\log_2s\rceil$.
:::
:::

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

### How many more does one-hot need?

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

::: check
kind: parts
given: L = 3 | 5 | 9

## A detector flags an {L}-bit pattern, overlaps allowed.

::: part
answer: L + 1
tolerance: 0

### How many states as a Moore machine?

::: misses
- [any] $L + 1$.
:::
:::

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

### How many flip-flops as a binary-encoded Mealy machine?

::: misses
- [any] $\lceil\log_2L\rceil$.
:::
:::
:::

::: check
kind: boolean
vars: Q1, Q0, X
answer: X
ops: and, or, not

## In the 101 detector (S0 = 00, S1 = 01, S2 = 10, S3 = 11), write $Q_0^+$.

::: right
Right: $Q_0^+ = X$. Every state goes to S1 or S3 on a 1 and to S0 or S2 on a 0.
:::

::: misses
- [any] Not yet. Look at the low bit of every next state.
:::
:::

::: check
kind: parts
given: n = 8 | 16 | 32; T = 1 | 2.5; r = 0.3 | 0.6

## A shift-and-add multiplier for n = {n} bits adds in {T} ns with {r} ns of register overhead.

::: part
answer: n*(T + r)
unit: ns
tolerance: 0.5%

### How long does one product take?

::: misses
- [any] $n(t_\text{add} + t_\text{reg})$.
:::
:::

::: part
answer: 1000/(n*(T + r))
tolerance: 0.5%

### How many products per second, in millions?

::: misses
- [any] The reciprocal.
:::
:::
:::

::: check
kind: parts
given: k = 3 | 5; t = 2 | 3; r = 0.2 | 0.4; N = 100 | 10000

## An operation of {k} steps of {t} ns each runs {N} times, with {r} ns of overhead per clock.

::: part
answer: N*(k*t + r)/1000
unit: µs
tolerance: 0.5%

### How long does a single-cycle design take?

::: misses
- [any] $N(kt + r)$.
:::
:::

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

### A k-stage pipeline?

::: misses
- [any] $(N + k - 1)(t + r)$.
:::
:::
:::

::: check
kind: parts
given: a = 40 | 70 | 91; b = 12 | 15 | 21

## The subtraction GCD machine starts with A = {a}, B = {b}.

::: part
answer: floor(a/b)
tolerance: 0

### How many subtractions from A happen before A first drops below B?

::: misses
- [any] Repeated subtraction is division.
:::
:::

::: part
answer: a - b*floor(a/b)
tolerance: 0

### What's left in A then?

::: misses
- [any] The remainder.
:::
:::
:::

::: check
kind: parts
given: T = 1 | 2; s = 0.05 | 0.1; t = 25 | 50

## A synchronizer clocked every {T} ns uses flops with τ = {t} ps and {s} ns setup.

::: part
answer: exp((T - s)*1000/t)
tolerance: 0.5%

### By what factor does one extra stage raise the MTBF?

::: misses
- [any] $e^{(T - t_\text{su})/\tau}$.
:::
:::

::: part
answer: (T - s)*1000/t/ln(10)
tolerance: 0.5%

### How many decades is that?

::: misses
- [any] Divide the exponent by $\ln10$.
:::
:::
:::

::: check
kind: parts
given: B = 80 | 400; fw = 150 | 200; fr = 60 | 100

## A writer at {fw} MHz sends bursts of {B} words; the reader runs at {fr} MHz.

::: part
answer: B*(1 - fr/fw)
tolerance: 0.5%

### What FIFO depth does the burst need?

::: misses
- [any] $B\left(1 - \frac{f_r}{f_w}\right)$.
:::
:::

::: part
answer: B/fw
unit: µs
tolerance: 0.5%

### How long does the burst last?

::: misses
- [any] $\frac{B}{f_w}$.
:::
:::
:::

::: check
kind: parts
given: fs = 20 | 100; fd = 50 | 200

## A four-phase handshake with two-flop synchronizers passes words from {fs} MHz to {fd} MHz.

::: part
answer: 4*1000/fd + 4*1000/fs
unit: ns
tolerance: 0.5%

### About how long per word?

::: misses
- [any] $4T_\text{dst} + 4T_\text{src}$.
:::
:::

::: part
answer: 1000/(4*1000/fd + 4*1000/fs)
tolerance: 0.5%

### About how many million words per second?

::: misses
- [any] The reciprocal.
:::
:::
:::

::: check
kind: boolean
vars: S1, S0, E
answer: ~S1 & S0 & E | S1 & ~S0
ops: and, or, not

## A controller asserts done in state 10, and asserts load in state 01 when E is 1. Write the OR of load and done.

::: right
Right: $\bar S_1S_0E + S_1\bar S_0$.
:::

::: misses
- [any] Not yet. Combine the two conditions.
:::
:::

::: check
kind: parts
given: v = 3 | 7 | 11

## A 4-bit pointer steps from {v} to the next value (each of these values ends in a run of 1s).

::: part
answer: 1
tolerance: 0

### How many bits change in Gray code?

::: misses
- [any] Gray code changes one bit per step.
:::
:::

::: part
answer: 3 + step(v - 7) - step(v - 11)
tolerance: 0

### How many change in plain binary?

::: misses
- [any] The run of 1s and the 0 above it all flip.
:::
:::
:::

::: check
kind: parts
given: n = 4 | 6; m = 3 | 5

## Two state machines have {n} and {m} states.

::: part
answer: n*m
tolerance: 0

### At most how many state pairs can an equivalence check visit?

::: misses
- [n + m] It searches pairs, one state from each.
- [any] $nm$.
:::
:::

::: part
answer: n*m*2
tolerance: 0

### How many transitions can it follow, with one input bit?

::: misses
- [any] Two per pair.
:::
:::
:::

::: check
kind: parts
given: N = 2 | 5 | 10; T = 5 | 20

## A pulse of one fast-clock period, {T} ns, must cross into a domain whose clock period is {N} times longer.

::: part
answer: N*T
unit: ns
tolerance: 0.5%

### How long is the slow domain's clock period?

::: misses
- [any] $NT$.
:::
:::

::: part
answer: 1/N*100
unit: %
tolerance: 0.5%

### What's the chance a raw pulse lands on a slow clock edge and is seen at all?

::: misses
- [any] The pulse covers $\frac1N$ of the slow period.
:::
:::
:::

::: check
kind: parts
given: k = 2 | 3 | 4

## A multi-cycle datapath shares one ALU across {k} steps of 4 ns, with 0.5 ns overhead per clock; a single-cycle version has {k} ALUs.

::: part
answer: k*4.5
unit: ns
tolerance: 0.5%

### What's the multi-cycle time per result?

::: misses
- [any] $k(4 + 0.5)$.
:::
:::

::: part
answer: k*4 + 0.5
unit: ns
tolerance: 0.5%

### And the single-cycle time per result?

::: misses
- [any] $4k + 0.5$.
:::
:::
:::

::: check
given: s = 0..7 int
answer: 2*(s - 4*floor(s/4)) + 1 - floor(s/4)
base: 2
width: 3

## A 3-bit Johnson counter has $D_2 = Q_1$, $D_1 = Q_0$ and $D_0 = \bar Q_2$. From state $Q_2Q_1Q_0$ = {s:bin3}, what's the next state?

::: right
Right: {answer}. Shift left, and bring in the inverse of the old top bit.
:::

::: misses
- [any] Not yet. $Q_2^+ = Q_1$, $Q_1^+ = Q_0$, $Q_0^+ = \bar Q_2$.
:::
:::
:::
