Salta al contenuto
Note per Studenti Digital Systems - Exam of 11 July 2022 Report

Digital Systems - Exam of 11 July 2022

Questa pagina non ha ancora la versione ripasso: qui sotto c'è il testo completo.

In questa pagina 24

Exam of the second sitting (11 July 2022) of the equivalent Italian-language course Circuiti Digitali of the Engineering degrees at the University of Padova, translated into English. The paper has two parts: 20 multiple-choice quizzes (three options each, only one correct; wrong answers carry a negative score, the sheet does not give the value) and 3 exercises to be solved on the sheet. The sheet states neither the points of the single exercises nor the duration; calculators, notes, books and colleagues are not allowed, and nobody may leave the room.

Source and checks: the questions are translated faithfully from the original paper. The official solution is not public: every answer below has been derived from the course theory and checked with scripts (truth tables, minimisation compared with a symbolic algebra system, simulation of the two state machines, number conversions). Where a quiz is ambiguous it is said explicitly. The VHDL code of exercise 3 could not be compiled (no VHDL simulator was available): it was checked by hand against the transition table and by a Python model of the three processes.

Quiz 1

Which of the following represents the highest level of abstraction?

  • a. logic gates
  • b. microarchitecture
  • c. register transfer logic (RTL)
Show the result

b.

Show the full solution

The levels of abstraction, from the most abstract to the most concrete, are: algorithm, programming language, operating system, ISA, microarchitecture, register transfer (RTL), logic gates, transistor circuit. Of the three options the microarchitecture comes first, so it is the highest. Typical mistake: choosing RTL because it sounds "more abstract" than gates, forgetting that the microarchitecture describes the whole processor and RTL its register movements. Theory: Digital Systems - Signals, Binary Information and Abstraction LevelsA digital system processes discrete quantities; a binary one encodes them with two voltage ranges (0 and 1), the input range being wider than the output range, which gives noise margins and a regenerative property. Precision depends on the number of bits. A computer is memory, CPU (control unit plus datapath) and I/O. Design proceeds through abstraction levels from algorithm to transistor, following a flow from specification to verification.Digital Systems - Signals, Binary Information and Abstraction Levels →.

Quiz 2

In a system with even parity, which of the following codes signals an error?

  • a. 00100010
  • b. 11111111
  • c. none of the other answers
Show the result

c. (both codes are acceptable)

Show the full solution

Quiz 3

What is the decimal equivalent of the BCD number 00101000?

  • a. 23+25=402^3+2^5=40
  • b. 28
  • c. it is not a valid BCD number
Show the result

b. (2828)

Show the full solution

Quiz 4

The Unicode encoding UTF-8:

  • a. always uses a single byte to encode all alphanumeric characters
  • b. always uses two bytes to encode all alphanumeric characters
  • c. none of the other answers
Show the result

c.

Show the full solution

UTF-8 is a variable-length code: it uses 1 to 4 bytes per code point. The first 128 code points (the ASCII characters, which include the letters without accents and the digits) take one byte, but other alphanumeric characters (accented letters, Greek or Cyrillic letters, and so on) take two or more bytes. So a. ("always one byte for all") and b. ("always two bytes") are both false. Theory: Binary Codes - BCD, ASCII, Unicode, Parity and GrayAn n-bit code distinguishes 2^n elements. BCD encodes each decimal digit on 4 bits (1010 to 1111 unused; it differs from the plain binary of the number). ASCII uses 7 bits for 128 characters; Unicode UTF-8 uses 1 to 4 bytes and is ASCII compatible. A parity bit detects errors on an odd number of bits. Hamming distance is the number of differing bits. Gray code makes consecutive numbers differ by one bit and is built by reflection or with g_i = b_i xor b_(i+1).Binary Codes - BCD, ASCII, Unicode, Parity and Gray →.

Quiz 5

The Hamming distance between the decimal numbers 8 and 4 is:

  • a. 1
  • b. 2
  • c. 3
Show the result

b. (22)

Show the full solution

Quiz 6

Which of the following statements is correct?

  • a. 1 xnor 0 xor 1=11\ \text{xnor}\ 0\ \text{xor}\ 1=1
  • b. 1 xnor 0 xor 1=01\ \text{xnor}\ 0\ \text{xor}\ 1=0
  • c. none of the other answers
Show the result

a.

Show the full solution

XNOR is 1 when the two inputs are equal, XOR is 1 when they are different. Reading from left to right: (1 xnor 0)=0(1\ \text{xnor}\ 0)=0 because the inputs differ; then 0 xor 1=10\ \text{xor}\ 1=1. If the operators were grouped from the right the result would be the same: 0 xor 1=10\ \text{xor}\ 1=1 and 1 xnor 1=11\ \text{xnor}\ 1=1. In both cases the value is 11, so a. is right and b. is wrong. Theory: Logic Gates, Gate Delay and Universal GatesAND, OR, NOT implement the Boolean operations; NAND, NOR, XOR and XNOR derive from them. Every function is described by a truth table with 2^n rows. Multi-input XOR is the odd-parity function. An ideal gate has zero delay; a real gate has a propagation delay t_G (different for 0 to 1 and 1 to 0), so the output changes t_G after the input. NAND and NOR are each universal.Logic Gates, Gate Delay and Universal Gates →.

Quiz 7

