Salta al contenuto
Note per Studenti Digital Systems - Mock Exam 2 Report

Digital Systems - Mock Exam 2

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

In questa pagina 24

Mock exam built on the model of the sittings of 21 June 2022 and 11 July 2022 of the equivalent Italian-language course Circuiti Digitali (Engineering degrees, University of Padova): 20 multiple-choice quizzes (three options, only one correct) and 3 exercises (a Karnaugh-map synthesis, a finite state machine designed from a verbal description, a VHDL description of a state machine with a test bench). The real sheets give neither the points nor the duration, so the values below are a proposal: quiz right answer +1+1, wrong answer −0.3-0.3, no answer 00 (at most 2020 points); each exercise 1010 points; duration 33 hours; no notes, books or calculators.

Because the English-language course also covers computer organisation and memory, 4 of the 20 quizzes (17-20) are on the memory and input-output chapters (memory chips, polling, interrupts, DMA); the other 16 are centred on canonical forms, Karnaugh maps, multiplexers and decoders, adders, timing, registers and counters. All the questions and exercises are new: none is taken from the real papers or from the published simulations of the Italian course.

Checks: truth tables enumerated by script, minimisations compared with a symbolic algebra system (SOP and POS), the multiplexer connections and the numerical quiz answers recomputed, the state machine reduced by partition refinement and simulated on input sequences. The VHDL could not be compiled (no simulator was available): it was checked by hand against the transition table and by a Python model that follows the case statement and the test bench timing line by line.

Quiz 1

The function F(A,B,C)=A+B C‾F(A,B,C)=A+B\,\overline C is written in canonical SOP form. The number of minterms is:

  • a. 3
  • b. 5
  • c. none of the other answers
Show the result

b. F=∑m(2,4,5,6,7)F=\sum m(2,4,5,6,7).

Show the full solution

Go through the truth table: A=1A=1 gives F=1F=1 on the four rows 100,101,110,111100,101,110,111 (minterms 4,5,6,74,5,6,7); with A=0A=0 the product B C‾B\,\overline C is 11 only for B=1,C=0B=1,C=0, i.e. row 010010 (minterm 22). So F=∑m(2,4,5,6,7)F=\sum m(2,4,5,6,7), five minterms. The term AA alone is not a minterm: it lacks BB and CC and expands into four of them (A=A(B+B‾)(C+C‾)A=A(B+\overline B)(C+\overline C)). Typical mistake: counting the product terms of the expression (two) instead of the rows of the truth table. 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 2

A function of three variables is F=∑m(1,2,4)F=\sum m(1,2,4). Its canonical POS form is:

  • a. ∏M(0,3,5,6,7)\prod M(0,3,5,6,7)
  • b. ∏M(1,2,4)\prod M(1,2,4)
  • c. none of the other answers
Show the result

a.

Show the full solution

The canonical POS is the product of the maxterms of the rows where F=0F=0, i.e. of all the indices missing from the SOP: {0,…,7}∖{1,2,4}={0,3,5,6,7}\{0,\dots,7\}\setminus\{1,2,4\}=\{0,3,5,6,7\}. Check on row 33 (011011): F=0F=0 and M3=A+B‾+C‾=0M_3=A+\overline B+\overline C=0 there, so the product is 00. Option b writes in the POS the indices of the ones: the typical mistake. 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 3

How many different Boolean functions of 33 variables exist?

  • a. 8
  • b. 64
  • c. 256
Show the result

c.

Show the full solution

Quiz 4

In the Karnaugh map of a function of 44 variables, a rectangular group of 88 cells containing ones corresponds to a product that eliminates:

  • a. two variables
  • b. four variables
  • c. none of the other answers
Show the result

c. It eliminates three variables.

Show the full solution

Quiz 5

The function of four variables F(A,B,C,D)=∑m(0,2,8,10)F(A,B,C,D)=\sum m(0,2,8,10) has the minimal SOP:

  • a. B‾ D‾\overline B\,\overline D
  • b. A‾ C‾\overline A\,\overline C
  • c. none of the other answers
Show the result

a.

Show the full solution

Rows 0=00000=0000, 2=00102=0010, 8=10008=1000, 10=101010=1010 are the four corners of the map, which are adjacent because the map wraps around (left edge with right edge, top with bottom). In the whole group B=0B=0 and D=0D=0 stay constant while AA and CC take every value, so the product is B‾ D‾\overline B\,\overline D. The product A‾ C‾\overline A\,\overline C would cover rows 0,1,4,50,1,4,5: wrong cells. Typical mistake: not seeing the group because the corners look far apart. Theory: 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 →.

Quiz 6

In a Karnaugh map, a cell marked with the don't care condition X:

  • a. must always be covered by at least one group
  • b. can be taken as 11 or as 00, whichever makes the groups larger
  • c. makes the group that contains it an essential prime implicant
Show the result

b.

Show the full solution

Quiz 7

The function F(A,B,C,D)=∑m(1,3,4,6,7,12,13,15)F(A,B,C,D)=\sum m(1,3,4,6,7,12,13,15) is implemented with an 8-to-1 multiplexer whose select inputs are S2S1S0=ABCS_2S_1S_0=ABC and whose data inputs get 00, 11, DD or D‾\overline D. The data input I2I_2 is connected to:

  • a. DD
  • b. 00
  • c. D‾\overline D
Show the result

c. I2=D‾I_2=\overline D.

Show the full solution

