Digital electronics
A digital circuit works with two voltage levels, 0 and 1. With them we represent numbers (in binary, signed and floating point), compute logic functions with gates and, adding memory (flip-flops), build counters and state machines. This topic follows that path with the four Digital electronics tools.
Number systems
In a positional system of base each digit is worth its value times a power of the base. Binary (base 2) uses 0 and 1; octal (8) and hexadecimal (16, digits 0–9 and A–F) are shorthands for binary, because 8 = 2³ and 16 = 2⁴:
| Conversion | Method |
|---|---|
| Base → decimal | Sum of digit × (as above). |
| Decimal → binary, integer part | Divide by 2 over and over; the remainders, read from bottom to top, are the bits. |
| Decimal → binary, fractional part | Multiply by 2 over and over; the integer part of each product, read from top to bottom, is the bit. |
| Binary ↔ octal / hexadecimal | Group by 3 or 4 bits from the radix point toward both sides; each group is one digit. |
Other codes: BCD writes each decimal digit with 4 bits (45 → 0100 0101) and Gray code orders numbers so that two consecutive ones differ in a single bit (); it is used in position encoders and in Karnaugh maps.
Signed integers and overflow
With bits there are patterns. Unsigned, they represent 0 to . For negatives almost every processor uses two's complement: the most significant bit is worth instead of , so the range is to (with 8 bits, −128 to 127).
To change the sign, invert every bit and add 1. The advantage is that addition is the same for signed and unsigned numbers, and the subtraction is : a single adder does everything. What changes is how the result is read and when it is wrong:
- Unsigned: the result does not fit if a carry comes out of the last bit (flag C = 1).
- Signed: there is overflow (V = 1) when two numbers of the same sign give a result of the opposite sign; it is equivalent to the carry into the sign bit differing from the carry out of it.
- Adding two numbers of different sign never overflows.
IEEE 754 floating point
Real numbers are stored in binary scientific notation. In single precision (32 bits) there is 1 sign bit , 8 exponent bits stored with a bias of 127 and 23 mantissa bits ; the 1 before the point is not stored (hidden bit):
is reserved for zero and denormal numbers (no hidden bit), and for infinity (mantissa 0) and NaN. With 24 effective bits, the precision is about 7 decimal digits; a value that does not fit is rounded to the nearest one.
Boolean algebra and gates
A logic variable is 0 or 1. The three basic operations are AND (product, : it is 1 only if both are 1), OR (sum, : it is 1 if either is 1) and NOT (complement, ). Each one is a gate; NAND and NOR are negated AND and OR, and XOR is 1 when the inputs differ.
| Law | Form with + | Form with · |
|---|---|---|
| Identity and null | ||
| Complement | ||
| Idempotence | ||
| Absorption | ||
| Distributive | ||
| De Morgan |
De Morgan explains why NAND alone (or NOR alone) is enough for any circuit: an AND–OR sum of products becomes NAND–NAND by negating each product twice.
Canonical forms and Karnaugh maps
Every function can be written from its truth table. Each row with output 1 is a minterm, a product with every variable (the one that is 0 goes negated); the sum of the minterms is the canonical SOP form, . The rows with output 0 give maxterms (sums) and the POS form, . They are correct but long: they need simplifying.
The Karnaugh map draws the truth table so that neighboring cells differ in a single bit: rows and columns go in Gray code (00, 01, 11, 10) and opposite edges are neighbors too. Two neighboring cells with a 1 merge because : the variable that changes disappears.
- Groups are rectangles of 1, 2, 4, 8… cells (powers of 2), and they may wrap around the edges.
- Each group of cells removes variables: the ones that do not change within the group remain.
- Look for the largest possible groups and the fewest groups that cover every 1; a 1 may be in several groups.
- «Don't care» cells (X, combinations that never happen) are used as 1 only if they enlarge a group; they do not need to be covered.
- Grouping the 0s instead of the 1s gives the minimal POS form.
With more than 4 or 5 variables the map stops being practical and the Quine–McCluskey method is used, which does the same with tables: it combines minterms that differ in one bit until it gets the prime implicants (groups that cannot grow); the essential ones (the only ones covering some 1) go in for sure, and if some 1s remain uncovered, Petrick's method picks the cheapest combination of the rest.
Combinational circuits
In a combinational circuit the output depends only on the inputs at that instant. The usual building blocks:
| Block | What it does | Equations |
|---|---|---|
| Half adder | Adds two bits. | |
| Full adder | Adds two bits and the incoming carry. | |
| 4:1 multiplexer | Passes to the output the input chosen by . | |
| 2:4 decoder | Activates a single output, the one of the input number. |
Chaining full adders, each passing its carry to the next, adds -bit numbers (a ripple-carry adder). It is simple but slow: the last bit waits for the carry to travel the whole chain.
Sequential circuits and flip-flops
A sequential circuit has memory: its output also depends on what happened before. The simplest memory element is the SR latch, two cross-coupled NOR gates that hold one bit. A flip-flop changes only on the rising edge of the clock (CLK), so the whole circuit advances at the same time, one step per cycle:
| Flip-flop | Characteristic equation | Excitation: 0→0, 0→1, 1→0, 1→1 |
|---|---|---|
| D | D = 0, 1, 0, 1 | |
| T | T = 0, 1, 1, 0 | |
| JK | JK = 0X, 1X, X1, X0 | |
| SR | (SR = 0) | SR = 0X, 10, 01, X0 |
The excitation table answers the design question: for the state to go from to , what must the inputs be? The X entries are freedoms the Karnaugh map takes advantage of.
State machines
A finite state machine describes a sequential circuit as a set of states and the transitions between them. In a Moore machine the output depends only on the state (written inside the circle); in a Mealy machine, on the state and the input (written on the arrow as input/output), and it usually needs fewer states. The design always follows the same steps:
- State diagram from the problem statement: what the circuit has to remember.
- State table: next state and output for each state and each input.
- Code assignment: with states, flip-flops are needed; unused codes are «don't care».
- Transition and excitation table with the chosen flip-flop.
- One Karnaugh map per flip-flop input and per output, and the circuit.
Common mistakes
- Reading the remainders of division by 2 from top to bottom: the first one is the least significant bit.
- Grouping by 4 bits from the left when converting to hexadecimal: group from the radix point.
- Confusing the carry out (C) with signed overflow (V): 100 + 50 with 8 bits has C = 0 and V = 1.
- Ordering the Karnaugh map in binary (00, 01, 10, 11) instead of Gray: the groups stop being valid.
- Forgetting that the map edges are neighbors, or making groups of 3 or 6 cells.
- Treating the X as required 1s and covering them even when they do not help.
- Writing the output of a Mealy machine inside the state, or that of a Moore machine on the arrow.
Worked examples
Example 1From decimal to binary, octal and hexadecimal
Solution
- Integer part, divisions by 2: 45 → 22 remainder 1, 22 → 11 remainder 0, 11 → 5 remainder 1, 5 → 2 remainder 1, 2 → 1 remainder 0, 1 → 0 remainder 1. From bottom to top: .
- Fractional part, multiplications by 2: 0.625 × 2 = 1.25 → 1; 0.25 × 2 = 0.5 → 0; 0.5 × 2 = 1.0 → 1, and the fraction ends (exact). From top to bottom: .
- Octal, groups of 3 from the point: 101 101 . 101 → 55.5. Hexadecimal, groups of 4: 0010 1101 . 1010 → 2D.A.
- Check: .
Solve it in Simuveliq
- In Engineering → Number systems, in Base conversion, type 45.625 with base 10.
- The Result in every base card gives 10 1101.101, 55.5 and 2D.A, and Step by step shows the division table, the multiplication table and the groups of 3 and 4 bits.
Example 2Two's complement and overflow
Solution
- (a) +45 = 0010 1101. Invert the bits: 1101 0010, and add 1: 1101 0011. Check: unsigned, that pattern is 211 = 2⁸ − 45.
- (b) 0110 0100 (100) + 0011 0010 (50) = 1001 0110. The carry into the sign bit is 1 and the carry out is 0: C = 0 and V = 0 ⊕ 1 = 1.
- Unsigned, 1001 0110 = 150: correct (C = 0, it fits in 0…255). Signed, the sign bit is 1 and the pattern is 150 − 256 = −106: two positives gave a negative, overflow, because 150 does not fit in −128…127.
Solve it in Simuveliq
- In Number systems, type −45 (base 10, n = 8 bits): the representations table gives two's complement = 1101 0011, next to sign-magnitude (1010 1101), one's complement (1101 0010) and excess-128 (0101 0011), and the step by step does the inversion and the +1.
- In Binary arithmetic (n bits), A = 100, B = 50 and A + B: the card shows the carry row, the flags C = 0 · V = 1 · N = 1 · Z = 0 and both readings, −106 «overflow (V = 1)» and 150 «fits».
Example 3A number in IEEE 754
Solution
- Sign: negative, .
- (6 = 110 and 0.75 = 0.11). Normalized: .
- Stored exponent: .
- Mantissa: the bits after the hidden 1, 1011, padded with zeros up to 23 bits.
- Pattern: 1 | 1000 0001 | 1011 000… → 1100 0000 1101 1000 0000… = 0xC0D80000. Since 6.75 is exact in binary, the stored value is exact (error 0).
Solve it in Simuveliq
- In Number systems, in the IEEE 754 · 32 bits panel, type −6.75. The card paints the 32 bits by field, gives «hex 0xC0D80000» and the five steps (sign, binary, normalize, exponent 2 + 127 = 129, mantissa).
- Try 0.1: the stored value is no longer exact and the card shows the error.
Example 4Majority voter
Solution
- Truth table: F = 1 on the rows with two or three ones, 011, 101, 110 and 111, that is, .
- In the map, m7 is a neighbor of m3, m5 and m6. Three pairs that share m7 are formed: m3–m7 (A changes: remains), m5–m7 (B changes: ) and m6–m7 (C changes: ). All three are essential: each is the only one covering its other 1.
- . Grouping the zeros (m0, m1, m2, m4, which form three pairs with m0) gives the POS , of the same cost.
Solve it in Simuveliq
- In Engineering → Karnaugh maps, in Examples, «Load» → Majority voter (3 variables).
- The map colors the three groups; Expressions gives the minimal SOP and POS, the NAND-only and NOR-only versions and the cost, and Quine–McCluskey step by step reaches the same three essential prime implicants. «Build the circuit» → AND–OR builds it in the simulator.
Example 5Simplifying with don't cares
Solution
- The 1s m3, m7, m15 and m11 fill the column CD = 11: a group of 4, A and B change, remains.
- m1 is still missing. Alone, it would be . Taking the X at m5 as a 1, the square m1, m3, m5, m7 (rows 00 and 01, columns 01 and 11) is a group of 4: B and C change, remains.
- The X at m0 and m2 do not help any needed group and stay as 0. Factoring, the POS is , cheaper still.
Solve it in Simuveliq
- «Load» → With don't cares: Σm(1,3,7,11,15) + d(0,2,5). The map shows the X and the two groups; Expressions gives the SOP , the POS and the cost of each one («POS is cheaper»).
- In Quine–McCluskey, the X take part in the combinations marked «(X)», but they are not columns of the implicant table: they need not be covered.
Example 6Cyclic function (Petrick's method)
Solution
- The six 1s form a ring of pairs and there are six 2-cell prime implicants: (1, 5), (2, 6), (0, 2, which wraps around the edges), (0, 1), (5, 7) and (6, 7).
- Each 1 is in two of them, so none is essential: the map does not say where to start.
- Petrick: for each minterm, the sum of the implicants that cover it, and the product is required to be 1: . The cheapest products have 3 terms: and .
Solve it in Simuveliq
- «Load» → Cyclic function (Petrick). Quine–McCluskey says «There are no essential implicants (cyclic function)», writes Petrick's product and picks P3, P1, P6: , the groups on the map.
Example 7Full adder
Solution
- Truth table: the sum of three bits goes from 0 to 3 = 11₂. S is the low bit and is 1 when there is an odd number of ones: (the map of S is a checkerboard, with no pairs: XOR).
- is 1 with two or three ones: it is the majority voter of example 4, .
- To reuse the XOR of A and B, write : if A and B are 1 there is a carry; if only one is 1, there is a carry when arrives. That is 5 gates: two XOR, two AND and one OR.
- Check: 1 + 1 + 0 = 2 = 10₂, so S = 0 and = 1; and 1 + 1 + 1 = 3 = 11₂, S = 1 and = 1.
Solve it in Simuveliq
- In Engineering → Digital circuits, «Load example» → Full adder. Click the switches A, B and Cin and watch the LEDs S and Cout.
- The truth table the simulator gets from the circuit gives S = 0, 1, 1, 0, 1, 0, 0, 1 and Cout = 0, 0, 0, 1, 0, 1, 1, 1 for rows 000 to 111, with the expressions (A ⊕ B) ⊕ Cin and (A ⊕ B)Cin + AB.
Example 8Detector of the sequence 101
Solution
- States according to how much of the sequence has been seen: S0 = nothing, S1 = «1», S2 = «10». From S2, a 1 completes 101 (Z = 1) and that 1 is already the start of another: go to S1 (overlap). A 0 in S2 gives «100», which is useless: back to S0.
- Three states → flip-flops: S0 = 00, S1 = 01, S2 = 10; code 11 is unused (X).
- With D flip-flops, : only when going to S2 (from S1 with X = 0), and when going to S1, which happens with every X = 1. With the X of code 11, the maps give , and .
- Check with X = 1 0 1 0 1: states S0 → S1 → S2 → S1 → S2 → S1 and Z = 0 0 1 0 1, two detections.
Solve it in Simuveliq
- In Engineering → State machines, in Examples, «Load» → 101 detector (Mealy, overlapping).
- You see the State diagram, the Transition and excitation table · D (with «With 3 states, k = ⌈log₂ 3⌉ = 2 flip-flops are needed») and the Minimal equations with their map: D1 = Q0X̄, D0 = X, Z = Q1X. «Build the circuit in the simulator» builds it with its clock so you can test it.
Example 9Modulo-5 counter with T flip-flops
Solution
- Five states → 3 flip-flops (, from 000 to 100); codes 101, 110 and 111 never appear: X.
- With T, : a flip-flop is toggled when its bit has to change. From 011 to 100 all three change () and from 100 to 000 only (100).
- Excitation table for 000, 001, 010, 011, 100: = 0, 0, 0, 1, 1; = 0, 1, 0, 1, 0; = 1, 1, 1, 1, 0.
- Maps with the X: , , , and the Moore output .
Solve it in Simuveliq
- «Load» → Modulo-5 counter (T). The excitation table says «The 3 unused codes are don't-cares (X)» and the Minimal equations give T2 = Q2 + Q1Q0, T1 = Q0, T0 = Q̄2 and Z = Q2.
- Change the flip-flops to D or JK in Implementation to compare how many gates each one needs.