De Morgan's theorem states that:

  • a. x+y+z‾=x‾⋅y‾⋅z‾\overline{x+y+z}=\overline{x}\cdot\overline{y}\cdot\overline{z}
  • b. x+y+z‾=x‾⋅y‾+z‾\overline{x+y+z}=\overline{x}\cdot\overline{y}+\overline{z}
  • c. x+y+z‾=x‾⋅y⋅z‾\overline{x+y+z}=\overline{x}\cdot y\cdot\overline{z}
Show the result

a.

Show the full solution

The complement of a sum is the product of the complements of all the variables: x+y+z‾=x‾ y‾ z‾\overline{x+y+z}=\overline x\,\overline y\,\overline z. Option b. changes the last AND into an OR; option c. forgets to complement yy. A truth-table check of the three options confirms that only a. is equal to the left-hand side for all 8 input combinations. Theory: Boolean Algebra - Axioms, Theorems and Function ComplementBoolean algebra works on two-valued variables with AND, OR, NOT. Fundamental identities (identity element, idempotence, complement, commutative, associative, both distributive laws) come in dual pairs; De Morgan, absorption, adjacency and consensus are the main theorems, proved by perfect induction or algebraically. The complement of a function is obtained with De Morgan or with the dual plus literal negation. Cost is measured in literals or gate inputs.Boolean Algebra - Axioms, Theorems and Function Complement →.

Quiz 8

Which of the following expressions represents a canonical form of a function of three Boolean variables x,y,zx,y,z?

  • a. x+xy‾ z+yzx+\overline{xy}\,z+yz
  • b. x+y+zx+y+z
  • c. (xyz)(xy‾ z)(xyz)(\overline{xy}\,z)
Show the result

b. (x+y+zx+y+z is the maxterm M0M_0, i.e. a canonical product of sums with a single factor)

Show the full solution

A canonical form is a sum of minterms (SOP) or a product of maxterms (POS): every term contains all the variables, direct or complemented. Option a. contains the terms xx and yzyz, which do not use all three variables, so it is not canonical. Option c. is a product of product terms; it is not a sum of minterms nor a product of maxterms, and it is also identically 00 (it contains x⋅x‾x\cdot\overline{x}), so it is not a canonical form of anything. Option b. is a sum containing xx, yy and zz exactly once: it is the maxterm M0M_0, the canonical POS of the function that is 00 only for xyz=000xyz=000. Warning: the question is not very precise, because a "product with a single factor" is a degenerate case; b. is the only sensible answer anyway. Theory: Canonical Forms - Minterms, Maxterms, SOP and POSA minterm is a product containing every variable exactly once and is 1 on a single truth-table row; a maxterm is the dual sum and is 0 on a single row; with n variables there are 2^n of each and the complement of minterm i is maxterm i. Canonical SOP = sum of minterms of rows with F=1; canonical POS = product of maxterms of rows with F=0. They come mechanically from the truth table but are redundant, so they are the starting point for minimization. SOP and POS are two-level circuits.Canonical Forms - Minterms, Maxterms, SOP and POS →.

Quiz 9

With nn variables, how many minterms are possible?

  • a. nn
  • b. 2n−12^n-1
  • c. none of the other answers
Show the result

c. (there are 2n2^n)

Show the full solution

Quiz 10

A maxterm represents:

  • a. a row of the truth table
  • b. a column of the truth table
  • c. none of the other answers
Show the result

a.

Show the full solution

Quiz 11

The following VHDL code fragment