Input I2I_2 is selected when ABC=010ABC=010, which corresponds to the pair of rows 0100=40100=4 (D=0D=0) and 0101=50101=5 (D=1D=1). Here F(4)=1F(4)=1 (4 is a minterm) and F(5)=0F(5)=0 (5 is not): FF equals 11 for D=0D=0 and 00 for D=1D=1, i.e. F=D‾F=\overline D. The full list is I0=DI_0=D (rows 0,10,1: 0,10,1), I1=DI_1=D (rows 2,32,3: 0,10,1), I2=D‾I_2=\overline D, I3=1I_3=1 (rows 6,76,7: 1,11,1), I4=0I_4=0 (rows 8,98,9), I5=0I_5=0 (rows 10,1110,11), I6=1I_6=1 (rows 12,1312,13), I7=DI_7=D (rows 14,1514,15: 0,10,1). Typical mistake: forgetting that the pair (1,0)(1,0) needs the complemented variable. Theory: Decoders, Encoders and MultiplexersAn n-to-m decoder converts a binary input into a one-hot output whose lines are the minterms of the inputs (m AND gates; hierarchical construction lowers the input cost; enable). Any function equals a decoder plus an OR of its minterms. The encoder does the inverse but fails with several or no active inputs; the priority encoder fixes it with a priority and a valid output V. A 2^n-to-1 multiplexer computes Y = sum of m_i(S) I_i and implements any n-variable function; a smaller MUX uses the last variable (0, 1, X, not X) as data.Decoders, Encoders and Multiplexers →.

Quiz 8

A 4-to-16 decoder is built hierarchically with two 2-to-4 decoders (each with 22 inverters and 44 two-input ANDs) and 1616 two-input ANDs. Counting the gate inputs (an inverter counts 11), the cost is:

  • a. 52
  • b. 68
  • c. none of the other answers
Show the result

a.

Show the full solution

Each 2-to-4 decoder costs 2⋅1+4⋅2=102\cdot1+4\cdot2=10; two of them cost 2020. The final level has 1616 two-input ANDs, each combining one output of the first decoder with one of the second: 16⋅2=3216\cdot2=32. Total 20+32=5220+32=52. The flat solution, 44 inverters and 1616 four-input ANDs, costs 4+16⋅4=684+16\cdot4=68 (option b): the hierarchical one is cheaper. Theory: Decoders, Encoders and MultiplexersAn n-to-m decoder converts a binary input into a one-hot output whose lines are the minterms of the inputs (m AND gates; hierarchical construction lowers the input cost; enable). Any function equals a decoder plus an OR of its minterms. The encoder does the inverse but fails with several or no active inputs; the priority encoder fixes it with a priority and a valid output V. A 2^n-to-1 multiplexer computes Y = sum of m_i(S) I_i and implements any n-variable function; a smaller MUX uses the last variable (0, 1, X, not X) as data.Decoders, Encoders and Multiplexers →.

Quiz 9

A ripple carry adder has 66 full adders. The carry crosses each stage in 2 tG2\,t_G with tG=0.4t_G=0.4 ns. The sum of the most significant bit is available after about:

  • a. 2.4 ns
  • b. 8 ns
  • c. 4.8 ns
Show the result

c.

Show the full solution

Carries are produced one after the other, so the delay grows linearly with the number of bits: 6⋅2 tG=6⋅0.8=4.86\cdot2\,t_G=6\cdot0.8=4.8 ns. Option a counts only one gate delay per stage (6⋅0.46\cdot0.4); option b is not obtained from the data. This is the reason why the ripple adder is simple but slow. 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 →.

Quiz 10

In the adder-subtractor (each bit BiB_i is XORed with the control SS, and AA is added to the result), when S=1S=1 the carry in of the first full adder is:

  • a. 11
  • b. 00
  • c. S‾\overline S
Show the result

a.

Show the full solution

