Digital Systems - Exam of 11 July 2022
Questa pagina non ha ancora la versione ripasso: qui sotto c'è il testo completo.
In questa pagina 24
Exam of the second sitting (11 July 2022) of the equivalent Italian-language course Circuiti Digitali of the Engineering degrees at the University of Padova, translated into English. The paper has two parts: 20 multiple-choice quizzes (three options each, only one correct; wrong answers carry a negative score, the sheet does not give the value) and 3 exercises to be solved on the sheet. The sheet states neither the points of the single exercises nor the duration; calculators, notes, books and colleagues are not allowed, and nobody may leave the room.
Source and checks: the questions are translated faithfully from the original paper. The official solution is not public: every answer below has been derived from the course theory and checked with scripts (truth tables, minimisation compared with a symbolic algebra system, simulation of the two state machines, number conversions). Where a quiz is ambiguous it is said explicitly. The VHDL code of exercise 3 could not be compiled (no VHDL simulator was available): it was checked by hand against the transition table and by a Python model of the three processes.
Quiz 1
Which of the following represents the highest level of abstraction?
- a. logic gates
- b. microarchitecture
- c. register transfer logic (RTL)
Show the result
b.
Show the full solution
The levels of abstraction, from the most abstract to the most concrete, are: algorithm, programming language, operating system, ISA, microarchitecture, register transfer (RTL), logic gates, transistor circuit. Of the three options the microarchitecture comes first, so it is the highest. Typical mistake: choosing RTL because it sounds "more abstract" than gates, forgetting that the microarchitecture describes the whole processor and RTL its register movements. Theory: Digital Systems - Signals, Binary Information and Abstraction LevelsA digital system processes discrete quantities; a binary one encodes them with two voltage ranges (0 and 1), the input range being wider than the output range, which gives noise margins and a regenerative property. Precision depends on the number of bits. A computer is memory, CPU (control unit plus datapath) and I/O. Design proceeds through abstraction levels from algorithm to transistor, following a flow from specification to verification.Digital Systems - Signals, Binary Information and Abstraction Levels →.
Quiz 2
In a system with even parity, which of the following codes signals an error?
- a. 00100010
- b. 11111111
- c. none of the other answers
Show the result
c. (both codes are acceptable)
Show the full solution
With even parity the total number of 1s in the word must be even. 00100010 has two 1s and 11111111 has eight 1s: both counts are even, so no error is signalled. An error would be detected only by an odd count (for instance 00100011). Typical mistake: thinking that "all ones" must be wrong. 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 3
What is the decimal equivalent of the BCD number 00101000?
- a.
- b. 28
- c. it is not a valid BCD number
Show the result
b. ()
Show the full solution
In BCD every group of 4 bits is one decimal digit: and , so the number is . Both groups are valid digits (only to are not). Option a. reads the word as plain binary: . 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 4
The Unicode encoding UTF-8:
- a. always uses a single byte to encode all alphanumeric characters
- b. always uses two bytes to encode all alphanumeric characters
- c. none of the other answers
Show the result
c.
Show the full solution
UTF-8 is a variable-length code: it uses 1 to 4 bytes per code point. The first 128 code points (the ASCII characters, which include the letters without accents and the digits) take one byte, but other alphanumeric characters (accented letters, Greek or Cyrillic letters, and so on) take two or more bytes. So a. ("always one byte for all") and b. ("always two bytes") are both false. Theory: Binary Codes - BCD, ASCII, Unicode, Parity and GrayAn n-bit code distinguishes 2^n elements. BCD encodes each decimal digit on 4 bits (1010 to 1111 unused; it differs from the plain binary of the number). ASCII uses 7 bits for 128 characters; Unicode UTF-8 uses 1 to 4 bytes and is ASCII compatible. A parity bit detects errors on an odd number of bits. Hamming distance is the number of differing bits. Gray code makes consecutive numbers differ by one bit and is built by reflection or with g_i = b_i xor b_(i+1).Binary Codes - BCD, ASCII, Unicode, Parity and Gray →.
Quiz 5
The Hamming distance between the decimal numbers 8 and 4 is:
- a. 1
- b. 2
- c. 3
Show the result
b. ()
Show the full solution
The Hamming distance is the number of bit positions in which two words differ. and differ in the two leftmost bits, so the distance is . 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 other answers
Show the result
a.
Show the full solution
XNOR is 1 when the two inputs are equal, XOR is 1 when they are different. Reading from left to right: because the inputs differ; then . If the operators were grouped from the right the result would be the same: and . In both cases the value is , so a. is right and b. is wrong. Theory: Logic Gates, Gate Delay and Universal GatesAND, OR, NOT implement the Boolean operations; NAND, NOR, XOR and XNOR derive from them. Every function is described by a truth table with 2^n rows. Multi-input XOR is the odd-parity function. An ideal gate has zero delay; a real gate has a propagation delay t_G (different for 0 to 1 and 1 to 0), so the output changes t_G after the input. NAND and NOR are each universal.Logic Gates, Gate Delay and Universal Gates →.
Quiz 7
De Morgan's theorem states that:
- a.
- b.
- c.
Show the result
a.
Show the full solution
The complement of a sum is the product of the complements of all the variables: . Option b. changes the last AND into an OR; option c. forgets to complement . A truth-table check of the three options confirms that only a. is equal to the left-hand side for all 8 input combinations. Theory: Boolean Algebra - Axioms, Theorems and Function ComplementBoolean algebra works on two-valued variables with AND, OR, NOT. Fundamental identities (identity element, idempotence, complement, commutative, associative, both distributive laws) come in dual pairs; De Morgan, absorption, adjacency and consensus are the main theorems, proved by perfect induction or algebraically. The complement of a function is obtained with De Morgan or with the dual plus literal negation. Cost is measured in literals or gate inputs.Boolean Algebra - Axioms, Theorems and Function Complement →.
Quiz 8
Which of the following expressions represents a canonical form of a function of three Boolean variables ?
- a.
- b.
- c.
Show the result
b. ( is the maxterm , i.e. a canonical product of sums with a single factor)
Show the full solution
A canonical form is a sum of minterms (SOP) or a product of maxterms (POS): every term contains all the variables, direct or complemented. Option a. contains the terms and , which do not use all three variables, so it is not canonical. Option c. is a product of product terms; it is not a sum of minterms nor a product of maxterms, and it is also identically (it contains ), so it is not a canonical form of anything. Option b. is a sum containing , and exactly once: it is the maxterm , the canonical POS of the function that is only for . Warning: the question is not very precise, because a "product with a single factor" is a degenerate case; b. is the only sensible answer anyway. Theory: Canonical Forms - Minterms, Maxterms, SOP and POSA minterm is a product containing every variable exactly once and is 1 on a single truth-table row; a maxterm is the dual sum and is 0 on a single row; with n variables there are 2^n of each and the complement of minterm i is maxterm i. Canonical SOP = sum of minterms of rows with F=1; canonical POS = product of maxterms of rows with F=0. They come mechanically from the truth table but are redundant, so they are the starting point for minimization. SOP and POS are two-level circuits.Canonical Forms - Minterms, Maxterms, SOP and POS →.
Quiz 9
With variables, how many minterms are possible?
- a.
- b.
- c. none of the other answers
Show the result
c. (there are )
Show the full solution
A minterm corresponds to one row of the truth table, and a table with inputs has rows. For there are minterms, not and not . The same count holds for the maxterms. 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 maxterm represents:
- a. a row of the truth table
- b. a column of the truth table
- c. none of the other answers
Show the result
a.
Show the full solution
A maxterm is a sum containing every variable once; it is on exactly one row of the truth table (the row it was built from) and on all the others. So it represents a row of the table, namely a row where the function is , never a column. (The dual object, the minterm, corresponds to a row where the function is .) 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 11
The following VHDL code fragment
process(clk, rst)
begin
if (rst = '1') then
a <= '0';
elsif (clk'event and clk = '0') then
a <= b;
end if;
end process;where and are internal signals of type std_logic:
- a. is useful to define a positive edge-triggered flip-flop with synchronous reset
- b. is useful to define a negative edge-triggered flip-flop with asynchronous reset
- c. is useful to define a positive edge-triggered flip-flop with asynchronous reset
Show the result
b.
Show the full solution
Two details decide the answer.
- Reset:
rstis in the sensitivity list and is tested before the clock condition, outside the clock branch. The reset acts as soon asrstbecomes'1', whatever the clock does: it is asynchronous. A synchronous reset would have onlyclkin the list and the test onrstinside the clock branch. - Edge:
clk'event and clk = '0'is true when the clock has just changed and its new value is'0', i.e. on the falling edge: the flip-flop is negative edge-triggered. With'1'it would be positive edge-triggered.
Quiz 12
A structural VHDL description:
- a. always leads to a more optimised synthesis than a behavioral description
- b. uses exclusively Boolean equations
- c. none of the other answers
Show the result
c.
Show the full solution
A structural description lists components (instances) and the wires that connect them. a. is false: the synthesis tool optimises the circuit whatever the style, and nothing guarantees that the structural style gives a better result. b. is false: Boolean equations in concurrent assignments belong to the dataflow style, not to the structural one. 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
Let be the 2's complement of on bits; which of the following properties is true?
- a.
- b.
- c.
Show the result
a.
Show the full solution
By definition the 2's complement of on bits is , so (for , : and ). The in b. comes from the 1's complement , which becomes the 2's complement only after adding 1. Option c. is not an identity. 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 ripple adder, overflow occurs when:
- a. the carry of the full adder of the most significant bit and the one immediately before it are equal
- b. the carry of the full adder of the most significant bit and the one immediately before it are different
- c. none of the other answers
Show the result
b.
Show the full solution
For numbers in 2's complement the overflow is : the carry entering the most significant bit and the carry leaving it must be different. If they are equal the result is representable (a final carry out is simply discarded). Example on 4 bits: has carry into the last bit and carry out , different: overflow ( does not fit). Theory: Binary Adders and SubtractorsHalf adder: S = X xor Y, C = XY. Full adder with carry in Z: S = X xor Y xor Z, C = XY + XZ + YZ = G + PZ with P = X xor Y, G = XY; two half adders and an OR. The n-bit ripple carry adder chains n full adders, so delay grows linearly with n. Adder-subtractor: XOR of each B bit with a control S, which is also the carry in, computes A+B or A+not B+1 = A-B. The 2-bit multiplier uses 4 ANDs and 2 half adders.Binary Adders and Subtractors →, Signed Numbers, Complement Arithmetic and OverflowUnsigned subtraction is correct without borrow out; otherwise the result M-N+2^n is wrong. One's complement is 2^n-1-N (bitwise inversion); two's complement is 2^n-N (one's complement plus 1). Signed numbers: sign-magnitude (two zeros, symmetric range) or two's complement (one zero, range -2^(n-1) to 2^(n-1)-1, MSB weight -2^(n-1)). In two's complement addition and subtraction are the same adder: A-B = A + not B + 1, carry out discarded. Overflow: unsigned if carry out is 1 in an addition; signed if the carry into the sign bit differs from the carry out of it.Signed Numbers, Complement Arithmetic and Overflow →.
Quiz 15
The setup time of a flip-flop:
- a. depends only on the flip-flop
- b. depends on the logic downstream of the flip-flop
- c. depends on the logic upstream of the flip-flop
Show the result
a.
Show the full solution
The setup time is the minimum time the data input must be stable before the active clock edge: it is a parameter of the flip-flop itself (its internal master latch), given in the data sheet. The logic before or after the flip-flop does not change ; it only determines how much time is left (the slack) in the constraint . Typical mistake: confusing the parameter with the constraint it appears in. Theory: Timing of Sequential Systems - Setup, Hold and Maximum Clock FrequencyA flip-flop stores the right value only if its input is stable for the setup time before and the hold time after the clock edge, and its output changes after the propagation delay. In a synchronous circuit the clock period must satisfy T >= t_pd,FF + t_COMB + t_s,FF + t_slack, which fixes the maximum frequency; slowing the clock cures setup violations but not hold violations, which require t_pd,FF,min + t_COMB,min >= t_h. Clock skew modifies both constraints.Timing of Sequential Systems - Setup, Hold and Maximum Clock Frequency →.
Quiz 16
In an RS latch made with NOR gates, the combination , brings the output to:
- a. '0'
- b. an intermediate value between '0' and '1'
- c. '1'
Show the result
a. ('0')
Show the full solution
In the NOR latch and . With each NOR has a on one input, so both outputs are : . A logic value is produced (never an intermediate level), but it violates the requirement that be the complement of : this is the forbidden input combination, and the behaviour after going back to is unpredictable. Theory: Sequential Systems - State, Latches and Flip-FlopsA sequential circuit has outputs that depend on the inputs and on the state held in memory elements; it is a combinational network with flip-flops in a feedback loop, where present state is the flip-flop outputs and next state is their inputs. Synchronous circuits update only on the clock edge. The SR latch (NOR) sets, resets, holds, and forbids S=R=1; the D latch is transparent while C=1; the edge-triggered D flip-flop is two D latches in cascade (master-slave) and samples D only on the active clock edge, with Q(t+1)=D(t).Sequential Systems - State, Latches and Flip-Flops →.
Quiz 17
The program counter PC:
- a. at every clock cycle is always updated with PC+1
- b. none of the other answers
- c. at every clock cycle is updated with the opcode of the next instruction
Show the result
b.
Show the full solution
The PC holds the address of the next instruction. It is incremented () in the normal flow, but it is loaded in parallel with a new address when there is a jump or a taken branch, and it can also stay unchanged (for instance while a multi-cycle instruction is executing). So a. is false because of "always". c. is false because the PC contains an address, not an opcode. 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
In an interrupt priority management system based on a daisy chain:
- a. none of the other answers
- b. the CPU determines the peripheral with the highest priority
- c. two interrupts can be served in parallel if they are on opposite sides of the chain
Show the result
a.
Show the full solution
In a daisy chain the priority is given by the position of the devices in the chain: the grant signal travels along the chain and the first requesting device (the closest to the CPU) takes it. The priority is therefore fixed by the wiring and not decided by the CPU, so b. is false. Interrupts are handled one at a time: no parallel service, wherever the devices are, so c. is false. Parallel handling belongs to the parallel priority scheme with a priority encoder. Theory: Programmed I-O and InterruptsIn programmed I/O the CPU polls the device in a busy-wait loop and wastes most cycles; with interrupts the interface raises a signal when data are ready, the CPU suspends its work, runs a service routine and returns. Interrupts can be vectored (the device supplies the address of its routine) or non-vectored; with several devices a priority scheme is needed, by software polling, by hardware daisy chain (priority = position in the chain, no parallel handling) or by parallel priority with a priority encoder and a mask register.Programmed I-O and Interrupts →.
Quiz 19
In the absence of conditional branches, a 4-stage pipeline:
- a. always executes 4 instructions per clock cycle
- b. executes at most 4 instructions per clock cycle
- c. executes at least 4 instructions per clock cycle
Show the result
b.
Show the full solution
With 4 stages at most 4 instructions are in the pipeline at the same time, one per stage, and in steady state one instruction is completed per cycle. "Always" and "at least" are false: at the start (the pipeline fills) and in the presence of data hazards (stalls, bubbles) not all the stages are busy, and removing the conditional branches only removes the control hazards. Only "at most 4" is always true. Note: strictly speaking the instructions completed per cycle are at most one; the wording means instructions in execution, and b. is the only sustainable option anyway. Theory: Pipelining and HazardsA pipeline splits execution into stages separated by registers (IF, DOF, EX, WB) working in parallel on different instructions; latency stays the same while throughput grows by less than the number of stages (flip-flop delays, slowest stage). With k stages and N instructions k+N-1 cycles are needed. Hazards stall the pipeline: data hazards (operand not yet written; fixes are NOPs, stalls and forwarding) and control hazards (branches; fixes are NOPs or branch prediction with bubbles).Pipelining and Hazards →.
Quiz 20
In how many distinct locations of a 2-way set-associative cache with 16-bit words can a datum coming from the main memory be stored?
- a.
- b.
- c.
Show the result
b. ()
Show the full solution
In a -way cache the address fixes the set, and inside the set the datum can go in any of the ways: here , so exactly 2 locations (a word is a single location per way, so ). The word width (16 bit) is irrelevant for counting locations, which excludes c.; has no meaning here. For comparison: a direct-mapped cache gives 1 location, a fully associative one gives all the lines of the cache. Theory: Memory Hierarchy and Cache MemoryMemories form a hierarchy (small fast SRAM, larger slower DRAM, huge slow disks) which works because programs reuse data close in time and in space (locality). A cache hit or miss gives an average access time t_hit plus miss rate times miss penalty; placement can be direct mapped (index = low address bits, tag = high bits), fully associative (tag = whole address, compared in parallel by an associative memory) or k-way set associative (a block can sit in k locations of one set).Memory Hierarchy and Cache Memory →.
Exercise 1 (points not stated)
Synthesise the logic function , where and are two unsigned positive integers on two bits, with and the most significant bits, using Karnaugh maps. Report the truth table of the function, the Karnaugh map with the groupings used to simplify the function, and the final equation obtained.
Show the result
The function is for six of the 16 input combinations: . Minimal sum of products, three groups: (minimal product of sums, five factors: ).
Show the full solution
Step 1: truth table. The function has 4 inputs, so the table has rows. when the number is greater than (see Digital Systems - Signals, Binary Information and Abstraction LevelsA digital system processes discrete quantities; a binary one encodes them with two voltage ranges (0 and 1), the input range being wider than the output range, which gives noise margins and a regenerative property. Precision depends on the number of bits. A computer is memory, CPU (control unit plus datapath) and I/O. Design proceeds through abstraction levels from algorithm to transistor, following a flow from specification to verification.Digital Systems - Signals, Binary Information and Abstraction Levels → and Number Systems and Base ConversionsA number in base r is the sum of a_i r^i with digits from 0 to r-1. Conversions: base r to decimal by weighted sum; decimal to base r by successive divisions (integer part, remainders read bottom-up) and successive multiplications (fractional part, integer parts read top-down); binary to octal or hexadecimal by groups of 3 or 4 bits starting from the radix point. Binary sum, difference and product follow the decimal rules with borrows and shifted partial products.Number Systems and Base Conversions → for the weights of the bits).
| 00 | 00 | 0 | 0 | 0 |
| 00 | 01 | 0 | 1 | 0 |
| 00 | 10 | 0 | 2 | 0 |
| 00 | 11 | 0 | 3 | 0 |
| 01 | 00 | 1 | 0 | 1 |
| 01 | 01 | 1 | 1 | 0 |
| 01 | 10 | 1 | 2 | 0 |
| 01 | 11 | 1 | 3 | 0 |
| 10 | 00 | 2 | 0 | 1 |
| 10 | 01 | 2 | 1 | 1 |
| 10 | 10 | 2 | 2 | 0 |
| 10 | 11 | 2 | 3 | 0 |
| 11 | 00 | 3 | 0 | 1 |
| 11 | 01 | 3 | 1 | 1 |
| 11 | 10 | 3 | 2 | 1 |
| 11 | 11 | 3 | 3 | 0 |
There are no don't-care conditions: all 16 combinations are valid inputs. The six 1s are the minterms (index ).
Step 2: Karnaugh map. Rows and columns , both in Gray order , so that neighbouring cells (also those on opposite edges) differ in one variable (Karnaugh Maps and Two-Level MinimizationA Karnaugh map is the truth table arranged in a grid with rows and columns in Gray code, so that adjacent cells (also across opposite edges) differ in one variable. Groups of 2^k ones eliminate k variables and give a product. A prime implicant is a maximal group, an essential one is the only cover of some minterm; the minimum cover has all essentials plus few other primes. For POS, group the zeros. Don't cares may be used as 1 or 0. XOR functions have a checkerboard map and do not simplify.Karnaugh Maps and Two-Level Minimization →):
| 00 | 01 | 11 | 10 | |
|---|---|---|---|---|
| 00 | 0 | 0 | 0 | 0 |
| 01 | 1 | 0 | 0 | 0 |
| 11 | 1 | 1 | 0 | 1 |
| 10 | 1 | 1 | 0 | 0 |
Step 3: groups. Three groups cover all the 1s, each as large as possible:
- Group A, 4 cells: rows and (i.e. ) and columns and (i.e. ). The variables that stay constant are and : product . It means "the high bit of is 1 and the high bit of is 0, so ".
- Group B, 2 cells: row and the columns and . The two columns are adjacent across the edge of the map (they differ only in ). Constant: , , : product .
- Group C, 2 cells: column and the rows and (adjacent, they differ in ). Constant: , , : product .
All the three groups are essential: the cells and belong only to A, the cell only to B, the cell only to C. The cell is in all three groups and is covered more than once, which is allowed. No group covers a 0.
Step 4: equation. Meaning: wins either with the high bit, or, when the high bits are equal, with the low bit. The second form (with the XNOR) is equivalent (checked by the script) and is the usual comparator equation, but it needs an XNOR gate; the minimal two-level form is the one above.
Product of sums (optional). Grouping the 0s of the map (the complement is , then apply De Morgan) gives : it has more factors than the SOP has terms, so the SOP is the better two-level form here (Karnaugh Maps and Two-Level MinimizationA Karnaugh map is the truth table arranged in a grid with rows and columns in Gray code, so that adjacent cells (also across opposite edges) differ in one variable. Groups of 2^k ones eliminate k variables and give a product. A prime implicant is a maximal group, an essential one is the only cover of some minterm; the minimum cover has all essentials plus few other primes. For POS, group the zeros. Don't cares may be used as 1 or 0. XOR functions have a checkerboard map and do not simplify.Karnaugh Maps and Two-Level Minimization →).
Checks. A script compared the equation with the truth table on all 16 rows and with the minimal form computed by a symbolic algebra system (identical); it also verified that every group contains only 1s and that each of the three is essential.
Typical mistakes: writing the columns in binary order instead of Gray order (the groups no longer correspond to adjacent cells); forgetting the group that wraps around the edge (group B); using (then also the equal cases would be 1); swapping the roles of and in the table.
Exercise 2 (points not stated)
Draw the state diagram, without equivalent states, complete with all the transitions and all the signals, for an automatic gate. Show clearly the input and output signals in the diagram, using the names given in the text.
The system has the following inputs:
btnof one bit, on which a pulse lasting one clock cycle is generated every time the button of the gate remote control is pressed. For simplicity the remote control only allows to open the gate when it is completely closed;btnis ignored if the gate is already open or moving.finecorsa(limit switch) of two bits, which is '11' when the gate is completely open, '00' when it is completely closed, '10' when it is moving
and must drive the following output:
motore(motor) of two bits, which controls the gate motor with the following scheme: '01' = open, '10' = close, '00' = stop motor.
The controller must open the gate when a pulse is detected on the line btn and close it again after 2 clock cycles have passed from the complete opening (i.e. from when the gate is stopped). The motor must be stopped when the gate must not move.
Show the result
Moore machine with 5 states (no two of them equivalent), initial state CLOSED:
| state | motore |
next state |
|---|---|---|
| CLOSED | 00 | OPENING if btn=1, otherwise CLOSED |
| OPENING | 01 | OPEN1 if finecorsa=11, otherwise OPENING |
| OPEN1 | 00 | OPEN2 (always) |
| OPEN2 | 00 | CLOSING (always) |
| CLOSING | 10 | CLOSED if finecorsa=00, otherwise CLOSING |
Show the full solution
Step 1: type of machine and signals. Inputs: btn (1 bit) and finecorsa (2 bits); output: motore (2 bits). The output depends only on what the gate is doing (opening, closing, stopped), so a Moore machine is the natural choice: the output is written inside each state (Finite State Machines - AnalysisAnalysing a synchronous sequential circuit means deriving from the circuit the flip-flop input equations (next state) and output equations, the state table (2^(m+n) rows for m flip-flops and n inputs), the state diagram (circles are states, arrows carry input/output) and a timing simulation. Mealy: output depends on state and input (written on the arrows, may change between clock edges); Moore: output depends only on the state (written in the circle, changes only at the clock edge). Two states are equivalent if they give the same outputs and lead to equivalent states, and can be merged to save flip-flops.Finite State Machines - Analysis →, Finite State Machines - SynthesisSynthesis of a synchronous sequential circuit follows specifications, state diagram, state table (merging equivalent states), binary state encoding, choice of D flip-flop, flip-flop input and output equations, minimisation, circuit and verification. A state summarises the useful part of history; a sequence recogniser has one state per recognised prefix, reusing states for overlaps. A reset gives a known initial state. Gray encoding (minimum flip-flops) versus one-hot (one flip-flop per state, simpler logic): for the 1101 recogniser Gray costs about half.Finite State Machines - Synthesis →).
Step 2: states. We need to remember what the controller is doing, since btn and finecorsa alone do not say it (for example finecorsa=10 means "moving" but not whether the gate is opening or closing):
- CLOSED, motor stopped (
motore=00), waiting for the button; - OPENING,
motore=01, untilfinecorsa=11; - OPEN1 and OPEN2, motor stopped (
motore=00): they count the 2 clock cycles of waiting. Two cycles need two states in a row, because a Moore machine can only count by moving through states; - CLOSING,
motore=10, untilfinecorsa=00.
Step 3: no equivalent states. Two states are equivalent if they have the same output and, for every input, equivalent next states. Here the three states with motore=00 are different: CLOSED can stay in itself for ever (if btn=0); OPEN1 always goes to OPEN2 (output 00) and only after that to CLOSING; OPEN2 goes to CLOSING (output 10) at the next cycle whatever the input. So after one clock cycle the output sequences differ, and no state can be removed. A script ran the standard partition-refinement procedure on the table and obtained 5 classes for 5 states.
Step 4: transitions.
- CLOSED:
btn=1 gives OPENING;btn=0 stays.finecorsais not looked at (it is '00' in this state). - OPENING: the gate is moving,
finecorsagoes from '00' to '10' and finally to '11'. Whenfinecorsa=11 (completely open) go to OPEN1; otherwise stay.btnis ignored (as the text says). - OPEN1: next state OPEN2, whatever the inputs;
btnis ignored. - OPEN2: next state CLOSING, whatever the inputs.
- CLOSING: when
finecorsa=00 go to CLOSED; otherwise stay. Just after the start of the closingfinecorsais still '11' or '10': the test is on '00' only, so the machine stays in CLOSING in both cases.btnis ignored.
Description to redraw the diagram: five circles, each with the name of the state and, below, the value of motore; an incoming arrow marks CLOSED as the initial state. Arrows: CLOSED to OPENING labelled btn=1; a loop on CLOSED labelled btn=0; OPENING to OPEN1 labelled finecorsa=11; a loop on OPENING labelled finecorsa11; OPEN1 to OPEN2 and OPEN2 to CLOSING without label (always); CLOSING to CLOSED labelled finecorsa=00; a loop on CLOSING labelled finecorsa00.
Step 5: simulation. A script coupled the machine with a model of the gate (4 steps of travel, finecorsa computed from the position) and pressed btn at the cycles 2, 5 and 9. The first pulse opens the gate; the pulses at 5 (gate moving) and 9 (gate open, waiting) are ignored:
| cycle | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11-13 | 14 | 15 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| state | CLOSED | OPENING | OPENING | OPENING | OPENING | OPENING | OPEN1 | OPEN2 | CLOSING | CLOSING | CLOSING | CLOSED |
btn |
1 | 0 | 0 | 1 | 0 | 0 | 0 | 1 | 0 | 0 | 0 | 0 |
finecorsa |
00 | 00 | 10 | 10 | 10 | 11 | 11 | 11 | 11 | 10 | 00 | 00 |
motore |
00 | 01 | 01 | 01 | 01 | 01 | 00 | 00 | 10 | 10 | 10 | 00 |
The gate is detected open at cycle 7; the motor is stopped in the two cycles 8 and 9, and the closing starts at cycle 10. In the last cycle of the closing (cycle 14) the motor is still driven, for one cycle after finecorsa has become 00: this is the natural delay of a Moore machine, which reacts to the limit switch one clock cycle later.
Note on the reading of the text. "2 cycles after the complete opening" has been read as two clock cycles with the motor stopped (OPEN1 and OPEN2) after the cycle in which finecorsa=11 is detected. If the first of the two cycles is counted as the cycle of detection itself, one waiting state is enough (4 states in total); the text does not allow to exclude this reading, so the choice should be stated clearly in the answer.
Typical mistakes: a single OPEN state with no way to count two cycles; no distinction between OPENING and CLOSING (the same finecorsa=10 would be ambiguous); btn considered in the states where it must be ignored; outputs written on the arrows of a Moore diagram (they go inside the states); no initial state; using names different from btn, finecorsa, motore, which the text imposes.
Exercise 3 (points not stated)
Describe in VHDL the finite state machine with inputs and and output , having the following state diagram. In all the cases not indicated, the system does not change state. Separate in the code the memory elements from the purely combinational parts.
State diagram (described in words; the original is a drawing): four circles, each with the value of the two-bit output inside: (), (), (), (). An arrow coming from outside and labelled points to . Arrows:
- labelled and ;
- labelled ;
- with no label;
- labelled and ;
- labelled or .
Show the result
Moore machine. Next state for :
| state | 00 | 01 | 10 | 11 | |
|---|---|---|---|---|---|
| 00 | |||||
| 01 | |||||
| 10 | |||||
| 11 |
Code: three processes (state register with asynchronous reset, next state, output). The code is in the solution (not compiled, checked by hand and with a Python model).
Show the full solution
Step 1: reading the diagram. The output is written inside the states: Moore machine. The inputs and are single bits. The sentence "in all the cases not indicated, the system does not change state" gives the loops:
- leaves only for (to ) and (to ); for and it stays;
- leaves when (any , so and ); it stays when ;
- leaves when or , i.e. for ; it stays only for ;
- has an arrow with no label: it goes to always, whatever and .
Step 2: structure. The text asks to separate memory and combinational logic: the standard three-process model (VHDL - Finite State Machines and Sequential TestbenchesA finite state machine is described in behavioral VHDL with an enumerated type for the states and three processes: the state register (reset and state <= next_state on the clock edge), the next state as a combinational function of state and input (case state, with default next_state <= state), and the output as a combinational function of the state alone (Moore) or of state and input (Mealy). The testbench has a clock process and an input process (initial reset, then a test sequence that visits all states).VHDL - Finite State Machines and Sequential Testbenches →):
- state register, sensitive to
clkandrst: asynchronous reset to (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 →), otherwisestate <= next_stateon the rising edge; - next state: purely combinational, sensitive to
state,xandy; - output: purely combinational, sensitive to
statealone (Moore).
Step 3: code.
library IEEE;
use IEEE.std_logic_1164.all;
entity fsm_xy is
port ( clk, rst : in std_logic;
x, y : in std_logic;
w : out std_logic_vector(1 downto 0) );
end fsm_xy;
architecture beh of fsm_xy is
type state_type is (S0, SA, S2, SB);
signal state, next_state : state_type;
begin
-- 1) memory: state register with asynchronous reset
state_register : process (clk, rst)
begin
if rst = '1' then
state <= S0;
elsif clk'event and clk = '1' then
state <= next_state;
end if;
end process;
-- 2) next state: combinational
next_state_comb : process (state, x, y)
begin
next_state <= state; -- default: no change of state
case state is
when S0 =>
if x = '1' and y = '0' then
next_state <= SA;
elsif x = '0' and y = '1' then
next_state <= SB;
end if;
when SA =>
if x = '1' then
next_state <= S2;
end if;
when SB =>
if x = '0' or y = '1' then
next_state <= S2;
end if;
when S2 =>
next_state <= S0; -- arrow without label
end case;
end process;
-- 3) output (Moore): depends only on the state
output_comb : process (state)
begin
case state is
when S0 => w <= "00";
when SA => w <= "01";
when S2 => w <= "11";
when SB => w <= "10";
end case;
end process;
end beh;Notes on the code:
- the default
next_state <= state;at the start of the process implements "in all the cases not indicated, the system does not change state" and guarantees thatnext_statehas a value in every branch, so no unwanted latch is created (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 →); without it, the branches of , and would leavenext_stateunassigned for some inputs; - the conditions are written exactly as in the diagram:
x = '1' and y = '0'(withandas in the figure) andx = '0' or y = '1'; statemust be in the sensitivity list of the second process (the machine has to react to a change of state), together withxandy;- the
caseon the enumerated type covers all four states, sowhen othersis not needed; theifwithoutelseinside thecaseis correct thanks to the default; - the output process lists only
state: with a Mealy machinexandywould have to be added.
Step 4: checks. Not compiled (no VHDL simulator available): the syntax was checked by hand with the model of the course (VHDL - Entity, Architecture, Types and Description LevelsVHDL is a hardware description language, not a programming language: its statements are concurrent and describe blocks of circuit, used to document, simulate and synthesise. A block has an entity (name and in/out ports) and at least one architecture (what is inside) written in structural style with components and port map, dataflow style with Boolean equations, or behavioral style. Types include std_logic with values 0, 1, X, Z, U and -, std_logic_vector, bit, boolean and integer; signal is used for internal connections and constant for fixed values.VHDL - Entity, Architecture, Types and Description Levels →) and the behaviour with a Python model that reproduces the two combinational processes line by line. The model gives the table of the Result and, after the reset, the following runs (the first starts with and visits the five forward transitions; the second the loops of and ):
| cycle | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 |
|---|---|---|---|---|---|---|---|---|---|---|
| 10 | 11 | 00 | 01 | 11 | 00 | 01 | 10 | 00 | 11 | |
| present state | ||||||||||
| 00 | 01 | 11 | 00 | 10 | 11 | 00 | 10 | 10 | 11 | |
| next state |
| cycle | 0 | 1 | 2 | 3 | 4 | 5 | 6 |
|---|---|---|---|---|---|---|---|
| 00 | 11 | 10 | 01 | 00 | 10 | 01 | |
| present state | |||||||
| 00 | 00 | 00 | 01 | 01 | 01 | 11 | |
| next state |
In the first run the cycle 7 ( in ) shows that stays when and ; at cycle 8 (, so ) it leaves. The condition " or " is false only for , which is the only input that keeps in place.
Typical mistakes:
- scrambled conditions:
andandorexchanged in (the exit condition is "at least one of the two": it stays only for ); - a condition on the arrows , or an exit from at every input: the diagram has on and nothing on ;
- memory and combinational logic in the same process (against the request of the text);
statemissing from the sensitivity list of the next-state process: the simulation does not react to the change of state;- no default for
next_state: latches appear in the synthesis; rstmissing from the list of the register process, or the reset to a state different from .
Self-assessment grid
| exercise | points | what must be there for full marks | typical mistakes |
|---|---|---|---|
| Quiz 1-20 | not stated, negative score for wrong answers | correct choice for all 20 questions (b, c, b, c, b, a, a, b, c, a, b, c, a, b, a, a, b, a, b, b); for the loose ones (8, 19) the reasoning matters | De Morgan applied to one variable only (7); parity read backwards (2); UTF-8 taken as fixed length (4); setup time attributed to the logic (15); clock edge and reset type confused (11); daisy chain priority given to the CPU (18) |
| Exercise 1 | not stated | table with 16 rows and 6 ones; map with Gray order; three essential groups (4, 2 and 2 cells, one across the edge); | columns in binary order; wrap-around group missed; instead of |
| Exercise 2 | not stated | Moore diagram with 5 states and initial state; outputs inside the states; two waiting states in a row; btn ignored while moving or open; names btn, finecorsa, motore |
one waiting state only; opening and closing not distinguished; outputs on the arrows; missing initial state |
| Exercise 3 | not stated | three processes (register with reset, next state with default, Moore output); correct conditions ( / / / or ); unlabelled arrow | memory and logic mixed; and/or swapped; state missing from the sensitivity list; no default for the next state |