vhdl
process(clk, rst)
begin
    if (rst = '1') then
        a <= '0';
    elsif (clk'event and clk = '0') then
        a <= b;
    end if;
end process;

where aa and bb are internal signals of type std_logic:

  • a. is useful to define a positive edge-triggered flip-flop with synchronous reset
  • b. is useful to define a negative edge-triggered flip-flop with asynchronous reset
  • c. is useful to define a positive edge-triggered flip-flop with asynchronous reset
Show the result

b.

Show the full solution

Two details decide the answer.

  • Reset: rst is in the sensitivity list and is tested before the clock condition, outside the clock branch. The reset acts as soon as rst becomes '1', whatever the clock does: it is asynchronous. A synchronous reset would have only clk in the list and the test on rst inside the clock branch.
  • Edge: clk'event and clk = '0' is true when the clock has just changed and its new value is '0', i.e. on the falling edge: the flip-flop is negative edge-triggered. With '1' it would be positive edge-triggered.

Typical mistake: reading clk'event and ignoring the value '0'. Theory: VHDL - Latches, Flip-Flops and ResetsIn VHDL a memory element is a process in which some branch does not assign the signal: the D latch is process(D,C) with if C='1' then Q<=D, the positive-edge-triggered flip-flop is process(CLK) with if CLK'event and CLK='1'. Asynchronous reset: RST is in the sensitivity list and tested first (if RST='1' ... elsif clock edge); synchronous reset: only CLK in the list and RST tested inside the clock-edge branch, so a clock edge is needed for it to act. The testbench of a synchronous circuit has a process generating the clock and one applying inputs away from the active edge.VHDL - Latches, Flip-Flops and Resets →.

Quiz 12

A structural VHDL description:

  • a. always leads to a more optimised synthesis than a behavioral description
  • b. uses exclusively Boolean equations
  • c. none of the other answers
Show the result

c.

Show the full solution

Quiz 13

Let CC be the 2's complement of MM on nn bits; which of the following properties is true?

  • a. M+C=2nM+C=2^n
  • b. M+C=2n+1M+C=2^n+1
  • c. M−C=2nM-C=2^n
Show the result

a.

Show the full solution

Quiz 14

In a ripple adder, overflow occurs when:

  • a. the carry of the full adder of the most significant bit and the one immediately before it are equal
  • b. the carry of the full adder of the most significant bit and the one immediately before it are different
  • c. none of the other answers
Show the result

b.

Show the full solution

For numbers in 2's complement the overflow is V=cn−1⊕cnV=c_{n-1}\oplus c_n: the carry entering the most significant bit and the carry leaving it must be different. If they are equal the result is representable (a final carry out is simply discarded). Example on 4 bits: 0111+00010111+0001 has carry into the last bit 11 and carry out 00, different: overflow (7+1=87+1=8 does not fit). Theory: Binary Adders and SubtractorsHalf adder: S = X xor Y, C = XY. Full adder with carry in Z: S = X xor Y xor Z, C = XY + XZ + YZ = G + PZ with P = X xor Y, G = XY; two half adders and an OR. The n-bit ripple carry adder chains n full adders, so delay grows linearly with n. Adder-subtractor: XOR of each B bit with a control S, which is also the carry in, computes A+B or A+not B+1 = A-B. The 2-bit multiplier uses 4 ANDs and 2 half adders.Binary Adders and Subtractors →, Signed Numbers, Complement Arithmetic and OverflowUnsigned subtraction is correct without borrow out; otherwise the result M-N+2^n is wrong. One's complement is 2^n-1-N (bitwise inversion); two's complement is 2^n-N (one's complement plus 1). Signed numbers: sign-magnitude (two zeros, symmetric range) or two's complement (one zero, range -2^(n-1) to 2^(n-1)-1, MSB weight -2^(n-1)). In two's complement addition and subtraction are the same adder: A-B = A + not B + 1, carry out discarded. Overflow: unsigned if carry out is 1 in an addition; signed if the carry into the sign bit differs from the carry out of it.Signed Numbers, Complement Arithmetic and Overflow →.

Quiz 15

The setup time of a flip-flop:

  • a. depends only on the flip-flop
  • b. depends on the logic downstream of the flip-flop
  • c. depends on the logic upstream of the flip-flop
Show the result

a.

Show the full solution

The setup time tst_s is the minimum time the data input must be stable before the active clock edge: it is a parameter of the flip-flop itself (its internal master latch), given in the data sheet. The logic before or after the flip-flop does not change tst_s; it only determines how much time is left (the slack) in the constraint T≥tpd,FF+tCOMB+tsT\ge t_{pd,FF}+t_{COMB}+t_{s}. Typical mistake: confusing the parameter with the constraint it appears in. Theory: Timing of Sequential Systems - Setup, Hold and Maximum Clock FrequencyA flip-flop stores the right value only if its input is stable for the setup time before and the hold time after the clock edge, and its output changes after the propagation delay. In a synchronous circuit the clock period must satisfy T >= t_pd,FF + t_COMB + t_s,FF + t_slack, which fixes the maximum frequency; slowing the clock cures setup violations but not hold violations, which require t_pd,FF,min + t_COMB,min >= t_h. Clock skew modifies both constraints.Timing of Sequential Systems - Setup, Hold and Maximum Clock Frequency →.

Quiz 16

In an RS latch made with NOR gates, the combination R=1R=1, S=1S=1 brings the output QQ to:

  • a. '0'
  • b. an intermediate value between '0' and '1'
  • c. '1'
Show the result

a. ('0')

Show the full solution

In the NOR latch Q=R+Q‾‾Q=\overline{R+\overline Q} and Q‾=S+Q‾\overline Q=\overline{S+Q}. With R=S=1R=S=1 each NOR has a 11 on one input, so both outputs are 00: Q=Q‾=0Q=\overline Q=0. A logic value is produced (never an intermediate level), but it violates the requirement that Q‾\overline Q be the complement of QQ: this is the forbidden input combination, and the behaviour after going back to SR=00SR=00 is unpredictable. Theory: Sequential Systems - State, Latches and Flip-FlopsA sequential circuit has outputs that depend on the inputs and on the state held in memory elements; it is a combinational network with flip-flops in a feedback loop, where present state is the flip-flop outputs and next state is their inputs. Synchronous circuits update only on the clock edge. The SR latch (NOR) sets, resets, holds, and forbids S=R=1; the D latch is transparent while C=1; the edge-triggered D flip-flop is two D latches in cascade (master-slave) and samples D only on the active clock edge, with Q(t+1)=D(t).Sequential Systems - State, Latches and Flip-Flops →.

Quiz 17

The program counter PC:

  • a. at every clock cycle is always updated with PC+1
  • b. none of the other answers
  • c. at every clock cycle is updated with the opcode of the next instruction
Show the result

b.

Show the full solution

Quiz 18

In an interrupt priority management system based on a daisy chain:

  • a. none of the other answers
  • b. the CPU determines the peripheral with the highest priority
  • c. two interrupts can be served in parallel if they are on opposite sides of the chain
Show the result

a.

Show the full solution