The same signal SS drives both the XORs and the carry in of the first full adder. With S=1S=1 the XORs give B‾\overline B (one's complement) and the carry in 11 supplies the "+1+1" of the two's complement: the circuit computes A+B‾+1=A−BA+\overline B+1=A-B. With S=0S=0 it computes A+BA+B with carry in 00. 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 →.

Quiz 11

In a synchronous circuit tpd,FF=0.6t_{pd,FF}=0.6 ns, the critical path of the combinational network is 3.13.1 ns and ts,FF=0.3t_{s,FF}=0.3 ns (no slack, no skew). The maximum clock frequency is about:

  • a. 322 MHz
  • b. 250 MHz
  • c. none of the other answers
Show the result

b.

Show the full solution

Quiz 12

A hold-time violation in a synchronous circuit is cured by:

  • a. lowering the clock frequency
  • b. adding delay (buffers) on the shortest paths
  • c. none of the other answers
Show the result

b.

Show the full solution

Quiz 13

Compared with clock gating, the main advantage of controlling the loading of a register with a load enable (a 2-to-1 multiplexer in front of each DD input) is:

  • a. lower power consumption, because idle blocks receive no clock
  • b. no clock skew, because the clock reaches the flip-flops directly
  • c. none of the other answers
Show the result

b.

Show the full solution

Quiz 14

A 4-bit synchronous binary counter with enable and carry out is in the state Q=1011Q=1011 with EN=1EN=1. At the next active edge:

  • a. Q=1100Q=1100 and CO=1CO=1
  • b. Q=1010Q=1010 and CO=0CO=0
  • c. Q=1100Q=1100 and CO=0CO=0
Show the result

c.

Show the full solution

Quiz 15

In a ripple (asynchronous) counter with 66 flip-flops, each with propagation delay 11 ns, in the worst case the outputs settle after:

  • a. 6 ns
  • b. 1 ns
  • c. none of the other answers
Show the result

a.

Show the full solution

Quiz 16

A bidirectional shift register has the control S1S0S_1S_0: 0000 hold, 0101 shift left, 1010 shift right, 1111 parallel load. With Q3Q2Q1Q0=0110Q_3Q_2Q_1Q_0=0110, right serial input RSI=1RSI=1 and S1S0=10S_1S_0=10, after one clock edge Q3Q2Q1Q0Q_3Q_2Q_1Q_0 is:

  • a. 1100
  • b. 1011
  • c. 0110
Show the result

b.

Show the full solution

Quiz 17

A 128K×16128\mathrm K\times16 memory is built with chips of 32K×832\mathrm K\times8. The number of chips needed is:

  • a. 4
  • b. 16
  • c. none of the other answers
Show the result

c. 88 chips.

Show the full solution

Number of chips = required capacity divided by chip capacity: (128K⋅16)/(32K⋅8)=8(128\mathrm K\cdot16)/(32\mathrm K\cdot8)=8. Equivalently: two chips side by side give the 1616 bits of the word (same addresses), and 128K/32K=4128\mathrm K/32\mathrm K=4 such pairs give the words. The 1717 address bits split into 1515 that go to every chip and 22 that drive a 2-to-4 decoder enabling one pair of chips (chip select). Option a counts only the words (128K/32K=4128\mathrm K/32\mathrm K=4) and forgets that each word needs two chips side by side. Theory: Main Memory - RAM, ROM and Chip OrganisationA memory is an array of cells (words of several bits) with control circuitry; memories are classified as read-only or read/write, random, serial or hybrid access, volatile or non-volatile. A RAM of 2^k x n bits has k address bits (independent of n), n data bits, read/write and chip select. SRAM uses a bistable cell (latch), is fast and needs no refresh; DRAM stores charge in a capacitor, is denser and needs refresh. Chips use row and column decoders (coincident selection), tri-state outputs, and arrays of chips for more words or more bits per word.Main Memory - RAM, ROM and Chip Organisation →.

Quiz 18

A peripheral produces 200200 bytes per second. With programmed I/O, the CPU needs 5050 ns for one status check and checks continuously. How many checks does it make between two consecutive bytes?

  • a. about 1 000
  • b. about 10 000
  • c. about 100 000
Show the result

c.

Show the full solution

Quiz 19

In a vectored interrupt system:

  • a. the device that raises the interrupt supplies the address (vector) of its service routine
  • b. the CPU polls all the devices by software to find the one that requested service
  • c. the interrupt signal is an input of the peripheral and an output of the CPU
Show the result

a.

Show the full solution

Quiz 20

A DMA controller transfers a block of 20482048 words from a disk to memory. Which statement is correct?

  • a. the CPU is interrupted after each word
  • b. the controller increments its address register after each word and raises one interrupt at the end
  • c. none of the other answers
Show the result

b.

Show the full solution

The CPU only programs the controller (address and amount of data) and grants the bus (Bus Request / Bus Granted); the controller then moves the words without the CPU, incrementing the address register 20482048 times, and at the end raises a single interrupt to say the transfer is finished. Option a describes interrupt-driven I/O, not DMA; forgetting the final interrupt is a common mistake. Theory: Direct Memory Access (DMA)In DMA a controller takes over the buses and moves data between a fast device and memory without involving the CPU; it asks for the bus with Bus Request, receives it with Bus Granted, increments an address register after every word, and raises a single interrupt at the end. The CPU programs it as if it were a peripheral.Direct Memory Access (DMA) →.

Exercise 1 (points 10)

A safety system has four sensors A,B,C,DA,B,C,D (11 = sensor active). The alarm FF must be on (F=1F=1) when at least three of the four sensors are active, and off otherwise (all the 1616 combinations can occur).

a) Write the truth table, the canonical SOP form and the Karnaugh map of FF, and find the minimal SOP form, indicating the groups.

b) Find the minimal POS form and say which of the two forms (SOP or POS) costs less, counting the gate inputs (the input variables are available only in direct form, but the minimal forms need no inverter).

c) Implement FF with an 8-to-1 multiplexer, using A,B,CA,B,C as select inputs (AA most significant) and without any other gate.

d) Implement FF with a 4-to-1 multiplexer with A,BA,B as select inputs, using the minimum number of additional gates.

Show the result

a) F=∑m(7,11,13,14,15)F=\sum m(7,11,13,14,15). Minimal SOP: F=ABC+ABD+ACD+BCDF=ABC+ABD+ACD+BCD (four groups of 22 cells, all essential; 1212 literals).

b) F=∏M(0,1,2,3,4,5,6,8,9,10,12)F=\prod M(0,1,2,3,4,5,6,8,9,10,12). Minimal POS: F=(A+B)(A+C)(A+D)(B+C)(B+D)(C+D)F=(A+B)(A+C)(A+D)(B+C)(B+D)(C+D) (66 sums, 1212 literals). Cost: SOP 4⋅3+4=164\cdot3+4=16 gate inputs, POS 6⋅2+6=186\cdot2+6=18. The SOP costs less.

c) S2S1S0=ABCS_2S_1S_0=ABC: I0=I1=I2=I4=0I_0=I_1=I_2=I_4=0, I3=I5=I6=DI_3=I_5=I_6=D, I7=1I_7=1.

d) S1S0=ABS_1S_0=AB: I0=0I_0=0, I1=I2=C DI_1=I_2=C\,D, I3=C+DI_3=C+D; one AND and one OR (two gates, 44 gate inputs).

Show the full solution

Step 1: truth table and canonical form (point a). The function counts the ones among the inputs: F=1F=1 if A+B+C+D≥3A+B+C+D\ge3 (here ++ is the arithmetic sum of the bits). Rows are numbered ABCDABCD in binary:

row ABCDABCD ones FF
0-6 00000000 to 01100110 00 to 22 0
7 0111 3 1
8, 9, 10 1000,1001,10101000,1001,1010 11 or 22 0
11 1011 3 1
12 1100 2 0
13 1101 3 1
14 1110 3 1
15 1111 4 1

So F=∑m(7,11,13,14,15)=A‾BCD+AB‾CD+ABC‾D+ABCD‾+ABCDF=\sum m(7,11,13,14,15)=\overline A BCD+A\overline B CD+AB\overline C D+ABC\overline D+ABCD (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 →): five rows with F=1F=1, hence 16−5=1116-5=11 rows with F=0F=0 (the 1111 maxterms of point b).

Step 2: the map and the minimal SOP. Map with rows ABAB and columns CDCD in Gray order (00,01,11,1000,01,11,10):

AB\CDAB\backslash CD 00 01 11 10
00 0 0 0 0
01 0 0 1 0
11 0 1 1 1
10 0 0 1 0

Prime implicants, all groups of two adjacent cells:

  • cells 14,1514,15 (row AB=11AB=11, columns 11,1011,10): ABCABC (DD changes);
  • cells 13,1513,15 (row 1111, columns 01,1101,11): ABDABD (CC changes);
  • cells 11,1511,15 (column CD=11CD=11, rows 10,1110,11): ACDACD (BB changes);
  • cells 7,157,15 (column 1111, rows 01,1101,11): BCDBCD (AA changes).

Each is essential: minterm 1414 is covered only by ABCABC, 1313 only by ABDABD, 1111 only by ACDACD, 77 only by BCDBCD (cell 1515 is shared by all four). No larger group exists: there is no row, column or square of four ones. Hence F=ABC+ABD+ACD+BCDF=ABC+ABD+ACD+BCD (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 →). Check: ABCD=1110ABCD=1110 gives ABC=1ABC=1, so F=1F=1; ABCD=1100ABCD=1100 gives all products 00, so F=0F=0.

Step 3: the POS (point b). Group the zeros: the map has 1111 zeros and every zero belongs to a group of four cells where two variables are 00. For instance cells 0,1,2,30,1,2,3 (row AB=00AB=00): in the group A=0A=0 and B=0B=0 are constant, giving the product A‾ B‾\overline A\,\overline B for F‾\overline F, hence the sum A+BA+B for FF (variables that are 00 in the group enter direct). The six groups are the rows and columns of the map where two variables are both 00:

  • A‾ B‾\overline A\,\overline B (cells 0,1,2,30,1,2,3) gives (A+B)(A+B); A‾ C‾\overline A\,\overline C (cells 0,1,4,50,1,4,5) gives (A+C)(A+C); A‾ D‾\overline A\,\overline D (cells 0,2,4,60,2,4,6) gives (A+D)(A+D);
  • B‾ C‾\overline B\,\overline C (cells 0,1,8,90,1,8,9) gives (B+C)(B+C); B‾ D‾\overline B\,\overline D (cells 0,2,8,100,2,8,10) gives (B+D)(B+D); C‾ D‾\overline C\,\overline D (cells 0,4,8,120,4,8,12) gives (C+D)(C+D).

All six are essential (cell 33 only in the first, 55 only in the second, 66 in the third, 99 in the fourth, 1010 in the fifth, 1212 in the sixth). So F=(A+B)(A+C)(A+D)(B+C)(B+D)(C+D).F=(A+B)(A+C)(A+D)(B+C)(B+D)(C+D). It says in words what the function is: "at least three ones" is the same as "among any two variables at least one is 11". Cost in gate inputs (the literals are all direct, so no inverters): SOP, four 3-input ANDs and a 4-input OR, 4⋅3+4=164\cdot3+4=16; POS, six 2-input ORs and a 6-input AND, 6⋅2+6=186\cdot2+6=18. Same number of literals (1212), but the SOP has a smaller final gate: the SOP costs less. Typical mistake: comparing only the literals and concluding that the two are equivalent.

Step 4: the 8-to-1 multiplexer (point c). Connect A,B,CA,B,C to S2,S1,S0S_2,S_1,S_0. For each select value the multiplexer picks one data input, and that input must supply FF for both values of DD (Decoders, Encoders and MultiplexersAn n-to-m decoder converts a binary input into a one-hot output whose lines are the minterms of the inputs (m AND gates; hierarchical construction lowers the input cost; enable). Any function equals a decoder plus an OR of its minterms. The encoder does the inverse but fails with several or no active inputs; the priority encoder fixes it with a priority and a valid output V. A 2^n-to-1 multiplexer computes Y = sum of m_i(S) I_i and implements any n-variable function; a smaller MUX uses the last variable (0, 1, X, not X) as data.Decoders, Encoders and Multiplexers →):

ABCABC rows (D=0, D=1D=0,\ D=1) (F(D=0),F(D=1))(F(D{=}0),F(D{=}1)) IiI_i
000 0, 1 (0,0)(0,0) 00
001 2, 3 (0,0)(0,0) 00
010 4, 5 (0,0)(0,0) 00
011 6, 7 (0,1)(0,1) DD
100 8, 9 (0,0)(0,0) 00
101 10, 11 (0,1)(0,1) DD
110 12, 13 (0,1)(0,1) DD
111 14, 15 (1,1)(1,1) 11

So I3=I5=I6=DI_3=I_5=I_6=D, I7=1I_7=1, the others 00: no other gate is needed. Check with ABCD=1011ABCD=1011: ABC=101ABC=101 selects I5=D=1I_5=D=1, F=1F=1 (three sensors active). Typical mistakes: swapping the order of the select inputs (AA must go to S2S_2, the most significant), or using D‾\overline D where the pair is (0,1)(0,1).

