Logic Circuits
"<b>Logic Circuits</b>: The DNA of Computers. <br><br>Beshy, ito na 'yun. Kung walang Logic Circuits, walang computer, walang internet, walang cellphone. We are going to dive DEEP. Hihimayin natin from the electrons sa wires hanggang sa complex state machines. Hindi pwedeng 'pwede na' dito. Dapat master mo. <br><br>We will cover everything from <b>Number Systems</b> (the language) to <b>Sequential Circuits</b> (the memory). Ready ka na ba sumakit ang ulo sa kakaisip ng 1s and 0s? Let's go!"
Chapter 1: Number Systems & Codes
Speaking the Machine's Language
1.1 Positional Number Systems
Technical Definition
A number system is defined by its base (or radix) $r$. A number represents a value based on the position of its digits. The general formula for the value of a number $d_n...d_1d_0.d_{-1}...d_{-m}$ is:
🧠 Beshy Explanation
Imagine mo beshy, 'yung pera natin. 'Pag may ₱1,000 bill ka, value niya 1000 diba? Pero 'pag may ₱1 coin ka, 1 lang. Pareho silang "pera" pero depende sa pwesto o mukha (base) nila kung gaano sila kabigat.
Sa Decimal (Base 10), digits natin 0-9. 'Pag naubusan ka na ng digits (naka-9 ka na), nag-a-add ka ng 1 sa kaliwa tapos reset sa 0 (nagiging 10). Ganon din sa ibang base:
- Binary (Base 2): 0 at 1 lang. Parang switch—ON or OFF. 'Pag puno na (1), lipat sa kaliwa (10, na equivalent sa 2 natin).
- Octal (Base 8): 0-7. Minsan ginagamit pang-shortcut ng binary.
- Hexadecimal (Base 16): 0-9 tapos A-F. Si 'A' ay 10, si 'F' ay 15. Ito yung nakikita mo sa mga color codes (#FFFFFF) o memory addresses!
1.2 Base Conversions
Decimal to Base-r (Integer)
Method: Successive Division.
Divide the number by the target base $r$. Record the remainder. Repeat with the quotient until it becomes 0. Read remainders from Bottom to Top (MSB to LSB).
Beshy Tip: Divide nang divide, tapos yung mga "sobra" (remainder), yun yung sagot, pabaligtad ang basa!
Decimal to Base-r (Fraction)
Method: Successive Multiplication.
Multiply the fraction by base $r$. Record the integer part. Repeat with the new fraction until 0 or precision reached. Read integers from Top to Bottom.
Beshy Tip: Multiply naman dito. Kunin mo yung whole number sa kaliwa, yun ang sagot, pababa ang basa!
1.3 Complements & Signed Numbers
Technical Concept: r's and (r-1)'s Complement
To simplify subtraction in hardware, computers use complements.
- (r-1)'s Complement: Subtract each digit from $(r-1)$. In binary, this is 1's Complement (invert bits).
- r's Complement: (r-1)'s Complement + 1. In binary, this is 2's Complement.
🧠 Beshy Explanation: Negative Numbers
Paano nagne-negative ang computer e puro 0 at 1 lang alam nun? Wala namang "negative sign" key sa loob ng CPU.
Dito pumapasok ang 2's Complement. Ito ang standard!
- Sign-Magnitude: Yung pinaka-kaliwang bit (MSB) ay sign. 0 = Positive, 1 = Negative.
Problema: May dalawang zero (+0 at -0). Sayang sa space at hassle sa math. - 1's Complement: Baliktarin lahat ng bits. 0101 magiging 1010.
Problema: May dalawang zero pa rin. - 2's Complement (The Winner 🏆): Kunin ang 1's complement tapos mag-add ng 1.
Bakit winner? Isa lang ang zero. At pag nag-add ka ng positive at negative number, automatic tama ang sagot, di na kailangan ng special logic para sa subtraction!
Chapter 2: Boolean Algebra
The Mathematics of Logic
2.1 Axioms and Theorems
Boolean algebra operates on variables that can only be 0 (False) or 1 (True). George Boole formulated this in 1854.
| Theorem | Expression (OR / AND) | Beshy Explanation |
|---|---|---|
| Identity | $X + 0 = X$ $X \cdot 1 = X$ |
Pag nag-add ka ng wala, o nag-multiply sa 1, walang pagbabago. "Stay ka lang." |
| Null | $X + 1 = 1$ $X \cdot 0 = 0$ |
Pag may 1 sa OR, automatic 1 na. Pag may 0 sa AND, automatic 0 na. "Sapaw." |
| Idempotent | $X + X = X$ $X \cdot X = X$ |
Kahit ulit-ulitin mo, 'yun pa rin 'yun. "True or True" is just True. |
| Complement | $X + X' = 1$ $X \cdot X' = 0$ |
Ikaw o ang kabaliktaran mo? Edi lahat (1). Ikaw at ang kabaliktaran mo? Impossible (0). |
| De Morgan's | $(X+Y)' = X'Y'$ $(XY)' = X'+Y'$ |
"Break the bar, change the sign." Ang inverse ng OR ay AND ng mga inverses. |
2.2 Canonical Forms (SOP vs POS)
Sum of Products (SOP)
Also known as Minterm Expansion.
- Focuses on output 1.
- Uses AND terms summed by OR.
- Notation: $\sum m(1, 3, 7)$
- Minterm: $A'BC$ (Example for 011)
Product of Sums (POS)
Also known as Maxterm Expansion.
- Focuses on output 0.
- Uses OR terms multiplied by AND.
- Notation: $\prod M(0, 2, 4)$
- Maxterm: $(A+B'+C)$ (Example for 010 - note the inversion is reversed!)
Chapter 3: Map Simplification
Making Circuits Cheaper and Faster
3.1 The Karnaugh Map (K-Map)
A graphical tool to simplify Boolean equations. It works because of the Adjacency Property: adjacent cells differ by only one bit (Gray Code).
Rules of the Game (Grouping):
-
RULE 1
Power of 2: Pwede lang mag-group ng 1, 2, 4, 8, 16 cells. Bawal ang 3, 5, o 6!
-
RULE 2
Rectangular: Dapat square o rectangle ang shape ng group. Bawal ang "L" shape o Tetris blocks.
-
RULE 3
Maximize: Gawin mong pinakamalaki ang group na kaya. Mas malaking group = Mas simpleng equation = Mas tipid sa gates!
-
RULE 4
Wrap Around: Ang K-Map ay parang Pac-Man world. Ang dulo sa kanan ay kadugtong ng kaliwa. Ang taas ay kadugtong ng baba.
Don't Care Conditions (X)
Minsan may mga input combinations na imposible mangyari (like codes 1010-1111 in BCD). Tinatawag itong "Don't Cares".
"Beshy, ang 'Don't Care' ay parang joker card. Pwede mong gawing 1 kung makakatulong palakihin ang group mo. Pwede ring gawing 0 kung sagabal. Use them wisely to simplify your circuit!"
Chapter 4: Combinational Logic
Circuits Without Memory
4.1 Arithmetic Circuits
Half Adder vs Full Adder
Half Adder: Adds 2 bits. Outputs Sum and Carry.
Equation: $S = A \oplus B$, $C = AB$.
Full Adder: Adds 3 bits (A, B, Carry-In). Needed for adding multi-bit numbers.
Beshy Note
Isipin mo ang Half Adder ay parang nag-a-add ka ng ones digit. Ang Full Adder ay parang nag-a-add ka ng tens digit—kailangan mong isama yung "carry" galing sa ones digit! Kaya "Full" kasi kumpleto rekados.
Ripple Carry vs Lookahead Carry
Ripple Carry Adder: Simple but slow. The carry has to "ripple" through every stage like a wave. If you have 64 bits, the last bit waits a long time!
Carry Lookahead Adder (CLA): Complex but fast. Uses extra logic to "predict" if a carry will be generated without waiting for the previous stage. Parang manghuhula siya!
4.2 MSI Components (MUX, DEMUX, Decoders)
Multiplexer (MUX)
"Many to One"
Acts like a digital switch. Select lines determine which input goes to the output.
Beshy Analogy: Train tracks! Maraming riles (inputs), pero iisa lang ang destination track (output). Yung switchman (selector) ang pipili kung sinong tren ang makakadaan.
Decoder
"Binary to One-Hot"
Takes an n-bit binary code and activates exactly one of $2^n$ outputs.
Beshy Analogy: Address finder. Pag sinabi mong "Unit 501", yung decoder ang maghahanap sa building kung nasaan ang Unit 501 at kakatok dun lang.
Chapter 5: Sequential Logic
Circuits with Memory and History
5.1 Latches vs Flip-Flops
Combinational circuits are amnesiacs—they forget the input as soon as it changes. Sequential circuits have Memory.
Latch (Level-Triggered)
Changes state as long as the Enable signal is active. "Transparent".
"Parang pinto na nakabukas. Habang bukas, pwedeng pumasok at lumabas ang pusa (data) anytime."
Flip-Flop (Edge-Triggered)
Changes state only at the specific moment of clock transition (rising or falling edge).
"Parang camera shutter. Kung ano lang ang itsura mo nung nag-click (clock edge), yun lang ang ma-save. Kahit mag-wacky face ka before or after, di na makikita."
5.2 The Big Four Flip-Flops
| Type | Name | Behavior | Beshy Note |
|---|---|---|---|
| SR | Set-Reset | S=1 Set, R=1 Reset. S=1, R=1 is Invalid. | Basic pero bawal sabay ang S at R, mag-aaway sila! |
| D | Data / Delay | Q follows D. Used for storage. | Gaya-gaya. Kung ano si D, yun din si Q next time. |
| JK | Jack-Kilby | Like SR, but J=1, K=1 Toggles. | Improved SR. Pag sabay silang 1, "switch" lang ng state. Walang away. |
| T | Toggle | T=1 Toggles, T=0 Holds. | Switch lang. On-Off-On-Off. |
5.3 Finite State Machines (FSM)
This is the heart of digital design. Designing a system that goes through a sequence of states.
Moore Machine
Output depends ONLY on the Current State.
Change happens sync with clock.
Mealy Machine
Output depends on Current State AND Input.
Reacts faster to inputs (async).
🎓 The Ultimate Logic Challenge
Kaya mo bang i-design ang isang 3-bit Synchronous Up/Down Counter gamit ang JK Flip-Flops mula sa scratch?
Steps to solve:
- Create the State Diagram (0-7 cycle).
- Create the Next-State Table based on Up/Down input.
- Derive Excitation Table for JK Flip-Flops.
- Use K-Maps to find equations for $J_A, K_A, J_B, K_B, J_C, K_C$.
- Draw the circuit!
"Master this, and you master the Board Exam!" - Beshy
Test Your Knowledge! 🧠
Ready ka na ba? Take the practice quiz for Logic Circuits to reinforce what you just learned.
Start Practice Quiz 📝