In a daisy chain the priority is given by the position of the devices in the chain: the grant signal travels along the chain and the first requesting device (the closest to the CPU) takes it. The priority is therefore fixed by the wiring and not decided by the CPU, so b. is false. Interrupts are handled one at a time: no parallel service, wherever the devices are, so c. is false. Parallel handling belongs to the parallel priority scheme with a priority encoder. Theory: Programmed I-O and InterruptsIn programmed I/O the CPU polls the device in a busy-wait loop and wastes most cycles; with interrupts the interface raises a signal when data are ready, the CPU suspends its work, runs a service routine and returns. Interrupts can be vectored (the device supplies the address of its routine) or non-vectored; with several devices a priority scheme is needed, by software polling, by hardware daisy chain (priority = position in the chain, no parallel handling) or by parallel priority with a priority encoder and a mask register.Programmed I-O and Interrupts →.

Quiz 19

In the absence of conditional branches, a 4-stage pipeline:

  • a. always executes 4 instructions per clock cycle
  • b. executes at most 4 instructions per clock cycle
  • c. executes at least 4 instructions per clock cycle
Show the result

b.

Show the full solution

With 4 stages at most 4 instructions are in the pipeline at the same time, one per stage, and in steady state one instruction is completed per cycle. "Always" and "at least" are false: at the start (the pipeline fills) and in the presence of data hazards (stalls, bubbles) not all the stages are busy, and removing the conditional branches only removes the control hazards. Only "at most 4" is always true. Note: strictly speaking the instructions completed per cycle are at most one; the wording means instructions in execution, and b. is the only sustainable option anyway. Theory: Pipelining and HazardsA pipeline splits execution into stages separated by registers (IF, DOF, EX, WB) working in parallel on different instructions; latency stays the same while throughput grows by less than the number of stages (flip-flop delays, slowest stage). With k stages and N instructions k+N-1 cycles are needed. Hazards stall the pipeline: data hazards (operand not yet written; fixes are NOPs, stalls and forwarding) and control hazards (branches; fixes are NOPs or branch prediction with bubbles).Pipelining and Hazards →.

Quiz 20

In how many distinct locations of a 2-way set-associative cache with 16-bit words can a datum coming from the main memory be stored?

  • a. 22=42^2=4
  • b. 2⋅1=22\cdot1=2
  • c. 2⋅16=322\cdot16=32
Show the result

b. (22)

Show the full solution

In a kk-way cache the address fixes the set, and inside the set the datum can go in any of the kk ways: here k=2k=2, so exactly 2 locations (a word is a single location per way, so 2⋅1=22\cdot 1=2). The word width (16 bit) is irrelevant for counting locations, which excludes c.; 222^2 has no meaning here. For comparison: a direct-mapped cache gives 1 location, a fully associative one gives all the lines of the cache. Theory: Memory Hierarchy and Cache MemoryMemories form a hierarchy (small fast SRAM, larger slower DRAM, huge slow disks) which works because programs reuse data close in time and in space (locality). A cache hit or miss gives an average access time t_hit plus miss rate times miss penalty; placement can be direct mapped (index = low address bits, tag = high bits), fully associative (tag = whole address, compared in parallel by an associative memory) or k-way set associative (a block can sit in k locations of one set).Memory Hierarchy and Cache Memory →.

Exercise 1 (points not stated)

Synthesise the logic function a>ba>b, where a=a1a0a=a_1a_0 and b=b1b0b=b_1b_0 are two unsigned positive integers on two bits, with a1a_1 and b1b_1 the most significant bits, using Karnaugh maps. Report the truth table of the function, the Karnaugh map with the groupings used to simplify the function, and the final equation obtained.

Show the result

The function is 11 for six of the 16 input combinations: (a,b)=(1,0),(2,0),(2,1),(3,0),(3,1),(3,2)(a,b)=(1,0),(2,0),(2,1),(3,0),(3,1),(3,2). Minimal sum of products, three groups: y=a1b1‾+a1a0b0‾+a0b1‾ b0‾y=a_1\overline{b_1}+a_1a_0\overline{b_0}+a_0\overline{b_1}\,\overline{b_0} (minimal product of sums, five factors: y=(a1+a0)(a1+b1‾)(a0+b1‾)(a1+b0‾)(b1‾+b0‾)y=(a_1+a_0)(a_1+\overline{b_1})(a_0+\overline{b_1})(a_1+\overline{b_0})(\overline{b_1}+\overline{b_0})).

Show the full solution

Step 1: truth table. The function has 4 inputs, so the table has 24=162^4=16 rows. y=1y=1 when the number a=2a1+a0a=2a_1+a_0 is greater than b=2b1+b0b=2b_1+b_0 (see Digital Systems - Signals, Binary Information and Abstraction LevelsA digital system processes discrete quantities; a binary one encodes them with two voltage ranges (0 and 1), the input range being wider than the output range, which gives noise margins and a regenerative property. Precision depends on the number of bits. A computer is memory, CPU (control unit plus datapath) and I/O. Design proceeds through abstraction levels from algorithm to transistor, following a flow from specification to verification.Digital Systems - Signals, Binary Information and Abstraction Levels → and Number Systems and Base ConversionsA number in base r is the sum of a_i r^i with digits from 0 to r-1. Conversions: base r to decimal by weighted sum; decimal to base r by successive divisions (integer part, remainders read bottom-up) and successive multiplications (fractional part, integer parts read top-down); binary to octal or hexadecimal by groups of 3 or 4 bits starting from the radix point. Binary sum, difference and product follow the decimal rules with borrows and shifted partial products.Number Systems and Base Conversions → for the weights of the bits).