Step 5: the 4-to-1 multiplexer (point d). Now only A,BA,B are selects, and the data inputs are functions of C,DC,D taken from the four sub-maps (rows of the map):

ABAB FF as a function of CDCD (00,01,10,1100,01,10,11) data input
00 0,0,0,00,0,0,0 00
01 0,0,0,10,0,0,1 C DC\,D
10 0,0,0,10,0,0,1 C DC\,D
11 0,1,1,10,1,1,1 C+DC+D

One AND (feeding I1I_1 and I2I_2) and one OR (feeding I3I_3) are enough. Interpretation: with A=B=1A=B=1 one more active sensor is enough, with a single active sensor among A,BA,B both CC and DD are needed, with none the alarm is off. The multiplexer solution of point c uses no gates but a larger multiplexer: a compromise between multiplexer size and logic.

Exercise 2 (points 10)

A pedestrian crossing is controlled by a synchronous Moore machine with clock, an asynchronous reset rst, and two push-buttons, bA and bB (one at each end of the crossing), which are 11 while the button is pressed. The cars have a traffic light with three lamps, red, yellow and green (outputs CR,CY,CGCR,CY,CG), the pedestrians a light with two lamps, red and green (outputs PR,PGPR,PG). Behaviour:

  • after reset and at rest: cars green, pedestrians red; the machine stays in this condition while bA=bB=0bA=bB=0;
  • if at least one button is pressed at rest, the cars light goes yellow (pedestrians still red) for one clock cycle;
  • then the cars light is red and the pedestrian light green for two cycles;
  • then both lights are red for one cycle (clearance), and the machine goes back to rest;
  • the buttons are ignored in every state except the rest state.

a) Draw the state diagram without equivalent states and write the state table with the outputs. Show with the equivalence method that a first diagram that remembers which button was pressed (six states) has two equivalent states.

b) Encode the states with 33 flip-flops with the assignment CG=000CG=000, CY=001CY=001, PG1=011PG1=011, PG2=010PG2=010, RR=110RR=110 (the other three codes are never used) and find the minimal equations of the D inputs (D2,D1,D0D_2,D_1,D_0), using r=bA+bBr=bA+bB as a single input.

c) Find the output equations of the five lamps.

d) Check what the machine does if it starts in an unused state.

e) Simulate the machine from reset with the input pairs (bA,bB)(bA,bB): 00,10,11,00,01,00,0000,10,11,00,01,00,00 (one per cycle).

Show the result

a) Five states: CGCG (CR CY CG=001CR\,CY\,CG=001, PR PG=10PR\,PG=10), CYCY (010010, 1010), PG1PG1 (100100, 0101), PG2PG2 (100100, 0101), RRRR (100100, 1010). Transitions: CG→CGCG\to CG if r=0r=0, CG→CYCG\to CY if r=1r=1; CY→PG1→PG2→RR→CGCY\to PG1\to PG2\to RR\to CG whatever the input. In the six-state draft the states CYACY_A and CYBCY_B (yellow after bAbA / after bBbB) are equivalent.

b) D2=Q2‾ Q1 Q0‾D_2=\overline{Q_2}\,Q_1\,\overline{Q_0}; D1=Q0+Q2‾ Q1D_1=Q_0+\overline{Q_2}\,Q_1; D0=Q1‾ Q0+Q1‾ rD_0=\overline{Q_1}\,Q_0+\overline{Q_1}\,r, with r=bA+bBr=bA+bB.

c) CR=Q1CR=Q_1; CY=Q1‾ Q0CY=\overline{Q_1}\,Q_0; CG=Q1‾ Q0‾CG=\overline{Q_1}\,\overline{Q_0}; PR=Q2+Q1‾PR=Q_2+\overline{Q_1}; PG=Q2‾ Q1PG=\overline{Q_2}\,Q_1.

d) The machine is self-starting: 100→000100\to000 (if r=0r=0) or 001001 (if r=1r=1); 101→011101\to011; 111→010111\to010.

e) States after the successive edges: CG, CY, PG1, PG2, RR, CG, CGCG,\ CY,\ PG1,\ PG2,\ RR,\ CG,\ CG.

Show the full solution

Step 1: the state diagram (point a). In a Moore machine the output depends only on the state, so each distinct combination of lamps in the sequence needs a 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 →). The sequence is: rest, yellow, green for pedestrians (two cycles, hence two states), clearance. The two pedestrian-green states have the same output but are not equivalent: they differ in the future (PG1PG1 goes to PG2PG2, PG2PG2 goes to RRRR) and the second one counts the second cycle. State table (next state for r=0r=0 and r=1r=1, where r=bA+bBr=bA+bB, i.e. r=0r=0 only for bA=bB=0bA=bB=0; outputs CR CY CGCR\,CY\,CG and PR PGPR\,PG):

state meaning CR CY CGCR\,CY\,CG PR PGPR\,PG next if r=0r=0 next if r=1r=1
CGCG rest 001 10 CGCG CYCY
CYCY cars yellow 010 10 PG1PG1 PG1PG1
PG1PG1 pedestrians green, 1st cycle 100 01 PG2PG2 PG2PG2
PG2PG2 pedestrians green, 2nd cycle 100 01 RRRR RRRR
RRRR both red 100 10 CGCG CGCG

Diagram to redraw: five circles with the output written inside, an arrow entering CGCG labelled rst=1rst=1; a loop on CGCG labelled "bA=0bA=0 and bB=0bB=0"; an arrow CG→CYCG\to CY labelled "bA=1bA=1 or bB=1bB=1"; unlabelled arrows (any input) CY→PG1→PG2→RR→CGCY\to PG1\to PG2\to RR\to CG.

