Digital Systems - Exam of 21 June 2022
Questa pagina non ha ancora la versione ripasso: qui sotto c'è il testo completo.
In questa pagina 24
Exam of the equivalent Italian-language course, Circuiti Digitali (Engineering, University of Padova), first sitting, 21 June 2022, translated into English. The paper has two parts: 20 multiple-choice questions (three answers each, one correct; the sheet says that wrong answers have a negative score and unanswered ones do not, without giving the amounts) and 3 exercises written on the sheet. The sheet gives no points for the exercises and no duration. Books, notes, calculators and colleagues are not allowed.
The official solution is not public. Every answer below was derived from the course notes and checked: the truth tables were enumerated by a script, the minimisation was compared with a symbolic algebra system, and both state machines were simulated on input sequences. Where a question is ambiguous this is said explicitly. The syllabus of this course covers every question of the paper.
Quiz 1
The precision of a digital system can be improved:
- a. by increasing the number of bits used to represent the processed information
- b. by widening the range of the physical quantity (e.g. voltage) used to represent one bit of information
- c. none of the above
Show the result
a.
Show the full solution
Precision is the size of the smallest step that can be represented, and it depends on how many bits are used: bits give values, so more bits mean smaller steps. A wider voltage range (b.) changes the noise margins, not the precision. Theory: Digital Systems - Signals, Binary Information and Abstraction LevelsA digital system processes discrete quantities; a binary one encodes them with two voltage ranges (0 and 1), the input range being wider than the output range, which gives noise margins and a regenerative property. Precision depends on the number of bits. A computer is memory, CPU (control unit plus datapath) and I/O. Design proceeds through abstraction levels from algorithm to transistor, following a flow from specification to verification.Digital Systems - Signals, Binary Information and Abstraction Levels →.
Quiz 2
In a top-down approach:
- a. one starts from the high-level specifications and then splits the system into smaller and smaller blocks
- b. one starts from the elementary blocks, which are progressively assembled to obtain the desired function
- c. none of the above
Show the result
a.
Show the full solution
Top-down means from the specification (a black box) down to blocks that can be built. Answer b. describes the opposite approach, bottom-up. Theory: Digital Systems - Signals, Binary Information and Abstraction LevelsA digital system processes discrete quantities; a binary one encodes them with two voltage ranges (0 and 1), the input range being wider than the output range, which gives noise margins and a regenerative property. Precision depends on the number of bits. A computer is memory, CPU (control unit plus datapath) and I/O. Design proceeds through abstraction levels from algorithm to transistor, following a flow from specification to verification.Digital Systems - Signals, Binary Information and Abstraction Levels →.
Quiz 3
In the hexadecimal system:
- a. each hexadecimal digit corresponds to two binary digits
- b. each hexadecimal digit corresponds to three binary digits
- c. each hexadecimal digit corresponds to four binary digits
Show the result
c.
Show the full solution
There are hexadecimal digits, so each one needs exactly 4 bits (). Two bits would give only 4 symbols, three bits (octal) 8. Theory: Number Systems and Base ConversionsA number in base r is the sum of a_i r^i with digits from 0 to r-1. Conversions: base r to decimal by weighted sum; decimal to base r by successive divisions (integer part, remainders read bottom-up) and successive multiplications (fractional part, integer parts read top-down); binary to octal or hexadecimal by groups of 3 or 4 bits starting from the radix point. Binary sum, difference and product follow the decimal rules with borrows and shifted partial products.Number Systems and Base Conversions →.
Quiz 4
In a Gray code:
- a. exactly one bit changes when passing from one code word to the next
- b. at most two bits change when passing from one code word to the next
- c. none of the above
Show the result
a.
Show the full solution
The defining property of a Gray code is Hamming distance between consecutive words: one bit changes. Statement b. is too weak: it would also be true of codes that are not Gray, so it is not the property that characterises the code (a possible ambiguity of the text: literally, "at most two" is also satisfied by a Gray code, but a. is the exact statement). Theory: Binary Codes - BCD, ASCII, Unicode, Parity and GrayAn n-bit code distinguishes 2^n elements. BCD encodes each decimal digit on 4 bits (1010 to 1111 unused; it differs from the plain binary of the number). ASCII uses 7 bits for 128 characters; Unicode UTF-8 uses 1 to 4 bytes and is ASCII compatible. A parity bit detects errors on an odd number of bits. Hamming distance is the number of differing bits. Gray code makes consecutive numbers differ by one bit and is built by reflection or with g_i = b_i xor b_(i+1).Binary Codes - BCD, ASCII, Unicode, Parity and Gray →.
Quiz 5
The Hamming distance between the representations of two numbers is:
- a. the number of bits that differ between the two representations
- b. the algebraic difference between the two representations
- c. none of the above
Show the result
a.
Show the full solution
Hamming distance counts the positions where the two words differ, for example and have distance even though the numbers and differ by . It is not an algebraic difference. Theory: Binary Codes - BCD, ASCII, Unicode, Parity and GrayAn n-bit code distinguishes 2^n elements. BCD encodes each decimal digit on 4 bits (1010 to 1111 unused; it differs from the plain binary of the number). ASCII uses 7 bits for 128 characters; Unicode UTF-8 uses 1 to 4 bytes and is ASCII compatible. A parity bit detects errors on an odd number of bits. Hamming distance is the number of differing bits. Gray code makes consecutive numbers differ by one bit and is built by reflection or with g_i = b_i xor b_(i+1).Binary Codes - BCD, ASCII, Unicode, Parity and Gray →.
Quiz 6
Which of the following statements is correct?
- a.
- b.
- c. none of the above
Show the result
b.
Show the full solution
XOR is associative: , then . Equivalently, the XOR of several bits is when the number of ones is odd: here there are two ones (even), so the result is . Theory: Boolean Algebra - Axioms, Theorems and Function ComplementBoolean algebra works on two-valued variables with AND, OR, NOT. Fundamental identities (identity element, idempotence, complement, commutative, associative, both distributive laws) come in dual pairs; De Morgan, absorption, adjacency and consensus are the main theorems, proved by perfect induction or algebraically. The complement of a function is obtained with De Morgan or with the dual plus literal negation. Cost is measured in literals or gate inputs.Boolean Algebra - Axioms, Theorems and Function Complement →, Logic Gates, Gate Delay and Universal GatesAND, OR, NOT implement the Boolean operations; NAND, NOR, XOR and XNOR derive from them. Every function is described by a truth table with 2^n rows. Multi-input XOR is the odd-parity function. An ideal gate has zero delay; a real gate has a propagation delay t_G (different for 0 to 1 and 1 to 0), so the output changes t_G after the input. NAND and NOR are each universal.Logic Gates, Gate Delay and Universal Gates →.
Quiz 7
The absorption theorem states that:
- a.
- b.
- c.
Show the result
a.
Show the full solution
. In b. the whole left side is negated, so it equals , not ; in c. the right side is wrong ( gives on the left and on the right). Theory: Boolean Algebra - Axioms, Theorems and Function ComplementBoolean algebra works on two-valued variables with AND, OR, NOT. Fundamental identities (identity element, idempotence, complement, commutative, associative, both distributive laws) come in dual pairs; De Morgan, absorption, adjacency and consensus are the main theorems, proved by perfect induction or algebraically. The complement of a function is obtained with De Morgan or with the dual plus literal negation. Cost is measured in literals or gate inputs.Boolean Algebra - Axioms, Theorems and Function Complement →.
Quiz 8
The consensus theorem states that:
- a.
- b.
- c.
Show the result
a.
Show the full solution
The term is the consensus of and and is redundant: , and is absorbed by , by . Counterexamples to the others: for the left side is and (b. false); for the left side is and (c. false). Theory: Boolean Algebra - Axioms, Theorems and Function ComplementBoolean algebra works on two-valued variables with AND, OR, NOT. Fundamental identities (identity element, idempotence, complement, commutative, associative, both distributive laws) come in dual pairs; De Morgan, absorption, adjacency and consensus are the main theorems, proved by perfect induction or algebraically. The complement of a function is obtained with De Morgan or with the dual plus literal negation. Cost is measured in literals or gate inputs.Boolean Algebra - Axioms, Theorems and Function Complement →.
Quiz 9
A minterm is:
- a. a sum of products in which all variables appear, direct or negated
- b. a product in which all variables appear, direct or negated
- c. a sum in which all variables appear, direct or negated
Show the result
b.
Show the full solution
A minterm is an AND of all the variables, each direct or complemented: it equals on exactly one row of the truth table. Answer a. describes a canonical SOP (a sum of minterms), answer c. a maxterm (an OR of all the variables). 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 10
A logic expression in SOP form:
- a. can be implemented with a circuit with two levels of logic gates
- b. can be implemented with a single level of logic gates
- c. none of the above
Show the result
a.
Show the full solution
A sum of products is an OR of AND terms: a first level of AND gates (one per product) and a second level with one OR gate. The inverters of the inputs are not counted as a level. One level only is possible just for degenerate expressions with a single term. 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 →, Combinational Design - Hierarchy and NAND-NOR MappingA combinational circuit has outputs depending only on the present inputs (no memory, no feedback); a sequential one also depends on history (state, memory, feedback). Design flow: specification, truth table, minimum-cost function, logic diagram, verification. With many inputs the hierarchical approach splits the system into reusable blocks (regularity). Basic blocks: one-variable functions, vectors, enabling. Technology mapping in CMOS: SOP to NAND-NAND, POS to NOR-NOR.Combinational Design - Hierarchy and NAND-NOR Mapping →.
Quiz 11
The following VHDL fragment, where a is a std_logic signal declared in the entity as out:
a <= '1';
a <= '0';- a. does not generate errors if inserted alone, without other elements, in the body of an architecture
- b. can be used only in a test bench
- c. none of the above
Show the result
c.
Show the full solution
Statements written directly in the body of an architecture are concurrent: each assignment is a separate driver of a. Two drivers with different values ('1' and '0') make the signal 'X' in simulation (conflict) and cannot be synthesised: it is a design error, so a. is false. Answer b. is false too: the same two lines are legal inside a process, where they are sequential and the last assignment wins (a ends at '0'), and this is used in processes of any design, not only in test benches. Hence c.
Remark on the text: a VHDL compiler does accept the two lines (std_logic is a resolved type), so "no errors" is true only at compilation; the error appears at simulation () and at synthesis, which is why a. is not the intended answer. Theory: 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 →, VHDL - Entity, Architecture, Types and Description LevelsVHDL is a hardware description language, not a programming language: its statements are concurrent and describe blocks of circuit, used to document, simulate and synthesise. A block has an entity (name and in/out ports) and at least one architecture (what is inside) written in structural style with components and port map, dataflow style with Boolean equations, or behavioral style. Types include std_logic with values 0, 1, X, Z, U and -, std_logic_vector, bit, boolean and integer; signal is used for internal connections and constant for fixed values.VHDL - Entity, Architecture, Types and Description Levels →.
Quiz 12
A VHDL description of dataflow type:
- a. always leads to a more optimised synthesis than a behavioral description
- b. makes exclusive use of direct instantiations
- c. none of the above
Show the result
c.
Show the full solution
Dataflow describes the circuit with concurrent assignments (Boolean equations, when, select). The quality of the synthesised circuit depends on the tool and on the circuit, not on the style: "always" makes a. false. Direct instantiation of components (port map) is the structural style, so b. is false. Theory: VHDL - Entity, Architecture, Types and Description LevelsVHDL is a hardware description language, not a programming language: its statements are concurrent and describe blocks of circuit, used to document, simulate and synthesise. A block has an entity (name and in/out ports) and at least one architecture (what is inside) written in structural style with components and port map, dataflow style with Boolean equations, or behavioral style. Types include std_logic with values 0, 1, X, Z, U and -, std_logic_vector, bit, boolean and integer; signal is used for internal connections and constant for fixed values.VHDL - Entity, Architecture, Types and Description Levels →.
Quiz 13
The two's complement representation of the number on 8 bits is:
- a. 11111101
- b. 11111100
- c. 10000011
Show the result
a. ()
Show the full solution
. Invert all bits: (one's complement); add : . Check: . Answer b. is the one's complement of ; answer c. is the sign-and-magnitude representation ( followed by ). Theory: Signed Numbers, Complement Arithmetic and OverflowUnsigned subtraction is correct without borrow out; otherwise the result M-N+2^n is wrong. One's complement is 2^n-1-N (bitwise inversion); two's complement is 2^n-N (one's complement plus 1). Signed numbers: sign-magnitude (two zeros, symmetric range) or two's complement (one zero, range -2^(n-1) to 2^(n-1)-1, MSB weight -2^(n-1)). In two's complement addition and subtraction are the same adder: A-B = A + not B + 1, carry out discarded. Overflow: unsigned if carry out is 1 in an addition; signed if the carry into the sign bit differs from the carry out of it.Signed Numbers, Complement Arithmetic and Overflow →.
Quiz 14
In a Mealy finite state machine:
- a. the state and the outputs always change at the same moment
- b. the state is a function of the output
- c. none of the above
Show the result
c.
Show the full solution
In a Mealy machine the output is a function of the present state and of the inputs: when an input changes, the output may change between two clock edges, while the state changes only at the clock edge. So a. is false. The state is not a function of the output (it is the output that is a function of the state), so b. is false. Theory: 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 →.
Quiz 15
The setup time is:
- a. the time for which the input signal of a flip-flop must remain stable before the arrival of the clock edge, to guarantee that the data is captured
- b. the time for which the input signal of a flip-flop must remain stable after the arrival of the clock edge, to guarantee that the data is captured
- c. the propagation time of a flip-flop
Show the result
a.
Show the full solution
Setup time: data stable before the active edge. Answer b. is the hold time (stable after the edge); c. is the clock-to-output delay. Theory: Timing of Sequential Systems - Setup, Hold and Maximum Clock FrequencyA flip-flop stores the right value only if its input is stable for the setup time before and the hold time after the clock edge, and its output changes after the propagation delay. In a synchronous circuit the clock period must satisfy T >= t_pd,FF + t_COMB + t_s,FF + t_slack, which fixes the maximum frequency; slowing the clock cures setup violations but not hold violations, which require t_pd,FF,min + t_COMB,min >= t_h. Clock skew modifies both constraints.Timing of Sequential Systems - Setup, Hold and Maximum Clock Frequency →.
Quiz 16
A sequential access memory:
- a. allows access to memory locations at consecutive addresses faster than at arbitrary addresses
- b. allows access to all memory locations at the same speed, regardless of the order of the accesses
- c. none of the above
Show the result
a.
Show the full solution
In a sequential (serial) access memory, such as a magnetic tape or a CD, the access time depends on the position of the data, so consecutive locations are faster than arbitrary ones. Answer b. describes a random access memory (RAM). 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 →, Memories - ROM, RAM, SRAM and DRAMA memory is a set of cells organised in words, with control circuitry. It is classified as read-only (ROM) or read/write, random access (RAM), serial (SAM) or hybrid (Flash), volatile (SRAM, DRAM) or non-volatile. A RAM 2^k x n has k address bits (independent of n), n data bits, read/write and chip select. SRAM uses a bistable latch cell, is fast and needs no refresh; DRAM stores charge on a capacitor, is denser and needs refresh. Chips are organised as a row/column matrix with coincident selection and tri-state outputs, and combined in arrays for more words or more bits per word.Memories - ROM, RAM, SRAM and DRAM →.
Quiz 17
The instruction register contains:
- a. the address of the next instruction to execute
- b. the number of instructions executed
- c. the instruction currently being executed
Show the result
c.
Show the full solution
The instruction register (IR) keeps the fetched instruction for the whole time it is executed, so that the control unit can decode it. The address of the next instruction is in the program counter (a.); nothing counts the executed instructions (b.). Theory: Simple Computer - Instruction Set, Single-Cycle and Multi-Cycle ControlThe 16-bit instruction word has an opcode of 7 bits plus register fields (DR, SA, SB or an immediate OP) or a branch format with a 6-bit PC-relative signed offset; the instruction set is load/store with ADD, SUB, logic, shifts, LDI, ADI, LD, ST, BRZ, BRN and JMP. In the single-cycle computer (separate instruction and data memories) a combinational instruction decoder derives MB, MD, RW, MW, PL, JB, BC from bits 15, 14, 13 and 9 and FS from bits 12 to 9, and the clock period is the sum of the delays on the critical path (9.8 ns in the example). In the multi-cycle computer (one memory) an instruction register, internal registers R8 to R15 and a sequential decoder are needed: fetch (INF) plus one or more execution states.Simple Computer - Instruction Set, Single-Cycle and Multi-Cycle Control →.
Quiz 18
A microprocessor with a microprogrammed decoding unit:
- a. allows operations of any complexity to be performed in a single clock cycle
- b. allows instructions that require more clock cycles to be implemented
- c. none of the above
Show the result
b.
Show the full solution
A microprogrammed control unit is a state machine that executes an instruction as a sequence of steps, one per clock cycle: complex instructions simply take more cycles. No control unit can do an arbitrarily complex operation in one cycle (a. false). Theory: Simple Computer - Instruction Set, Single-Cycle and Multi-Cycle ControlThe 16-bit instruction word has an opcode of 7 bits plus register fields (DR, SA, SB or an immediate OP) or a branch format with a 6-bit PC-relative signed offset; the instruction set is load/store with ADD, SUB, logic, shifts, LDI, ADI, LD, ST, BRZ, BRN and JMP. In the single-cycle computer (separate instruction and data memories) a combinational instruction decoder derives MB, MD, RW, MW, PL, JB, BC from bits 15, 14, 13 and 9 and FS from bits 12 to 9, and the clock period is the sum of the delays on the critical path (9.8 ns in the example). In the multi-cycle computer (one memory) an instruction register, internal registers R8 to R15 and a sequential decoder are needed: fetch (INF) plus one or more execution states.Simple Computer - Instruction Set, Single-Cycle and Multi-Cycle Control →, Machine Instructions, Addressing Modes, RISC and CISCA machine instruction is a fixed-width word split into an opcode and operand fields; in a load/store architecture only load and store reach memory, and operands are given by a few addressing modes (register, register indirect, immediate, PC-relative). RISC machines use simple fixed-length instructions that fit one pass through the pipeline, 32 registers with R0 equal to 0 and four addressing modes; CISC machines have complex variable-length instructions, many addressing modes and a microprogrammed control (a ROM-based state machine) taking several cycles.Machine Instructions, Addressing Modes, RISC and CISC →.
Quiz 19
What is the correct sequence of the functional units in a 4-stage microprocessor pipeline?
- a. IF, DOF, EX, WB
- b. DOF, IF, WB, EX
- c. IF, DOF, WB, EX
Show the result
a.
Show the full solution
An instruction is first fetched (IF, instruction fetch), then decoded with its operands read (DOF, decode and operand fetch), then executed (EX) and finally its result is written back (WB). The other orders put the decode before the fetch or the write-back before the execution. Theory: Pipelining and HazardsA pipeline splits execution into stages separated by registers (IF, DOF, EX, WB) working in parallel on different instructions; latency stays the same while throughput grows by less than the number of stages (flip-flop delays, slowest stage). With k stages and N instructions k+N-1 cycles are needed. Hazards stall the pipeline: data hazards (operand not yet written; fixes are NOPs, stalls and forwarding) and control hazards (branches; fixes are NOPs or branch prediction with bubbles).Pipelining and Hazards →.
Quiz 20
An interrupt:
- a. is an output signal of the CPU and an input signal of the peripheral
- b. is an input signal of the CPU and an output signal of the peripheral
- c. is a bidirectional signal between the CPU and the peripheral
Show the result
b.
Show the full solution
The peripheral raises the interrupt to tell the CPU that data are ready: it is an output of the peripheral and an input of the CPU, which suspends the current program and runs the service routine. 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 →.
Exercise 1
Minimise the logic equation controlling segment 2 of the following seven-segment display using Karnaugh maps. The circuit has as inputs the variables , which represent the bits of the number to display, from 0 to 9, from the least significant () to the most significant (), and as output , which must be when the segment has to be lit and otherwise.
The segments are numbered like this (the figure of the sheet):
0 0 0
5 1
5 1
5 1
6 6 6
4 2
4 2
4 2
3 3 3Report the Karnaugh map with the groupings used to simplify the function and the final equation obtained, exploiting the don't care conditions in a suitable way.
Show the result
Segment 2 is the lower right one: it is lit for all digits except . Inputs ( most significant); with don't cares . Three groups of 8 cells:
Show the full solution
Step 1: which digits light segment 2. In the figure segment 2 is the lower right vertical bar. In the usual shapes of the digits (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 →, BCD to seven segments) it is lit for and off only for (the digit uses top, upper right, middle, lower left and bottom). The doubtful shapes ( with or without the top bar, with or without the upper left bar, with or without the bottom bar) do not change segment 2.
Step 2: truth table. Four bits are needed for to ; the six combinations never occur and are don't care (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 →).
| number | ||
|---|---|---|
| 0 | 0000 | 1 |
| 1 | 0001 | 1 |
| 2 | 0010 | 0 |
| 3 | 0011 | 1 |
| 4 | 0100 | 1 |
| 5 | 0101 | 1 |
| 6 | 0110 | 1 |
| 7 | 0111 | 1 |
| 8 | 1000 | 1 |
| 9 | 1001 | 1 |
| 10-15 | 1010-1111 | X |
Step 3: Karnaugh map. Rows , columns , both in Gray order so that adjacent cells differ by one variable:
| 00 | 01 | 11 | 10 | |
|---|---|---|---|---|
| 00 | 1 | 1 | 1 | 0 |
| 01 | 1 | 1 | 1 | 1 |
| 11 | X | X | X | X |
| 10 | 1 | 1 | X | X |
(the only is the cell , number ; the cells of the row are ).
Step 4: groupings. With the don't cares used as where useful, three groups of 8 cells, the largest possible (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 →):
- columns and (all four rows): constant, giving the term (cells );
- rows and (all four columns): constant, giving the term (cells );
- columns and (adjacent, all four rows): constant, giving the term (cells ).
All three are essential: cell () is covered only by the first group, cell () only by the second, cell () only by the third. The don't care is left uncovered (treated as ): it is not needed, since the three groups already cover all the s.
Step 5: equation. Meaning: segment 2 is off only when , , (that is, the number is or the don't care ), whatever is: by De Morgan (Boolean Algebra - Axioms, Theorems and Function ComplementBoolean algebra works on two-valued variables with AND, OR, NOT. Fundamental identities (identity element, idempotence, complement, commutative, associative, both distributive laws) come in dual pairs; De Morgan, absorption, adjacency and consensus are the main theorems, proved by perfect induction or algebraically. The complement of a function is obtained with De Morgan or with the dual plus literal negation. Cost is measured in literals or gate inputs.Boolean Algebra - Axioms, Theorems and Function Complement →). The circuit is one inverter and one 3-input OR. The same function can be written as a single product of sums, , so the POS and SOP minimisations coincide.
Check. The equation gives for all nine digits other than and for . A script also compared it with the minimisation of sympy (SOP and POS, with the don't cares): same result.
Without don't cares the minimal form would be , with 6 literals instead of 3.
Typical mistakes: reading as the most significant bit (the sheet says is the least significant and the most significant); mixing up segment 2 with segment 1 (which is also lit for ); not using the don't cares; ordering the rows or columns of the map in binary instead of Gray order; leaving unsimplified.
Exercise 2
Draw 1) the symbol with inputs and outputs and 2) the state diagram, without equivalent states, complete with all transitions and all signals, of a coffee machine with these characteristics:
- there are two buttons, coffee and cappuccino, that generate a pulse of one clock cycle when pressed on the lines
caffè_btnandcapp_btnrespectively; - the machine has a coffee dispenser and a milk dispenser, activated by a pulse of one clock cycle on the lines
caffè_erandlatte_er; - when the coffee button is pressed, the machine must activate the coffee dispenser for one whole clock cycle;
- when the cappuccino button is pressed, the machine must activate the milk dispenser for two whole clock cycles and then the coffee dispenser for one whole clock cycle;
- while milk or coffee is being dispensed, any button presses are ignored.
Show the result
Moore machine with 4 states, all pairwise non-equivalent (outputs caffè_er, latte_er):
- IDLE ():
caffè_btn=1goes to CAFFE; otherwisecapp_btn=1goes to LATTE1; otherwise stays in IDLE; - LATTE1 () goes to LATTE2 whatever the inputs;
- LATTE2 () goes to CAFFE whatever the inputs;
- CAFFE () goes to IDLE whatever the inputs.
Cappuccino pressed in cycle : latte_er=1 in cycles and , caffè_er=1 in cycle . Symbol: inputs caffè_btn, capp_btn, clock, reset; outputs caffè_er, latte_er.
Show the full solution
Step 1: symbol. A rectangle with four inputs on the left, caffè_btn, capp_btn, clock, reset, and two outputs on the right, caffè_er and latte_er (all of one bit). The text does not mention a reset, but a state machine needs one to start from a known state (Finite State Machines - SynthesisSynthesis of a synchronous sequential circuit follows specifications, state diagram, state table (merging equivalent states), binary state encoding, choice of D flip-flop, flip-flop input and output equations, minimisation, circuit and verification. A state summarises the useful part of history; a sequence recogniser has one state per recognised prefix, reusing states for overlaps. A reset gives a known initial state. Gray encoding (minimum flip-flops) versus one-hot (one flip-flop per state, simpler logic): for the 1101 recogniser Gray costs about half.Finite State Machines - Synthesis →).
Step 2: type of machine and states. The outputs are fixed pulses of a whole clock cycle, decided by what the machine is doing and not by the instantaneous value of the buttons: a Moore machine, with the outputs written inside the states (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 →). The states are the situations to be remembered:
- IDLE: waiting for a button, both outputs ;
- LATTE1 and LATTE2: the first and the second cycle of milk,
latte_er=1; two states are needed because the machine must count two cycles and a state cannot count by itself; - CAFFE: the cycle with the coffee dispenser,
caffè_er=1.
Step 3: transitions (X means "either value"):
| state | outputs caffè_er, latte_er |
caffè_btn, capp_btn |
next state |
|---|---|---|---|
| IDLE | 0, 0 | 1X | CAFFE |
| IDLE | 0, 0 | 01 | LATTE1 |
| IDLE | 0, 0 | 00 | IDLE |
| LATTE1 | 0, 1 | XX | LATTE2 |
| LATTE2 | 0, 1 | XX | CAFFE |
| CAFFE | 1, 0 | XX | IDLE |
Description to redraw the diagram: four circles; entry arrow (reset) on IDLE; IDLE with a loop labelled caffè_btn=0, capp_btn=0; IDLE CAFFE labelled caffè_btn=1; IDLE LATTE1 labelled caffè_btn=0, capp_btn=1; LATTE1 LATTE2, LATTE2 CAFFE and CAFFE IDLE with no condition (or X): in these states the buttons are ignored, as required. Inside each circle the name of the state and the two outputs, for example LATTE1 / caffè_er=0, latte_er=1.
The text does not say what happens if both buttons are pressed in the same cycle: here the coffee wins (any choice is accepted if it is stated, for example ignoring both).
Step 4: no equivalent states. Two states are equivalent only if they give the same outputs and lead to equivalent states (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 →). IDLE and CAFFE have different outputs from LATTE1 and LATTE2 and from each other, so the only pair to examine is LATTE1 and LATTE2: they have the same output , but the next states are LATTE2 and CAFFE, which differ in the output ( against ). So LATTE1 and LATTE2 are not equivalent: after LATTE1 the coffee comes after two cycles, after LATTE2 after one. The machine has the minimum number of states for a Moore machine.
Step 5: simulation. Cappuccino pressed in cycle 1, then, while the machine is busy, the buttons are pressed again in cycles 2 and 3 (ignored); coffee pressed in cycle 7:
| cycle | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 |
|---|---|---|---|---|---|---|---|---|---|---|---|
| state | IDLE | IDLE | LATTE1 | LATTE2 | CAFFE | IDLE | IDLE | IDLE | CAFFE | IDLE | IDLE |
caffè_btn |
0 | 0 | 1 | 0 | 0 | 0 | 0 | 1 | 0 | 0 | 0 |
capp_btn |
0 | 1 | 0 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
caffè_er |
0 | 0 | 0 | 0 | 1 | 0 | 0 | 0 | 1 | 0 | 0 |
latte_er |
0 | 0 | 1 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
The milk is on for two whole cycles (2 and 3), then the coffee for one cycle (4), and the presses in cycles 2 and 3 have no effect. A coffee pressed in cycle 7 gives the coffee dispenser in cycle 8, one cycle later, because in a Moore machine the output follows the state.
Variant (Mealy). With the outputs on the arrows the same behaviour needs only 3 states: IDLE with caffè_btn=1 / caffè_er=1 as a loop, IDLE L2 with capp_btn=1 / latte_er=1, L2 C with latte_er=1, C IDLE with caffè_er=1. The outputs appear one cycle earlier than in the Moore machine, in the same cycle as the button pulse; the simulation confirmed that it is the Moore output advanced by one cycle. The sheet asks for a diagram without equivalent states, which both solutions satisfy.
Typical mistakes: only one milk state (the milk would last one cycle); the coffee dispenser forgotten after the milk; transitions from the dispensing states that look at the buttons (they must be ignored); outputs on the arrows in a Moore diagram; no entry arrow or no reset; merging LATTE1 and LATTE2 in the state reduction (the outputs are equal, but the next states are not equivalent).
Exercise 3
- Describe in VHDL the finite state machine with inputs and and output , having the following state diagram. In all cases not indicated, the system does not change state and the output is . Separate in the code the memory elements from the purely combinational parts.
- Create a VHDL test bench that makes the machine go through all the states.
Diagram (described in words): four states , , , ; the output is written on the arrows, under the condition, in the form condition over . An entry arrow with the label rst=1 / z=0 points to (reset state). Arrows:
- with
x=1 and y=0 / z=1; - with
x=1 / z=0; - without label;
- with
x=0 and y=1 / z=1; - with
x=0 or y=1 / z=0.
Show the result
Mealy machine (the output is on the arrows). Next state / output , for :
| state | 00 | 01 | 10 | 11 |
|---|---|---|---|---|
VHDL: entity with clk, rst, x, y in and z out, and three processes (state register with reset, next state, output). Test bench sequence , (one pair per cycle after the reset), with in cycles , , only; it visits all four states and all the arrows.
Show the full solution
Step 1: analysis of the diagram. The output is written on the arrows: a Mealy machine, depends on the state and on (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 →). The inputs and have one bit each. Reading the text "in all cases not indicated, the system does not change state and the output is ":
- stay arrows (not drawn): with and (neither condition holds); with ; with and (the only case where
x=0 or y=1is false); - the arrow has no condition: it is taken always, whatever and are; its output is not indicated, hence ;
- only on the two arrows leaving ; every other arrow, loop included, has ;
rst=1 / z=0: with the reset active the machine is in and the output is .
Step 2: structure. The text asks to separate the memory from the combinational parts: three processes, as in the course (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 →):
- state register: sensitive to
clkandrst, asynchronous reset to , otherwisestate <= next_stateon the rising edge (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 →); - next state: purely combinational, sensitive to
state,xandy, with the defaultnext_state <= statefor "does not change state"; - output: purely combinational and, being a Mealy machine, sensitive to
state,x,y(andrst, which forces as in the labelrst=1 / z=0).
Step 3: code of the machine.
library IEEE;
use IEEE.std_logic_1164.all;
entity fsm_xy is
port ( clk, rst : in std_logic;
x, y : in std_logic;
z : out std_logic );
end fsm_xy;
architecture beh of fsm_xy is
type state_type is (S0, S1, S2, S3);
signal state, next_state : state_type;
begin
-- 1) memory: state register with asynchronous reset
state_register : process (clk, rst)
begin
if rst = '1' then
state <= S0;
elsif clk'event and clk = '1' then
state <= next_state;
end if;
end process;
-- 2) next state: combinational
next_state_comb : process (state, x, y)
begin
next_state <= state; -- default: the state does not change
case state is
when S0 =>
if x = '1' and y = '0' then
next_state <= S1;
elsif x = '0' and y = '1' then
next_state <= S3;
end if;
when S1 =>
if x = '1' then
next_state <= S2;
end if;
when S2 =>
next_state <= S0; -- arrow without condition
when S3 =>
if x = '0' or y = '1' then
next_state <= S2;
end if;
end case;
end process;
-- 3) output (Mealy): function of state and inputs
output_comb : process (state, x, y, rst)
begin
z <= '0'; -- default: output 0
if rst = '0' and state = S0 then
if (x = '1' and y = '0') or (x = '0' and y = '1') then
z <= '1';
end if;
end if;
end process;
end beh;Notes on the code:
- the default
next_state <= state;and the defaultz <= '0';express "in all cases not indicated the state does not change and the output is ", and prevent unwanted latches because every signal has a value in every branch; - the condition of can also be written
if not (x = '1' and y = '0') then; the machine leaves unless and ; - the arrow is an assignment without
if; thecasecovers the four values of the enumerated type, sowhen othersis not needed; - the output process needs
xandyin the sensitivity list: without them would not react to a change of the inputs between two clock edges (a typical error that turns a Mealy machine into a Moore one); - the test
rst = '0'in the output process realises the labelrst=1 / z=0; without it the output could be during the reset if , although the state is already .
Step 4: test bench. The test bench has no ports, instantiates the machine, generates the clock and applies the inputs: two processes in parallel (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 sequence must pass through all the states, and it is better if it also uses the stay arrows and both conditions of .
library IEEE;
use IEEE.std_logic_1164.all;
entity test_fsm_xy is
end test_fsm_xy;
architecture test of test_fsm_xy is
signal clock, reset, x, y, z : std_logic;
signal test_x : std_logic_vector(0 to 12) := "0110100101010";
signal test_y : std_logic_vector(0 to 12) := "0101101001110";
constant PERIOD : time := 100 ns;
begin
DUT : entity work.fsm_xy(beh)
port map (clk => clock, rst => reset, x => x, y => y, z => z);
generate_clock : process
begin
clock <= '1'; wait for PERIOD/2;
clock <= '0'; wait for PERIOD/2;
end process;
apply_inputs : process
begin
reset <= '1'; x <= '0'; y <= '0';
wait for 3*PERIOD/2; -- initial reset: known starting state
reset <= '0';
for i in 0 to 12 loop
x <= test_x(i); -- one pair (x, y) per cycle,
y <= test_y(i); -- applied on the falling edge
wait for PERIOD;
end loop;
std.env.stop;
end process;
end test;The clock rises at ns; the reset is active from to ns; the pair of cycle is applied at ns, on the falling edge and far from the rising edge that samples it at ns.
Step 5: expected behaviour (state present in the cycle, during the cycle, state after the next rising edge):
| cycle | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 0 | 1 | 1 | 0 | 1 | 0 | 0 | 1 | 0 | 1 | 0 | 1 | 0 | |
| 0 | 1 | 0 | 1 | 1 | 0 | 1 | 0 | 0 | 1 | 1 | 1 | 0 | |
| present state | |||||||||||||
| 0 | 0 | 1 | 0 | 0 | 0 | 1 | 0 | 0 | 0 | 1 | 0 | 0 | |
| next state |
What each part of the sequence tests: cycles the stay arrows of ; cycle the arrow with ; cycle the stay arrow of (); cycle ; cycles the unconditional arrow ; cycles the arrow with ; cycle the stay arrow of (); cycle through x=0; cycle through y=1 (with ). Being a Mealy output, rises as soon as the inputs of cycles , , are applied (falling edge) and falls when the next ones arrive, not at a clock edge.
The behaviour of the next-state and output processes was checked against the transition table on all 16 combinations of state and inputs with a Python model, and the sequence above on that model; the VHDL was checked by hand against the table, but it was not run in a VHDL simulator.
Typical mistakes:
- writing the output as a function of the state only (that would be a Moore machine and would give wrong values for );
- forgetting
statein the sensitivity list of the next-state process, orx,yin that of the output process; - putting a condition on the arrow , or reading
x=0 or y=1asx=0 and y=1(an with must leave); - writing memory and logic in the same process, against the request of the text;
- a test bench that never reaches (it needs , from ) or that changes the inputs on the rising edge;
- forgetting the initial reset in the test bench: the state would be undefined at the start.
Self-assessment grid
| exercise | points | what must be there for full points | typical mistakes |
|---|---|---|---|
| Quiz 1-20 | not stated on the sheet (negative score for a wrong answer) | the correct answer for each of the 20 questions; for the ambiguous ones (4, 11) the reasoning | confusing setup and hold (15), top-down and bottom-up (2), IR and PC (17), interrupt direction (20); applying a rule to the wrong form (7, 8) |
| Exercise 1 | not stated | truth table with the don't cares for -, map with the three groups of 8 cells, | bit order ( is the least significant), segment 2 mistaken for another, don't cares not used, map not in Gray order |
| Exercise 2 | not stated | symbol with the four inputs and two outputs, diagram with 4 states and outputs inside the states, transitions of IDLE with the buttons, buttons ignored in the other states, no equivalent states | one milk state only, coffee missing after the milk, buttons read while dispensing, outputs on the arrows of a Moore diagram |
| Exercise 3 | not stated | three processes (memory with reset, next state, output) with default values, correct conditions of and , unconditional , a test bench with clock, reset and input sequence through all states | Moore output instead of Mealy, missing sensitivity signals, and and or swapped on , no reset in the test bench |