a1a0a_1a_0 b1b0b_1b_0 aa bb yy
00 00 0 0 0
00 01 0 1 0
00 10 0 2 0
00 11 0 3 0
01 00 1 0 1
01 01 1 1 0
01 10 1 2 0
01 11 1 3 0
10 00 2 0 1
10 01 2 1 1
10 10 2 2 0
10 11 2 3 0
11 00 3 0 1
11 01 3 1 1
11 10 3 2 1
11 11 3 3 0

There are no don't-care conditions: all 16 combinations are valid inputs. The six 1s are the minterms m4,m8,m9,m12,m13,m14m_4,m_8,m_9,m_{12},m_{13},m_{14} (index =8a1+4a0+2b1+b0=8a_1+4a_0+2b_1+b_0).

Step 2: Karnaugh map. Rows a1a0a_1a_0 and columns b1b0b_1b_0, both in Gray order 00,01,11,1000,01,11,10, so that neighbouring cells (also those on opposite edges) differ in one variable (Karnaugh Maps and Two-Level MinimizationA Karnaugh map is the truth table arranged in a grid with rows and columns in Gray code, so that adjacent cells (also across opposite edges) differ in one variable. Groups of 2^k ones eliminate k variables and give a product. A prime implicant is a maximal group, an essential one is the only cover of some minterm; the minimum cover has all essentials plus few other primes. For POS, group the zeros. Don't cares may be used as 1 or 0. XOR functions have a checkerboard map and do not simplify.Karnaugh Maps and Two-Level Minimization →):

a1a0\b1b0a_1a_0\backslash b_1b_0 00 01 11 10
00 0 0 0 0
01 1 0 0 0
11 1 1 0 1
10 1 1 0 0

Step 3: groups. Three groups cover all the 1s, each as large as possible:

  • Group A, 4 cells: rows 1111 and 1010 (i.e. a1=1a_1=1) and columns 0000 and 0101 (i.e. b1=0b_1=0). The variables that stay constant are a1=1a_1=1 and b1=0b_1=0: product a1b1‾a_1\overline{b_1}. It means "the high bit of aa is 1 and the high bit of bb is 0, so a≥2>ba\ge2>b".
  • Group B, 2 cells: row 1111 and the columns 0000 and 1010. The two columns are adjacent across the edge of the map (they differ only in b1b_1). Constant: a1=1a_1=1, a0=1a_0=1, b0=0b_0=0: product a1a0b0‾a_1a_0\overline{b_0}.
  • Group C, 2 cells: column 0000 and the rows 0101 and 1111 (adjacent, they differ in a1a_1). Constant: a0=1a_0=1, b1=0b_1=0, b0=0b_0=0: product a0b1‾ b0‾a_0\overline{b_1}\,\overline{b_0}.

All the three groups are essential: the cells (10,00)(10,00) and (11,01)(11,01) belong only to A, the cell (11,10)(11,10) only to B, the cell (01,00)(01,00) only to C. The cell (11,00)(11,00) is in all three groups and is covered more than once, which is allowed. No group covers a 0.

Step 4: equation. y=a1b1‾+a1a0b0‾+a0b1‾ b0‾y=a_1\overline{b_1}+a_1a_0\overline{b_0}+a_0\overline{b_1}\,\overline{b_0} Meaning: aa wins either with the high bit, or, when the high bits are equal, with the low bit. The second form y=a1b1‾+(a1⊙b1) a0b0‾y=a_1\overline{b_1}+(a_1\odot b_1)\,a_0\overline{b_0} (with ⊙\odot the XNOR) is equivalent (checked by the script) and is the usual comparator equation, but it needs an XNOR gate; the minimal two-level form is the one above.

Product of sums (optional). Grouping the 0s of the map (the complement is y‾\overline y, then apply De Morgan) gives y=(a1+a0)(a1+b1‾)(a0+b1‾)(a1+b0‾)(b1‾+b0‾)y=(a_1+a_0)(a_1+\overline{b_1})(a_0+\overline{b_1})(a_1+\overline{b_0})(\overline{b_1}+\overline{b_0}): it has more factors than the SOP has terms, so the SOP is the better two-level form here (Karnaugh Maps and Two-Level MinimizationA Karnaugh map is the truth table arranged in a grid with rows and columns in Gray code, so that adjacent cells (also across opposite edges) differ in one variable. Groups of 2^k ones eliminate k variables and give a product. A prime implicant is a maximal group, an essential one is the only cover of some minterm; the minimum cover has all essentials plus few other primes. For POS, group the zeros. Don't cares may be used as 1 or 0. XOR functions have a checkerboard map and do not simplify.Karnaugh Maps and Two-Level Minimization →).

Checks. A script compared the equation with the truth table on all 16 rows and with the minimal form computed by a symbolic algebra system (identical); it also verified that every group contains only 1s and that each of the three is essential.

Typical mistakes: writing the columns in binary order 00,01,10,1100,01,10,11 instead of Gray order (the groups no longer correspond to adjacent cells); forgetting the group that wraps around the edge (group B); using a≥ba\ge b (then also the equal cases would be 1); swapping the roles of aa and bb in the table.

Exercise 2 (points not stated)

Draw the state diagram, without equivalent states, complete with all the transitions and all the signals, for an automatic gate. Show clearly the input and output signals in the diagram, using the names given in the text.

The system has the following inputs:

  • btn of one bit, on which a pulse lasting one clock cycle is generated every time the button of the gate remote control is pressed. For simplicity the remote control only allows to open the gate when it is completely closed; btn is ignored if the gate is already open or moving.
  • finecorsa (limit switch) of two bits, which is '11' when the gate is completely open, '00' when it is completely closed, '10' when it is moving

and must drive the following output:

  • motore (motor) of two bits, which controls the gate motor with the following scheme: '01' = open, '10' = close, '00' = stop motor.

The controller must open the gate when a pulse is detected on the line btn and close it again after 2 clock cycles have passed from the complete opening (i.e. from when the gate is stopped). The motor must be stopped when the gate must not move.

Show the result

Moore machine with 5 states (no two of them equivalent), initial state CLOSED:

state motore next state
CLOSED 00 OPENING if btn=1, otherwise CLOSED
OPENING 01 OPEN1 if finecorsa=11, otherwise OPENING
OPEN1 00 OPEN2 (always)
OPEN2 00 CLOSING (always)
CLOSING 10 CLOSED if finecorsa=00, otherwise CLOSING
Show the full solution

Step 1: type of machine and signals. Inputs: btn (1 bit) and finecorsa (2 bits); output: motore (2 bits). The output depends only on what the gate is doing (opening, closing, stopped), so a Moore machine is the natural choice: the output is written inside each state (Finite State Machines - AnalysisAnalysing a synchronous sequential circuit means deriving from the circuit the flip-flop input equations (next state) and output equations, the state table (2^(m+n) rows for m flip-flops and n inputs), the state diagram (circles are states, arrows carry input/output) and a timing simulation. Mealy: output depends on state and input (written on the arrows, may change between clock edges); Moore: output depends only on the state (written in the circle, changes only at the clock edge). Two states are equivalent if they give the same outputs and lead to equivalent states, and can be merged to save flip-flops.Finite State Machines - Analysis →, Finite State Machines - SynthesisSynthesis of a synchronous sequential circuit follows specifications, state diagram, state table (merging equivalent states), binary state encoding, choice of D flip-flop, flip-flop input and output equations, minimisation, circuit and verification. A state summarises the useful part of history; a sequence recogniser has one state per recognised prefix, reusing states for overlaps. A reset gives a known initial state. Gray encoding (minimum flip-flops) versus one-hot (one flip-flop per state, simpler logic): for the 1101 recogniser Gray costs about half.Finite State Machines - Synthesis →).

Step 2: states. We need to remember what the controller is doing, since btn and finecorsa alone do not say it (for example finecorsa=10 means "moving" but not whether the gate is opening or closing):

  • CLOSED, motor stopped (motore=00), waiting for the button;
  • OPENING, motore=01, until finecorsa=11;
  • OPEN1 and OPEN2, motor stopped (motore=00): they count the 2 clock cycles of waiting. Two cycles need two states in a row, because a Moore machine can only count by moving through states;
  • CLOSING, motore=10, until finecorsa=00.

Step 3: no equivalent states. Two states are equivalent if they have the same output and, for every input, equivalent next states. Here the three states with motore=00 are different: CLOSED can stay in itself for ever (if btn=0); OPEN1 always goes to OPEN2 (output 00) and only after that to CLOSING; OPEN2 goes to CLOSING (output 10) at the next cycle whatever the input. So after one clock cycle the output sequences differ, and no state can be removed. A script ran the standard partition-refinement procedure on the table and obtained 5 classes for 5 states.

Step 4: transitions.

  • CLOSED: btn=1 gives OPENING; btn=0 stays. finecorsa is not looked at (it is '00' in this state).
  • OPENING: the gate is moving, finecorsa goes from '00' to '10' and finally to '11'. When finecorsa=11 (completely open) go to OPEN1; otherwise stay. btn is ignored (as the text says).
  • OPEN1: next state OPEN2, whatever the inputs; btn is ignored.
  • OPEN2: next state CLOSING, whatever the inputs.
  • CLOSING: when finecorsa=00 go to CLOSED; otherwise stay. Just after the start of the closing finecorsa is still '11' or '10': the test is on '00' only, so the machine stays in CLOSING in both cases. btn is ignored.

Description to redraw the diagram: five circles, each with the name of the state and, below, the value of motore; an incoming arrow marks CLOSED as the initial state. Arrows: CLOSED to OPENING labelled btn=1; a loop on CLOSED labelled btn=0; OPENING to OPEN1 labelled finecorsa=11; a loop on OPENING labelled finecorsa≠\ne11; OPEN1 to OPEN2 and OPEN2 to CLOSING without label (always); CLOSING to CLOSED labelled finecorsa=00; a loop on CLOSING labelled finecorsa≠\ne00.

Step 5: simulation. A script coupled the machine with a model of the gate (4 steps of travel, finecorsa computed from the position) and pressed btn at the cycles 2, 5 and 9. The first pulse opens the gate; the pulses at 5 (gate moving) and 9 (gate open, waiting) are ignored:

cycle 2 3 4 5 6 7 8 9 10 11-13 14 15
state CLOSED OPENING OPENING OPENING OPENING OPENING OPEN1 OPEN2 CLOSING CLOSING CLOSING CLOSED
btn 1 0 0 1 0 0 0 1 0 0 0 0
finecorsa 00 00 10 10 10 11 11 11 11 10 00 00
motore 00 01 01 01 01 01 00 00 10 10 10 00

The gate is detected open at cycle 7; the motor is stopped in the two cycles 8 and 9, and the closing starts at cycle 10. In the last cycle of the closing (cycle 14) the motor is still driven, for one cycle after finecorsa has become 00: this is the natural delay of a Moore machine, which reacts to the limit switch one clock cycle later.

Note on the reading of the text. "2 cycles after the complete opening" has been read as two clock cycles with the motor stopped (OPEN1 and OPEN2) after the cycle in which finecorsa=11 is detected. If the first of the two cycles is counted as the cycle of detection itself, one waiting state is enough (4 states in total); the text does not allow to exclude this reading, so the choice should be stated clearly in the answer.

Typical mistakes: a single OPEN state with no way to count two cycles; no distinction between OPENING and CLOSING (the same finecorsa=10 would be ambiguous); btn considered in the states where it must be ignored; outputs written on the arrows of a Moore diagram (they go inside the states); no initial state; using names different from btn, finecorsa, motore, which the text imposes.

Exercise 3 (points not stated)

Describe in VHDL the finite state machine with inputs xx and yy and output ww, having the following state diagram. In all the cases not indicated, the system does not change state. Separate in the code the memory elements from the purely combinational parts.

State diagram (described in words; the original is a drawing): four circles, each with the value of the two-bit output ww inside: S0S_0 (w=00w=00), SAS_A (w=01w=01), S2S_2 (w=11w=11), SBS_B (w=10w=10). An arrow coming from outside and labelled rst=1rst=1 points to S0S_0. Arrows:

  • S0→SAS_0\to S_A labelled x=1x=1 and y=0y=0;
  • SA→S2S_A\to S_2 labelled x=1x=1;
  • S2→S0S_2\to S_0 with no label;
  • S0→SBS_0\to S_B labelled x=0x=0 and y=1y=1;
  • SB→S2S_B\to S_2 labelled x=0x=0 or y=1y=1.
Show the result

Moore machine. Next state for xy=00,01,10,11xy=00,01,10,11:

state ww 00 01 10 11
S0S_0 00 S0S_0 SBS_B SAS_A S0S_0
SAS_A 01 SAS_A SAS_A S2S_2 S2S_2
SBS_B 10 S2S_2 S2S_2 SBS_B S2S_2
S2S_2 11 S0S_0 S0S_0 S0S_0 S0S_0

Code: three processes (state register with asynchronous reset, next state, output). The code is in the solution (not compiled, checked by hand and with a Python model).

Show the full solution

Step 1: reading the diagram. The output ww is written inside the states: Moore machine. The inputs xx and yy are single bits. The sentence "in all the cases not indicated, the system does not change state" gives the loops:

  • S0S_0 leaves only for xy=10xy=10 (to SAS_A) and xy=01xy=01 (to SBS_B); for xy=00xy=00 and xy=11xy=11 it stays;
  • SAS_A leaves when x=1x=1 (any yy, so xy=10xy=10 and 1111); it stays when x=0x=0;
  • SBS_B leaves when x=0x=0 or y=1y=1, i.e. for xy=00,01,11xy=00,01,11; it stays only for xy=10xy=10;
  • S2S_2 has an arrow with no label: it goes to S0S_0 always, whatever xx and yy.

Step 2: structure. The text asks to separate memory and combinational logic: the standard three-process model (VHDL - Finite State Machines and Sequential TestbenchesA finite state machine is described in behavioral VHDL with an enumerated type for the states and three processes: the state register (reset and state <= next_state on the clock edge), the next state as a combinational function of state and input (case state, with default next_state <= state), and the output as a combinational function of the state alone (Moore) or of state and input (Mealy). The testbench has a clock process and an input process (initial reset, then a test sequence that visits all states).VHDL - Finite State Machines and Sequential Testbenches →):

  1. state register, sensitive to clk and rst: asynchronous reset to S0S_0 (VHDL - Latches, Flip-Flops and ResetsIn VHDL a memory element is a process in which some branch does not assign the signal: the D latch is process(D,C) with if C='1' then Q<=D, the positive-edge-triggered flip-flop is process(CLK) with if CLK'event and CLK='1'. Asynchronous reset: RST is in the sensitivity list and tested first (if RST='1' ... elsif clock edge); synchronous reset: only CLK in the list and RST tested inside the clock-edge branch, so a clock edge is needed for it to act. The testbench of a synchronous circuit has a process generating the clock and one applying inputs away from the active edge.VHDL - Latches, Flip-Flops and Resets →), otherwise state <= next_state on the rising edge;
  2. next state: purely combinational, sensitive to state, x and y;
  3. output: purely combinational, sensitive to state alone (Moore).

Step 3: code.

vhdl
library IEEE;
use IEEE.std_logic_1164.all;

entity fsm_xy is
  port ( clk, rst : in  std_logic;
         x, y     : in  std_logic;
         w        : out std_logic_vector(1 downto 0) );
end fsm_xy;

architecture beh of fsm_xy is
  type state_type is (S0, SA, S2, SB);
  signal state, next_state : state_type;
begin
  -- 1) memory: state register with asynchronous reset
  state_register : process (clk, rst)
  begin
    if rst = '1' then
      state <= S0;
    elsif clk'event and clk = '1' then
      state <= next_state;
    end if;
  end process;

  -- 2) next state: combinational
  next_state_comb : process (state, x, y)
  begin
    next_state <= state;                    -- default: no change of state
    case state is
      when S0 =>
        if x = '1' and y = '0' then
          next_state <= SA;
        elsif x = '0' and y = '1' then
          next_state <= SB;
        end if;
      when SA =>
        if x = '1' then
          next_state <= S2;
        end if;
      when SB =>
        if x = '0' or y = '1' then
          next_state <= S2;
        end if;
      when S2 =>
        next_state <= S0;                   -- arrow without label
    end case;
  end process;

  -- 3) output (Moore): depends only on the state
  output_comb : process (state)
  begin
    case state is
      when S0 => w <= "00";
      when SA => w <= "01";
      when S2 => w <= "11";
      when SB => w <= "10";
    end case;
  end process;