Equivalent states in the six-state draft. A student who records which button started the sequence draws two yellow states: CYACY_A (reached when bA=1bA=1) and CYBCY_B (reached when bB=1bB=1), both leading to PG1PG1 and both with the same lamps. The equivalence method (partition refinement) starts by grouping states with the same output: {CG}, {CYA,CYB}, {PG1,PG2}, {RR}\{CG\},\ \{CY_A,CY_B\},\ \{PG1,PG2\},\ \{RR\}. Refine: PG1PG1 goes to PG2PG2 (block {PG1,PG2}\{PG1,PG2\}) while PG2PG2 goes to RRRR (another block), so they are split; CYACY_A and CYBCY_B both go to PG1PG1 for every input, so they stay together. The partition no longer changes: CYA≡CYBCY_A\equiv CY_B, they merge into CYCY, giving five states instead of six. Reason: after the press the machine does not need to remember who pressed. With 55 states ⌈log⁡25⌉=3\lceil\log_25\rceil=3 flip-flops are needed. Typical mistake: merging PG1PG1 and PG2PG2 because the lamps are equal (the cycle count would be lost).

Step 2: encoding and D equations (point b). With D flip-flops the next state is directly the value of DD. The table of the next code (variables Q2Q1Q0Q_2Q_1Q_0, input rr):

state code Q2Q1Q0Q_2Q_1Q_0 next (r=0r=0) next (r=1r=1)
CGCG 000 000 001
CYCY 001 011 011
PG1PG1 011 010 010
PG2PG2 010 110 110
RRRR 110 000 000
unused 100, 101, 111 X X

The codes 100,101,111100,101,111 never occur, so for both values of rr they are don't cares. Maps with rows Q2Q1Q_2Q_1 and columns Q0 rQ_0\,r in Gray order (00,01,11,1000,01,11,10):

D2D_2 (next code 110110 only from PG2=010PG2=010):

Q2Q1\Q0rQ_2Q_1\backslash Q_0r 00 01 11 10
00 0 0 0 0
01 1 1 0 0
11 0 0 X X
10 X X X X

The two ones are the cells Q2Q1Q0r=0100Q_2Q_1Q_0r=0100 and 01010101 (state 010010, any rr): they form a group of two cells with Q2=0Q_2=0, Q1=1Q_1=1, Q0=0Q_0=0 constant, so D2=Q2‾ Q1 Q0‾D_2=\overline{Q_2}\,Q_1\,\overline{Q_0}. (The row 1111, state RRRR, has zeros and prevents enlarging the group with Q2Q_2.)

D1D_1 (next codes 011,010,110011,010,110 have Q1=1Q_1=1: from CYCY, PG1PG1, PG2PG2):

Q2Q1\Q0rQ_2Q_1\backslash Q_0r 00 01 11 10
00 0 0 1 1
01 1 1 1 1
11 0 0 X X
10 X X X X

Groups: the 88 cells with Q0=1Q_0=1 (columns 11,1011,10, using the Xs of rows 11,1011,10): Q0Q_0; the row Q2Q1=01Q_2Q_1=01 (44 cells): Q2‾ Q1\overline{Q_2}\,Q_1. D1=Q0+Q2‾ Q1D_1=Q_0+\overline{Q_2}\,Q_1.

D0D_0 (next code 001001 from CGCG with r=1r=1, 011011 from CYCY, and PG1PG1 gives 010010, so D0=1D_0=1 only for CGCG with r=1r=1 and for CYCY):

Q2Q1\Q0rQ_2Q_1\backslash Q_0r 00 01 11 10
00 0 1 1 1
01 0 0 0 0
11 0 0 X X
10 X X X X

Groups: columns 11,1011,10 (Q0=1Q_0=1) with Q1=0Q_1=0 (rows 00,1000,10): Q1‾ Q0\overline{Q_1}\,Q_0; columns 01,1101,11 (r=1r=1) with Q1=0Q_1=0: Q1‾ r\overline{Q_1}\,r. D0=Q1‾ Q0+Q1‾ r=Q1‾ (Q0+r)D_0=\overline{Q_1}\,Q_0+\overline{Q_1}\,r=\overline{Q_1}\,(Q_0+r). Replacing r=bA+bBr=bA+bB: D0=Q1‾ Q0+Q1‾ bA+Q1‾ bBD_0=\overline{Q_1}\,Q_0+\overline{Q_1}\,bA+\overline{Q_1}\,bB. Typical mistake: using the unused states as zeros instead of don't cares, getting larger equations.

Step 3: outputs (point c). In a Moore machine the outputs are functions of the state only; the don't cares on 100,101,111100,101,111 simplify them:

lamp on in states map reading equation
CRCR 011,010,110011,010,110 all states with Q1=1Q_1=1 (also 111111 is X) Q1Q_1
CYCY 001001 Q1=0,Q0=1Q_1=0,Q_0=1 (with 101101 as X) Q1‾ Q0\overline{Q_1}\,Q_0
CGCG 000000 Q1=0,Q0=0Q_1=0,Q_0=0 (with 100100 as X) Q1‾ Q0‾\overline{Q_1}\,\overline{Q_0}
PRPR 000,001,110000,001,110 Q2=1Q_2=1 or Q1=0Q_1=0 Q2+Q1‾Q_2+\overline{Q_1}
PGPG 011,010011,010 Q2=0Q_2=0 and Q1=1Q_1=1 Q2‾ Q1\overline{Q_2}\,Q_1

