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 , wrong answer , no answer (at most points); each exercise points; duration 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 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. .
Show the full solution
Go through the truth table: gives on the four rows (minterms ); with the product is only for , i.e. row (minterm ). So , five minterms. The term alone is not a minterm: it lacks and and expands into four of them (). 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 . Its canonical POS form is:
- a.
- b.
- 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 , i.e. of all the indices missing from the SOP: . Check on row (): and there, so the product is . 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 variables exist?
- a. 8
- b. 64
- c. 256
Show the result
c.
Show the full solution
A function is fixed by its truth table, which has rows, and each row can be or independently: functions (in general : for ). The number is the number of rows, not of functions. 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 4
In the Karnaugh map of a function of variables, a rectangular group of 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
A group of cells eliminates variables: , so and the product contains only literal. Options a and b correspond to groups of and cells. 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 5
The function of four variables has the minimal SOP:
- a.
- b.
- c. none of the other answers
Show the result
a.
Show the full solution
Rows , , , 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 and stay constant while and take every value, so the product is . The product would cover rows : 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 or as , whichever makes the groups larger
- c. makes the group that contains it an essential prime implicant
Show the result
b.
Show the full solution
A don't care is a combination that cannot occur or whose output does not matter, so the designer is free: an X inside a group counts as , an X left outside counts as . Covering the Xs is not mandatory, a group made only of Xs is useless, and essential prime implicants are defined on the ones only (an X never makes a group essential). 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 7
The function is implemented with an 8-to-1 multiplexer whose select inputs are and whose data inputs get , , or . The data input is connected to:
- a.
- b.
- c.
Show the result
c. .
Show the full solution
Input is selected when , which corresponds to the pair of rows () and (). Here (4 is a minterm) and (5 is not): equals for and for , i.e. . The full list is (rows : ), (rows : ), , (rows : ), (rows ), (rows ), (rows ), (rows : ). Typical mistake: forgetting that the pair 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 inverters and two-input ANDs) and two-input ANDs. Counting the gate inputs (an inverter counts ), 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 ; two of them cost . The final level has two-input ANDs, each combining one output of the first decoder with one of the second: . Total . The flat solution, inverters and four-input ANDs, costs (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 full adders. The carry crosses each stage in with 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: ns. Option a counts only one gate delay per stage (); 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 is XORed with the control , and is added to the result), when the carry in of the first full adder is:
- a.
- b.
- c.
Show the result
a.
Show the full solution
The same signal drives both the XORs and the carry in of the first full adder. With the XORs give (one's complement) and the carry in supplies the "" of the two's complement: the circuit computes . With it computes with carry in . 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 ns, the critical path of the combinational network is ns and 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
The period must satisfy ns, so MHz. Option a is ns: it forgets that the clock-to-output delay of the flip-flop and the setup time are also part of the path. 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 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
The hold constraint is : it involves only minimum delays and does not contain the clock period, so slowing the clock does not help (it cures setup violations). The cure is to make the shortest path slower. 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 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 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
With load enable the clock goes straight to the flip-flops, so no gate is added on the clock path and no extra skew appears; the register simply recirculates when . Option a is the advantage of clock gating, which is why gating is sometimes still used even though it adds skew. Theory: Registers and Load ControlAn n-bit register is n flip-flops with a common clock, and a counter is a register that steps through a sequence of states. Loading can be controlled by clock gating (an OR with the clock, which saves power but adds delays and clock skew) or, preferably, by load enable (a 2-to-1 MUX before each D input selecting the new data or the flip-flop's own output). Complex systems are split into a datapath (registers and arithmetic-logic blocks) and a control unit (an FSM that sends control signals and receives status signals).Registers and Load Control →.
Quiz 14
A 4-bit synchronous binary counter with enable and carry out is in the state with . At the next active edge:
- a. and
- b. and
- c. and
Show the result
c.
Show the full solution
With the counter adds : (bits and go from to and bit goes from to : a bit toggles when all the lower bits are ). The carry out is only when and the count is , so here it is . Option a gives the right count but the wrong carry; option b would be a count down. Theory: Shift Registers and CountersA shift register is a chain of D flip-flops, each output feeding the next input, so bits move one position per clock edge; it has serial input and output, optional parallel load (Shift has priority over Load) and a bidirectional version with a 4-to-1 MUX per stage (S1S0: 00 hold, 01 shift left, 10 shift right, 11 load). Uses: serial/parallel conversion, serial interfaces, delay lines, pseudo-random generators. Counters step through a sequence of states: the ripple (asynchronous) counter clocks each flip-flop with the previous output and accumulates delay, the synchronous counter uses one clock for all flip-flops and is faster, with EN and CO for cascading.Shift Registers and Counters →.
Quiz 15
In a ripple (asynchronous) counter with flip-flops, each with propagation delay 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
Each flip-flop is clocked by the output of the previous one, so the changes propagate in cascade. In the transition all six flip-flops switch one after the other, and the outputs pass through intermediate values for ns. Reading the counter in that interval gives wrong values; the synchronous counter has all the flip-flops on the same clock and does not suffer from this. Theory: Shift Registers and CountersA shift register is a chain of D flip-flops, each output feeding the next input, so bits move one position per clock edge; it has serial input and output, optional parallel load (Shift has priority over Load) and a bidirectional version with a 4-to-1 MUX per stage (S1S0: 00 hold, 01 shift left, 10 shift right, 11 load). Uses: serial/parallel conversion, serial interfaces, delay lines, pseudo-random generators. Counters step through a sequence of states: the ripple (asynchronous) counter clocks each flip-flop with the previous output and accumulates delay, the synchronous counter uses one clock for all flip-flops and is faster, with EN and CO for cascading.Shift Registers and Counters →.
Quiz 16
A bidirectional shift register has the control : hold, shift left, shift right, parallel load. With , right serial input and , after one clock edge is:
- a. 1100
- b. 1011
- c. 0110
Show the result
b.
Show the full solution
is shift right: every bit moves one position towards and enters . From : new , new = old , new = old , new = old , so . Option a is the shift left with serial input ; option c is the hold (). Theory: Shift Registers and CountersA shift register is a chain of D flip-flops, each output feeding the next input, so bits move one position per clock edge; it has serial input and output, optional parallel load (Shift has priority over Load) and a bidirectional version with a 4-to-1 MUX per stage (S1S0: 00 hold, 01 shift left, 10 shift right, 11 load). Uses: serial/parallel conversion, serial interfaces, delay lines, pseudo-random generators. Counters step through a sequence of states: the ripple (asynchronous) counter clocks each flip-flop with the previous output and accumulates delay, the synchronous counter uses one clock for all flip-flops and is faster, with EN and CO for cascading.Shift Registers and Counters →.
Quiz 17
A memory is built with chips of . The number of chips needed is:
- a. 4
- b. 16
- c. none of the other answers
Show the result
c. chips.
Show the full solution
Number of chips = required capacity divided by chip capacity: . Equivalently: two chips side by side give the bits of the word (same addresses), and such pairs give the words. The address bits split into that go to every chip and that drive a 2-to-4 decoder enabling one pair of chips (chip select). Option a counts only the words () 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 bytes per second. With programmed I/O, the CPU needs 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
One byte every ms. In that time the CPU makes checks, almost all useless (busy-wait). With interrupts the interface would signal the CPU only times per second. 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 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
Vectored means that the requesting device sends the vector address of its own service routine, so the CPU knows where to jump without searching; in a non-vectored system the routine is at a fixed location. Option b describes the software polling used to find the source, option c is reversed: the interrupt is an output of the peripheral and an input of the CPU. 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 20
A DMA controller transfers a block of 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 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 ( = sensor active). The alarm must be on () when at least three of the four sensors are active, and off otherwise (all the combinations can occur).
a) Write the truth table, the canonical SOP form and the Karnaugh map of , 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 with an 8-to-1 multiplexer, using as select inputs ( most significant) and without any other gate.
d) Implement with a 4-to-1 multiplexer with as select inputs, using the minimum number of additional gates.
Show the result
a) . Minimal SOP: (four groups of cells, all essential; literals).
b) . Minimal POS: ( sums, literals). Cost: SOP gate inputs, POS . The SOP costs less.
c) : , , .
d) : , , ; one AND and one OR (two gates, gate inputs).
Show the full solution
Step 1: truth table and canonical form (point a). The function counts the ones among the inputs: if (here is the arithmetic sum of the bits). Rows are numbered in binary:
| row | ones | ||
|---|---|---|---|
| 0-6 | to | to | 0 |
| 7 | 0111 | 3 | 1 |
| 8, 9, 10 | or | 0 | |
| 11 | 1011 | 3 | 1 |
| 12 | 1100 | 2 | 0 |
| 13 | 1101 | 3 | 1 |
| 14 | 1110 | 3 | 1 |
| 15 | 1111 | 4 | 1 |
So (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 , hence rows with (the maxterms of point b).
Step 2: the map and the minimal SOP. Map with rows and columns in Gray order ():
| 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 (row , columns ): ( changes);
- cells (row , columns ): ( changes);
- cells (column , rows ): ( changes);
- cells (column , rows ): ( changes).
Each is essential: minterm is covered only by , only by , only by , only by (cell is shared by all four). No larger group exists: there is no row, column or square of four ones. Hence (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: gives , so ; gives all products , so .
Step 3: the POS (point b). Group the zeros: the map has zeros and every zero belongs to a group of four cells where two variables are . For instance cells (row ): in the group and are constant, giving the product for , hence the sum for (variables that are in the group enter direct). The six groups are the rows and columns of the map where two variables are both :
- (cells ) gives ; (cells ) gives ; (cells ) gives ;
- (cells ) gives ; (cells ) gives ; (cells ) gives .
All six are essential (cell only in the first, only in the second, in the third, in the fourth, in the fifth, in the sixth). So It says in words what the function is: "at least three ones" is the same as "among any two variables at least one is ". Cost in gate inputs (the literals are all direct, so no inverters): SOP, four 3-input ANDs and a 4-input OR, ; POS, six 2-input ORs and a 6-input AND, . Same number of literals (), 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 to . For each select value the multiplexer picks one data input, and that input must supply for both values of (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 →):
| rows () | |||
|---|---|---|---|
| 000 | 0, 1 | ||
| 001 | 2, 3 | ||
| 010 | 4, 5 | ||
| 011 | 6, 7 | ||
| 100 | 8, 9 | ||
| 101 | 10, 11 | ||
| 110 | 12, 13 | ||
| 111 | 14, 15 |
So , , the others : no other gate is needed. Check with : selects , (three sensors active). Typical mistakes: swapping the order of the select inputs ( must go to , the most significant), or using where the pair is .
Step 5: the 4-to-1 multiplexer (point d). Now only are selects, and the data inputs are functions of taken from the four sub-maps (rows of the map):
| as a function of () | data input | |
|---|---|---|
| 00 | ||
| 01 | ||
| 10 | ||
| 11 |
One AND (feeding and ) and one OR (feeding ) are enough. Interpretation: with one more active sensor is enough, with a single active sensor among both and 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 while the button is pressed. The cars have a traffic light with three lamps, red, yellow and green (outputs ), the pedestrians a light with two lamps, red and green (outputs ). Behaviour:
- after reset and at rest: cars green, pedestrians red; the machine stays in this condition while ;
- 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 flip-flops with the assignment , , , , (the other three codes are never used) and find the minimal equations of the D inputs (), using 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 : (one per cycle).
Show the result
a) Five states: (, ), (, ), (, ), (, ), (, ). Transitions: if , if ; whatever the input. In the six-state draft the states and (yellow after / after ) are equivalent.
b) ; ; , with .
c) ; ; ; ; .
d) The machine is self-starting: (if ) or (if ); ; .
e) States after the successive edges: .
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 ( goes to , goes to ) and the second one counts the second cycle. State table (next state for and , where , i.e. only for ; outputs and ):
| state | meaning | next if | next if | ||
|---|---|---|---|---|---|
| rest | 001 | 10 | |||
| cars yellow | 010 | 10 | |||
| pedestrians green, 1st cycle | 100 | 01 | |||
| pedestrians green, 2nd cycle | 100 | 01 | |||
| both red | 100 | 10 |
Diagram to redraw: five circles with the output written inside, an arrow entering labelled ; a loop on labelled " and "; an arrow labelled " or "; unlabelled arrows (any input) .
Equivalent states in the six-state draft. A student who records which button started the sequence draws two yellow states: (reached when ) and (reached when ), both leading to and both with the same lamps. The equivalence method (partition refinement) starts by grouping states with the same output: . Refine: goes to (block ) while goes to (another block), so they are split; and both go to for every input, so they stay together. The partition no longer changes: , they merge into , giving five states instead of six. Reason: after the press the machine does not need to remember who pressed. With states flip-flops are needed. Typical mistake: merging and 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 . The table of the next code (variables , input ):
| state | code | next () | next () |
|---|---|---|---|
| 000 | 000 | 001 | |
| 001 | 011 | 011 | |
| 011 | 010 | 010 | |
| 010 | 110 | 110 | |
| 110 | 000 | 000 | |
| unused | 100, 101, 111 | X | X |
The codes never occur, so for both values of they are don't cares. Maps with rows and columns in Gray order ():
(next code only from ):
| 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 and (state , any ): they form a group of two cells with , , constant, so . (The row , state , has zeros and prevents enlarging the group with .)
(next codes have : from , , ):
| 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 cells with (columns , using the Xs of rows ): ; the row ( cells): . .
(next code from with , from , and gives , so only for with and for ):
| 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 () with (rows ): ; columns () with : . . Replacing : . 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 simplify them:
| lamp | on in states | map reading | equation |
|---|---|---|---|
| all states with (also is X) | |||
| (with as X) | |||
| (with as X) | |||
| or | |||
| and |
Check: in each of the five states exactly one cars lamp and one pedestrian lamp are on; and are complementary on the used states ( in the used codes).
Step 4: unused states (point d). If noise brings the machine to or it must come back to the normal sequence. Evaluating the equations: gives , , , so the next state is () or (): or . State : , , , next . State : (), , (), next . 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 (state before each edge, inputs applied during the cycle, state after the edge):
| edge | state before | state after | lamps after (cars, ped) | ||
|---|---|---|---|---|---|
| 1 | 00 | 0 | green, red | ||
| 2 | 10 | 1 | yellow, red | ||
| 3 | 11 | 1 | red, green (button ignored) | ||
| 4 | 00 | 0 | red, green | ||
| 5 | 01 | 1 | red, red (button ignored) | ||
| 6 | 00 | 0 | green, red | ||
| 7 | 00 | 0 | 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 , , or : 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 ns (rising edge at , , ns, ...), an initial reset of 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, 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 ns and 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 ns, then for i in 0 to 17 loop applying bA_seq(i), bB_seq(i) and wait for PERIOD). The cycles give the states after the edges at ns.
c) First ped = "01" at the edge at ns (state PG1); between and 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 →).
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:
- the sensitivity list of process 1 contains
rstandclk, the one of process 2 contains all the signals it reads (state,bA,bB), otherwise the simulation would not react to the inputs; - in process 2 every branch assigns
cars,pedandnext_state(the default coversnext_state), so no latch is inferred (VHDL - Concurrent Statements, Processes and TestbenchesConcurrent VHDL statements are the plain signal assignment, when-else (priority logic, conditions evaluated in order) and with-select (parallel logic, every case covered once, others required). A process is a concurrent statement with a sequential body (if, case, loop) that wakes up when a signal in its sensitivity list changes; for combinational logic the list holds all inputs; signals are updated when the process suspends and the last assignment wins. An if without else or an uncovered case creates unwanted memory. A testbench has an empty entity, the instantiated DUT and a stimulus process with wait statements.VHDL - Concurrent Statements, Processes and Testbenches →); - the buttons are read only in
CG, as required: in the other states they are ignored; - the values of
carsandpeddepend only onstate, which makes it a Moore machine (the outputs change only after a clock edge).
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.
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 ns and falls at ns. The reset ends at ns (a falling edge), and the inputs of cycle () are applied at ns, exactly half a period before the rising edge at ns that samples them. The rising edges at and ns happen with rst='1' and are ignored (the asynchronous reset has priority).
Why this sequence covers everything. The five states are visited (cycles to ), and from CG all the cases are exercised: no button (cycle ), only bA (cycle ), only bB (cycle ), both (cycle ). The pairs in cycle (state CY), in cycle (state PG2) and in cycle (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 , at ns (plus a delta cycle in the simulator), as a Moore output it changes only at a clock edge. The edge at ns moves the machine to PG2, which holds until the edge at ns: in the interval - ns cars = "100" and ped = "01". Typical mistakes: answering with 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 | each, 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; read as always |
| Quiz 17-20 | each, 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 (2 pts); 4-to-1 multiplexer with and (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 with the unused codes as don't cares (3 pts); five output equations (1 pt); self-start check and simulation (2 pts) | merging and ; 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 |