end beh;

Notes on the code:

Step 4: checks. Not compiled (no VHDL simulator available): the syntax was checked by hand with the model of the course (VHDL - Entity, Architecture, Types and Description LevelsVHDL is a hardware description language, not a programming language: its statements are concurrent and describe blocks of circuit, used to document, simulate and synthesise. A block has an entity (name and in/out ports) and at least one architecture (what is inside) written in structural style with components and port map, dataflow style with Boolean equations, or behavioral style. Types include std_logic with values 0, 1, X, Z, U and -, std_logic_vector, bit, boolean and integer; signal is used for internal connections and constant for fixed values.VHDL - Entity, Architecture, Types and Description Levels →) and the behaviour with a Python model that reproduces the two combinational processes line by line. The model gives the table of the Result and, after the reset, the following runs (the first starts with x,y=1,0x,y=1,0 and visits the five forward transitions; the second the loops of S0S_0 and SAS_A):

cycle 0 1 2 3 4 5 6 7 8 9
xyxy 10 11 00 01 11 00 01 10 00 11
present state S0S_0 SAS_A S2S_2 S0S_0 SBS_B S2S_2 S0S_0 SBS_B SBS_B S2S_2
ww 00 01 11 00 10 11 00 10 10 11
next state SAS_A S2S_2 S0S_0 SBS_B S2S_2 S0S_0 SBS_B SBS_B S2S_2 S0S_0
cycle 0 1 2 3 4 5 6
xyxy 00 11 10 01 00 10 01
present state S0S_0 S0S_0 S0S_0 SAS_A SAS_A SAS_A S2S_2
ww 00 00 00 01 01 01 11
next state S0S_0 S0S_0 SAS_A SAS_A SAS_A S2S_2 S0S_0