Check: in each of the five states exactly one cars lamp and one pedestrian lamp are on; PRPR and PGPG are complementary on the used states (PR=PG‾PR=\overline{PG} in the used codes).

Step 4: unused states (point d). If noise brings the machine to 100,101100,101 or 111111 it must come back to the normal sequence. Evaluating the equations: 100100 gives D2=0D_2=0, D1=0D_1=0, D0=0‾(0+r)=rD_0=\overline{0}(0+r)=r, so the next state is 000000 (r=0r=0) or 001001 (r=1r=1): CGCG or CYCY. State 101101: D2=0D_2=0, D1=Q0=1D_1=Q_0=1, D0=Q1‾(1+r)=1D_0=\overline{Q_1}(1+r)=1, next 011=PG1011=PG1. State 111111: D2=0D_2=0 (Q0=1Q_0=1), D1=1D_1=1, D0=0D_0=0 (Q1=1Q_1=1), next 010=PG2010=PG2. All three enter the valid cycle: the machine is self-starting (the choice of the don't cares did not create a trap).

Step 5: simulation (point e). Start from reset, state CGCG (state before each edge, inputs applied during the cycle, state after the edge):

edge bA bBbA\,bB rr state before state after lamps after (cars, ped)
1 00 0 CGCG CGCG green, red
2 10 1 CGCG CYCY yellow, red
3 11 1 CYCY PG1PG1 red, green (button ignored)
4 00 0 PG1PG1 PG2PG2 red, green
5 01 1 PG2PG2 RRRR red, red (button ignored)
6 00 0 RRRR CGCG green, red
7 00 0 CGCG CGCG green, red

The Moore outputs change only at the clock edges, one state at a time. Typical mistake: starting a new crossing sequence because a button is pressed in CYCY, PG1PG1, PG2PG2 or RRRR: the statement says that the buttons are ignored there.

Exercise 3 (points 10)

Describe in VHDL the pedestrian crossing controller of Exercise 2 (Moore machine). Entity ped_crossing with inputs clk, rst, bA, bB (std_logic) and outputs cars (std_logic_vector(2 downto 0), bits red, yellow, green) and ped (std_logic_vector(1 downto 0), bits red, green). States CG, CY, PG1, PG2, RR; the reset is asynchronous, active high, and brings the machine to CG.

a) Write the architecture using two processes: one for the state register, one purely combinational for next state and outputs.

b) Write a test bench with a clock of period 100100 ns (rising edge at 00, 100100, 200200 ns, ...), an initial reset of 150150 ns, and one pair of inputs per clock cycle changed on the falling edge, taken from the vectors bA_seq = "011000000001100000" and bB_seq = "001010010001100000" (first character first, 1818 cycles). Check that the sequence visits all the states and the transitions of the rest state.

c) With this test bench, at which instant does ped take the value "01" for the first time after the reset? What are cars and ped between 500500 ns and 600600 ns?

Show the result

a) Architecture with type state_type is (CG, CY, PG1, PG2, RR), process 1 with asynchronous reset and state <= next_state on the rising edge, process 2 with default next_state <= state and a case state that assigns cars, ped and the next state in every branch (full code in the Solution).

b) Test bench with a clock process and an input process (reset for 150150 ns, then for i in 0 to 17 loop applying bA_seq(i), bB_seq(i) and wait for PERIOD). The 1818 cycles give the states CG,CY,PG1,PG2,RR,CG,CG,CY,PG1,PG2,RR,CG,CY,PG1,PG2,RR,CG,CGCG,CY,PG1,PG2,RR,CG,CG,CY,PG1,PG2,RR,CG,CY,PG1,PG2,RR,CG,CG after the edges at 200,300,…,1900200,300,\dots,1900 ns.

c) First ped = "01" at the edge at 400400 ns (state PG1); between 500500 and 600600 ns the state is PG2, cars = "100", ped = "01".

Show the full solution

Step 1: the two-process architecture (point a). The course model has three processes (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 →): register, next state, output. Here the last two are merged into one combinational process, which is legitimate for a Moore machine because the outputs are assigned inside the case only from the value of state and never from the inputs. Process 1 is the only one with memory (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 →).

vhdl
library IEEE;
use IEEE.std_logic_1164.all;

entity ped_crossing is
  port ( clk, rst, bA, bB : in  std_logic;
         cars : out std_logic_vector(2 downto 0);   -- (red, yellow, green)
         ped  : out std_logic_vector(1 downto 0) ); -- (red, green)
end ped_crossing;

architecture beh of ped_crossing is
  type state_type is (CG, CY, PG1, PG2, RR);
  signal state, next_state : state_type;
begin
  -- process 1: state register, asynchronous reset (tested first)
  state_register : process (rst, clk)
  begin
    if rst = '1' then
      state <= CG;
    elsif clk'event and clk = '1' then
      state <= next_state;
    end if;
  end process;

  -- process 2: next state and Moore outputs (combinational)
  comb : process (state, bA, bB)
  begin
    next_state <= state;                -- default: stay (last assignment wins)
    case state is
      when CG =>
        cars <= "001";  ped <= "10";
        if bA = '1' or bB = '1' then
          next_state <= CY;
        end if;
      when CY =>
        cars <= "010";  ped <= "10";
        next_state <= PG1;
      when PG1 =>
        cars <= "100";  ped <= "01";
        next_state <= PG2;
      when PG2 =>
        cars <= "100";  ped <= "01";
        next_state <= RR;
      when RR =>
        cars <= "100";  ped <= "10";
        next_state <= CG;
    end case;
  end process;
end beh;

Points to check, which are the usual lost marks:

Step 2: the test bench (point b). Same scheme as in the course: a process generating the clock and a process applying the inputs on the falling edge, away from the active edge.