In the first run the cycle 7 (xy=10xy=10 in SBS_B) shows that SBS_B stays when x=1x=1 and y=0y=0; at cycle 8 (xy=00xy=00, so x=0x=0) it leaves. The condition "x=0x=0 or y=1y=1" is false only for xy=10xy=10, which is the only input that keeps SBS_B in place.

Typical mistakes:

  • scrambled conditions: and and or exchanged in SBS_B (the exit condition is "at least one of the two": it stays only for x=1,y=0x=1,y=0);
  • a condition on the arrows S2→S0S_2\to S_0, or an exit from SAS_A at every input: the diagram has x=1x=1 on SA→S2S_A\to S_2 and nothing on S2→S0S_2\to S_0;
  • memory and combinational logic in the same process (against the request of the text);
  • state missing from the sensitivity list of the next-state process: the simulation does not react to the change of state;
  • no default for next_state: latches appear in the synthesis;
  • rst missing from the list of the register process, or the reset to a state different from S0S_0.
Self-assessment grid
exercise points what must be there for full marks typical mistakes
Quiz 1-20 not stated, negative score for wrong answers correct choice for all 20 questions (b, c, b, c, b, a, a, b, c, a, b, c, a, b, a, a, b, a, b, b); for the loose ones (8, 19) the reasoning matters De Morgan applied to one variable only (7); parity read backwards (2); UTF-8 taken as fixed length (4); setup time attributed to the logic (15); clock edge and reset type confused (11); daisy chain priority given to the CPU (18)
Exercise 1 not stated table with 16 rows and 6 ones; map with Gray order; three essential groups (4, 2 and 2 cells, one across the edge); y=a1b1‾+a1a0b0‾+a0b1‾ b0‾y=a_1\overline{b_1}+a_1a_0\overline{b_0}+a_0\overline{b_1}\,\overline{b_0} columns in binary order; wrap-around group missed; a≥ba\ge b instead of a>ba>b
Exercise 2 not stated Moore diagram with 5 states and initial state; outputs inside the states; two waiting states in a row; btn ignored while moving or open; names btn, finecorsa, motore one waiting state only; opening and closing not distinguished; outputs on the arrows; missing initial state
Exercise 3 not stated three processes (register with reset, next state with default, Moore output); correct conditions (x=1,y=0x=1,y=0 / x=0,y=1x=0,y=1 / x=1x=1 / x=0x=0 or y=1y=1); unlabelled arrow S2→S0S_2\to S_0 memory and logic mixed; and/or swapped; state missing from the sensitivity list; no default for the next state