vhdl
library IEEE;
use IEEE.std_logic_1164.all;

entity test_ped_crossing is
end test_ped_crossing;

architecture test of test_ped_crossing is
  signal clock, reset, bA, bB : std_logic;
  signal cars : std_logic_vector(2 downto 0);
  signal ped  : std_logic_vector(1 downto 0);
  constant bA_seq : std_logic_vector(0 to 17) := "011000000001100000";
  constant bB_seq : std_logic_vector(0 to 17) := "001010010001100000";
  constant PERIOD : time := 100 ns;
begin
  DUT : entity work.ped_crossing(beh)
        port map (clock, reset, bA, bB, cars, ped);

  generate_clock : process
  begin
    clock <= '1'; wait for PERIOD/2;
    clock <= '0'; wait for PERIOD/2;
  end process;

  apply_inputs : process
  begin
    reset <= '1'; bA <= '0'; bB <= '0';
    wait for 3*PERIOD/2;                  -- initial reset: 150 ns
    reset <= '0';
    for i in 0 to 17 loop
      bA <= bA_seq(i);                    -- one pair per cycle,
      bB <= bB_seq(i);                    -- on the falling edge
      wait for PERIOD;
    end loop;
    std.env.stop;
  end process;
end test;

The clock rises at 0,100,200,…0,100,200,\dots ns and falls at 50,150,250,…50,150,250,\dots ns. The reset ends at 150150 ns (a falling edge), and the inputs of cycle kk (k=1,…,18k=1,\dots,18) are applied at 150+100(k−1)150+100(k-1) ns, exactly half a period before the rising edge at 200+100(k−1)200+100(k-1) ns that samples them. The rising edges at 00 and 100100 ns happen with rst='1' and are ignored (the asynchronous reset has priority).

Why this sequence covers everything. The five states are visited (cycles 22 to 66), and from CG all the cases are exercised: no button (cycle 11), only bA (cycle 22), only bB (cycle 88), both (cycle 1313). The pairs 1111 in cycle 33 (state CY), 0101 in cycle 55 (state PG2) and 1111 in cycle 1212 (state RR) check that the buttons are ignored outside the rest state. Expected behaviour, computed with a model that follows the case statement (state and outputs just after each rising edge):

cycle edge (ns) bA bB state after cars ped
1 200 0 0 CG 001 10
2 300 1 0 CY 010 10
3 400 1 1 PG1 100 01
4 500 0 0 PG2 100 01
5 600 0 1 RR 100 10
6 700 0 0 CG 001 10
7 800 0 0 CG 001 10
8 900 0 1 CY 010 10
9 1000 0 0 PG1 100 01
10 1100 0 0 PG2 100 01
11 1200 0 0 RR 100 10
12 1300 1 1 CG 001 10
13 1400 1 1 CY 010 10
14 1500 0 0 PG1 100 01
15 1600 0 0 PG2 100 01
16 1700 0 0 RR 100 10
17 1800 0 0 CG 001 10
18 1900 0 0 CG 001 10

Step 3: reading the waveform (point c). ped becomes "01" when the state becomes PG1: that happens at the rising edge of cycle 33, at 400400 ns (plus a delta cycle in the simulator), as a Moore output it changes only at a clock edge. The edge at 500500 ns moves the machine to PG2, which holds until the edge at 600600 ns: in the interval 500500-600600 ns cars = "100" and ped = "01". Typical mistakes: answering with 250250 ns, the instant at which the first button press is applied (a Moore machine reacts at the next edge, and shows the yellow first); applying the inputs on the rising edge in the test bench (race with the clock); forgetting std.env.stop, which leaves the simulation running forever.

Self-assessment grid
exercise points what must be present for full points typical mistakes
Quiz 1-16 +1+1 each, −0.3-0.3 if wrong the answer, with the calculation or the rule behind it (the rows of the truth table, the group size, the stage delays, the period formula) counting terms instead of rows; maxterm indices equal to the ones of the SOP; ignoring the wrapped corners; setup and hold swapped; slowing the clock to cure hold; clock gating and load enable swapped; COCO read as always 11
Quiz 17-20 +1+1 each, −0.3-0.3 if wrong chips counted as capacity over capacity and address bits split; polling checks as time over check time; vector address supplied by the device; one final interrupt for the DMA forgetting the word width; interrupt as an input of the peripheral; an interrupt per word in DMA
Exercise 1 10 truth table and canonical SOP (3 pts); map with four essential groups and minimal SOP (2 pts); minimal POS and the cost comparison with the correct gate inputs (2 pts); 8-to-1 multiplexer with 0,D,10,D,1 (2 pts); 4-to-1 multiplexer with CDCD and C+DC+D (1 pt) non-adjacent groups; wrong literal sign in the POS; comparing only literals; select inputs in the wrong order
Exercise 2 10 correct state diagram and table with outputs (3 pts); equivalence of the two yellow states by partition refinement (1 pt); equations D2,D1,D0D_2,D_1,D_0 with the unused codes as don't cares (3 pts); five output equations (1 pt); self-start check and simulation (2 pts) merging PG1PG1 and PG2PG2; reacting to the buttons outside the rest state; unused states used as zeros; Moore outputs depending on the inputs
Exercise 3 10 entity and enumerated type (1 pt); register process with asynchronous reset (3 pts); combinational process with full sensitivity list, default and complete assignments (3 pts); test bench with clock, reset, inputs on the falling edge and a sequence that visits all the states (2 pts); correct reading of the waveform (1 pt) missing bA/bB in the sensitivity list; a branch without assignment (latch); reset after the clock test; inputs changed on the rising edge