diff --git a/Digital Circuits/circuits/arithmetic-circuits.md b/Digital Circuits/circuits/arithmetic-circuits.md new file mode 100644 index 00000000..2871ba0a --- /dev/null +++ b/Digital Circuits/circuits/arithmetic-circuits.md @@ -0,0 +1,146 @@ +# Arithmetic digital circuits + +Everything that a computer can do can be boiled down to mathematics and arithmetics. So being able to do arithmetics with digital circuits will be the next big step we're going to take. + +We'll be building some digital circuits capable of addition and subtraction + +___ + +# Half adder + +## Description + +This circuit will take in 2 input bits, add them together and output 2 bits. + +This circuit will be the foundation for other arithmetic circuits + +## Truth table + +> Note: h is the high bit, l is the low bit + +| a | b | h | l | +| - | - | - | - | +| 0 | 0 | 0 | 0 | +| 0 | 1 | 0 | 1 | +| 1 | 0 | 0 | 1 | +| 1 | 1 | 1 | 0 | + +## Structure + +This can be created using an AND gate and an XOR gate: + +![half adder structure](../images/half-adder-structure.png) + +___ + +# Full adder + +## Description + +This circuit works the same way as the half adder circuit, but it will take 3 input bits instead of 2 input bits. + +## Truth table + +| a | b | c | h | l | +| - | - | - | - | - | +| 0 | 0 | 0 | 0 | 0 | +| 0 | 0 | 1 | 0 | 1 | +| 0 | 1 | 0 | 0 | 1 | +| 0 | 1 | 1 | 1 | 0 | +| 1 | 0 | 0 | 0 | 1 | +| 1 | 0 | 1 | 1 | 0 | +| 1 | 1 | 0 | 1 | 0 | +| 1 | 1 | 1 | 1 | 1 | + +## Structure + +This can be constructed by connecting 2 half adders together + +![full adder structure](../images/full-adder-structure.png) + +___ + +# Multi-bit adder + +## Description + +This circuit functions similarly to how we would do binary addition. It takes in 5 bits (2 2-bit numbers and 1 carry bit), add them together and output a 3-bit number. + +Input: +- *ah* *al* is a 2-bit number +- *bh* *bl* is a 2-bit number +- *c* is a carry bit + +Output: +- *h* is the high bit +- *m* is the middle bit +- *l* is the low bit + +## Truth table + +The truth table is very big so I'll just put an example: + +| ah | al | bh | bl | c | h | m | l | +| -- | -- | -- | -- | - | - | - | - | +| 1 | 0 | 1 | 0 | 1 | 1 | 0 | 1 | + +ah = 1 and al = 0 (Number is 2 in binary) + +ah = 1 and al = 0 (Number is 2 in binary) + +c = 1 (1 carry bit) + +h = 1, m = 0, l = 1 (101 in binary, 5 in decimal) + +so 2 + 2 + 1 = 5 + +## Structure + +This circuit can be created using 2 full adders. 1 adder's high bit will carry over to the input of the other adder, this mimics how we carry bits when we manually add binary numbers. + +![multi-bit addder structure](../images/multi-bit-adder-structure.png) + +> We can keep adding onto this and create adders that can handle more bits like a 16-bit or 32-bit adder + +___ + +# Increment + +## Description + +It's quite useful to have a circuit that can count up 1 by 1 in computer science and programming. So let's learn about the increment circuit. + +This circuit will take in a number and increment it by 1. For this, we will use 16-bit number since it's quite useful to have something that can add multi-bit number. + +## Structure + +![increment structure](../images/increment-16-structure.png) + +___ + +# Subtraction + +## Description + +A big part of mathematics is subtraction. So let's learn about a circuit that allows us to subtract a number from another. We'll use 16-bit number because that allows us to subtract bigger number. + +## Truth table + +Here's an example truth table for how the circuit should function: + +| input 1 | input 2 | output | +| --- | --- | --- | +| A | 9 | 1 | +| 8FFF | 7FFF | 1000 | + +> Note: The number uses 2's complement, meaning the most significant bit will be the sign bit. If the sign bit is 1 then the number is negative + +## Structure + +What we need to do when we subtract is to flip the 2nd number to its negative counterpart and add it to the 1st number. + +There's a slight problem, which is when we flip a number from positive to negative in binary, for example, we want to change a 16-bit 1 to a 16-bit -1, if we just use a 16-bit inverter, we just changed the number to a 16-bit -2 instead. So what we need to do is to add 1 into the inverted number with the increment circuit we created before. + +> Note: A 16-bit inverter will just flip all the bits in a 16-bit number. It will change 1 to 0 and vice versa + +![subtraction circuit](../images/subtraction-16-structure.png) diff --git a/Digital Circuits/circuits/basic-gates.md b/Digital Circuits/circuits/basic-gates.md new file mode 100644 index 00000000..ec766196 --- /dev/null +++ b/Digital Circuits/circuits/basic-gates.md @@ -0,0 +1,132 @@ +# Basic logic gates + +The logic gates are the building blocks for digital circuits. They represent Boolean logical operations. Let's learn about some of them. + +___ + +# NAND gates + +## Description + +This is the most fundamental logic gate. In fact, you can build an entire computer using just NAND gates. This gate only produces an output of 0 if all of its input is 1. + +This can be made using just 2 switches. + +## Truth table + +| a | b | out | +| - | - | --- | +| 0 | 0 | 1 | +| 0 | 1 | 1 | +| 1 | 0 | 1 | +| 1 | 1 | 0 | + +## Symbol + +![nand gate symbol](../images/nand-gate.png) + +___ + +# NOT gate + +## Description + +The NOT gate, also known as the inverter gate, takes in 1 input and output 1 output. This circuit will invert the input, so if the input is 1 then the output will be 0 and vice versa. + +## Truth table + +| in | out | +| -- | --- | +| 0 | 1 | +| 1 | 0 | + +## Structure + +This gate can be created using 1 NAND gate: + +![not gate structure](../images/not-gate-structure.png) + +## Symbol + +![not gate symbol](../images/not-gate.png) + +___ + +# AND gate + +## Description + +This gate will take in 2 or more input and only output a 1 if all inputs are 1. + +## Truth table + +| a | b | out | +| - | - | --- | +| 0 | 0 | 0 | +| 0 | 1 | 0 | +| 1 | 0 | 0 | +| 1 | 1 | 1 | + +## Structure + +This gate can be created using a NAND gate and a NOT gate because it's basically the opposite of a NAND gate: + +![and gate structure](../images/and-gate-structure.png) + +## Symbol + +![and gate symbol](../images/and-gate.png) + +___ + +# OR gate + +## Description + +This gate will take in 2 or more input and only output a 0 if all inputs are 0. + +## Truth table + +| a | b | out | +| - | - | --- | +| 0 | 0 | 0 | +| 0 | 1 | 1 | +| 1 | 0 | 1 | +| 1 | 1 | 1 | + +## Struture + +This gate can be created using a NAND gate and 2 NOT gate because so as to flip the 2 inputs: + +![or gate structure](../images/or-gate-structure.png) + +## Symbol + +![or gate symbol](../images/or-gate.png) + +___ + +# XOR (Exclusive OR) gate + +## Description + +This gate takes in 2 or more input and will only output a 1 if there's an odd number of 1s in the inputs. So this gate is quite useful if you want to differentiate between odd and even number of bits. + +## Truth table + +| a | b | out | +| - | - | --- | +| 0 | 0 | 0 | +| 0 | 1 | 1 | +| 1 | 0 | 1 | +| 1 | 1 | 0 | + +## Structure + +This gate can be created using 1 NAND gate, 1 OR gate and 1 AND gate: + +![xor gate structure](../images/xor-gate-structure.png) + +## Symbol + +![xor gate symbol](../images/xor-gate.png) diff --git a/Digital Circuits/circuits/memory-circuits.md b/Digital Circuits/circuits/memory-circuits.md new file mode 100644 index 00000000..3a10fea9 --- /dev/null +++ b/Digital Circuits/circuits/memory-circuits.md @@ -0,0 +1,99 @@ +# Memory circuits + +A very useful function of a computer is its ability to "remember" information, which is why memory circuits are very important. It is extremely useful to be able to hold data inputed into a circuit, so let's learn about some memory circuits + +___ + +# Data latch + +## Description + +A data latch is capable of outputing and storing a single bit. It takes in 1 input bit as data and 1 input bit as a store signal. A store signal is used to indicate whether the circuit should store the input data or not. When the store signal is 1, the value of data is outputed and stored. When the store signal is 0, the value of data is ignored and the previously stored value is outputed + +## Truth table + +> Note: st is the store signal, d is the input data bit + +| st | d | Effect | +| -- | - | ------ | +| 1 | 0 | output set to 0 | +| 1 | 1 | output set to 1 | +| 0 | 1 | output set to previously stored value | +| 0 | 0 | output set to previously stored value | + +## Structure + +This circuit can be created using 2 AND gates, 2 NOR (inverted OR) gates and 1 NOT gate. + +A useful concept to remember is that when you connect the output of 2 NOR gates to the inputs of each other, you create a latch circuit. This circuit will hold on to its previous state, what we need to do is to lock the input to the NOR latch circuit if st is not set. we can do this using AND gates + +A NOR latch has this structure: + +![nor latch structure](../images/nor-latch-structure.png) + +Data latch structure: + +![latch structure](../images/latch-structure.png) + +___ + +# Data Flip-Flop (DFF) + +## Description + +This circuit is similar to the data latch, it is capable of storing and outputing 1 bit of information, but this circuit's output only change when a clock signal input goes HIGH (change from 0 to 1). This event is called a clock tick. + +> A clock will continously go HIGH (0 to 1) and LOW (1 to 0). This helps with timing in a computer. + +If the store signal is 1 at the time of the clock tick. the input data bit will become the new output and gets stored into the circuit. Otherwise, the output doesn't change. + +## Truth table + +| st | d | output at clock tick | +| -- | - | ------ | +| 1 | 0 | 0 | +| 1 | 1 | 1 | +| 0 | 1 | previously stored data | +| 0 | 0 | previously stored data | + +## Structure + +This circuit will need 2 data latches, 1 for latching the data input and wait for the clock to go HIGH, 1 for storing the actual data. We'll also need 2 AND gates and 1 NOT gate to validate the store signal and check if it's a 1 or 0. + +> Note: clk is the clock signal + +![dff structure](../images/dff-structure.png) + +___ + +# Register + +## Description + +The register is a very important component as it is responsible for storing immediate data for quick access. A register can hold multiple bits of data. We'll learn how a 2-bit register works. We can later on expand this 2-bit register work hold more bits using the same technique. + +The register functions similarly to the data flip-flop, except it can store multiple bits. + +## Structure + +This circuit can be created with 2 DFFs. It is quite simple. With this simple structure, we can keep adding onto it and create a register that can store however many bits we want. + +![register structure](../images/register-structure.png) + +___ + +# RAM + +## Description + +The RAM (Random Access Memory) is a memory unit with multiple different registers that we can address and use. + +For this circuit, we'll build a simple RAM circuit with 2 16-bit registers that we can address using a 1-bit address signal (ad). When ad is 1, the second register will be picked. When ad is 0, the first register will be picked. + +## Structure + +This circuit will need 2 16-bit registers, a switch to select which registers to use based on the ad signal, and a 16-bit multiplexer to select which of the 2 registers to output. + +> Note: d16 is the 16-bit number to be stored. + +![ram structure](../images/ram-structure.png) diff --git a/Digital Circuits/circuits/switching-circuits.md b/Digital Circuits/circuits/switching-circuits.md new file mode 100644 index 00000000..8788d131 --- /dev/null +++ b/Digital Circuits/circuits/switching-circuits.md @@ -0,0 +1,53 @@ +# Switching circuits + +It turns out, being able to select which input signals and which output path for our signals to go to is quite useful. So let's explore how to build a digital circuit that allows us to select which input signal and which output path to use. + +___ + +# Multiplexer + +## Description + +A multiplexer pick between 2 inputs using a select signal. If select is 1, it picks the 2nd input. If select is 0, it picks the 1st input. + +## Truth table + +> Note: s is the select signal + +| s | a | b | output | +| - | - | - | ------ | +| 0 | 0 | 0 | 0 | +| 0 | 1 | 0 | 0 | +| 0 | 0 | 1 | 1 | +| 0 | 1 | 1 | 1 | +| 1 | 0 | 0 | 0 | +| 1 | 0 | 1 | 0 | +| 1 | 1 | 0 | 1 | +| 1 | 1 | 1 | 1 | + +## Structure + +![multiplexer structure](../images/multiplexer-structure.png) + +___ + +# Switch + +## Description + +This circuit will channel input data bit to 1 of 2 output paths. It will take in 2 input signals, 1 select signal and 1 input data signal. It also has 2 output paths for the circuit to select between. + +## Truth table + +> Note: d is the input data bit + +| s | d | out1 | out0 | +| - | - | ---- | ---- | +| 0 | 0 | 0 | 0 | +| 0 | 1 | 0 | 1 | +| 1 | 0 | 0 | 0 | +| 1 | 1 | 1 | 0 | + +## Structure + +![switch structure](../images/switch-structure.png) diff --git a/Digital Circuits/images/and-gate-structure.png b/Digital Circuits/images/and-gate-structure.png new file mode 100644 index 00000000..03915ec6 Binary files /dev/null and b/Digital Circuits/images/and-gate-structure.png differ diff --git a/Digital Circuits/images/and-gate.png b/Digital Circuits/images/and-gate.png new file mode 100644 index 00000000..9ab19dfc Binary files /dev/null and b/Digital Circuits/images/and-gate.png differ diff --git a/Digital Circuits/images/dff-structure.png b/Digital Circuits/images/dff-structure.png new file mode 100644 index 00000000..d8f52358 Binary files /dev/null and b/Digital Circuits/images/dff-structure.png differ diff --git a/Digital Circuits/images/full-adder-structure.png b/Digital Circuits/images/full-adder-structure.png new file mode 100644 index 00000000..a0bff48d Binary files /dev/null and b/Digital Circuits/images/full-adder-structure.png differ diff --git a/Digital Circuits/images/half-adder-structure.png b/Digital Circuits/images/half-adder-structure.png new file mode 100644 index 00000000..5b1ec1d0 Binary files /dev/null and b/Digital Circuits/images/half-adder-structure.png differ diff --git a/Digital Circuits/images/increment-16-structure.png b/Digital Circuits/images/increment-16-structure.png new file mode 100644 index 00000000..911fcfa0 Binary files /dev/null and b/Digital Circuits/images/increment-16-structure.png differ diff --git a/Digital Circuits/images/latch-structure.png b/Digital Circuits/images/latch-structure.png new file mode 100644 index 00000000..6968d021 Binary files /dev/null and b/Digital Circuits/images/latch-structure.png differ diff --git a/Digital Circuits/images/multi-bit-adder-structure.png b/Digital Circuits/images/multi-bit-adder-structure.png new file mode 100644 index 00000000..b30ede47 Binary files /dev/null and b/Digital Circuits/images/multi-bit-adder-structure.png differ diff --git a/Digital Circuits/images/multiplexer-structure.png b/Digital Circuits/images/multiplexer-structure.png new file mode 100644 index 00000000..51a79e77 Binary files /dev/null and b/Digital Circuits/images/multiplexer-structure.png differ diff --git a/Digital Circuits/images/nand-gate.png b/Digital Circuits/images/nand-gate.png new file mode 100644 index 00000000..84b415c8 Binary files /dev/null and b/Digital Circuits/images/nand-gate.png differ diff --git a/Digital Circuits/images/nor-latch-structure.png b/Digital Circuits/images/nor-latch-structure.png new file mode 100644 index 00000000..da9a4213 Binary files /dev/null and b/Digital Circuits/images/nor-latch-structure.png differ diff --git a/Digital Circuits/images/not-gate-structure.png b/Digital Circuits/images/not-gate-structure.png new file mode 100644 index 00000000..76951baa Binary files /dev/null and b/Digital Circuits/images/not-gate-structure.png differ diff --git a/Digital Circuits/images/not-gate.png b/Digital Circuits/images/not-gate.png new file mode 100644 index 00000000..7dbaec9a Binary files /dev/null and b/Digital Circuits/images/not-gate.png differ diff --git a/Digital Circuits/images/or-gate-structure.png b/Digital Circuits/images/or-gate-structure.png new file mode 100644 index 00000000..ac8e2f80 Binary files /dev/null and b/Digital Circuits/images/or-gate-structure.png differ diff --git a/Digital Circuits/images/or-gate.png b/Digital Circuits/images/or-gate.png new file mode 100644 index 00000000..21ef9f56 Binary files /dev/null and b/Digital Circuits/images/or-gate.png differ diff --git a/Digital Circuits/images/ram-structure.png b/Digital Circuits/images/ram-structure.png new file mode 100644 index 00000000..e1c34489 Binary files /dev/null and b/Digital Circuits/images/ram-structure.png differ diff --git a/Digital Circuits/images/register-structure.png b/Digital Circuits/images/register-structure.png new file mode 100644 index 00000000..2395bec7 Binary files /dev/null and b/Digital Circuits/images/register-structure.png differ diff --git a/Digital Circuits/images/subtraction-16-structure.png b/Digital Circuits/images/subtraction-16-structure.png new file mode 100644 index 00000000..444617ab Binary files /dev/null and b/Digital Circuits/images/subtraction-16-structure.png differ diff --git a/Digital Circuits/images/switch-structure.png b/Digital Circuits/images/switch-structure.png new file mode 100644 index 00000000..d83b215a Binary files /dev/null and b/Digital Circuits/images/switch-structure.png differ diff --git a/Digital Circuits/images/xor-gate-structure.png b/Digital Circuits/images/xor-gate-structure.png new file mode 100644 index 00000000..a019b5d0 Binary files /dev/null and b/Digital Circuits/images/xor-gate-structure.png differ diff --git a/Digital Circuits/images/xor-gate.png b/Digital Circuits/images/xor-gate.png new file mode 100644 index 00000000..e3db9462 Binary files /dev/null and b/Digital Circuits/images/xor-gate.png differ diff --git a/Digital Circuits/readme.md b/Digital Circuits/readme.md new file mode 100644 index 00000000..7699c364 --- /dev/null +++ b/Digital Circuits/readme.md @@ -0,0 +1,31 @@ +# Digital Circuits + +Digital circuits carry electrical signals, just like normal analog circuits. The difference between the 2 is that digital circuits only have 2 states: 1 or 0. Digital circuits is the foundation for binary and Boolean logic. They are the backbones of modern computers. + +Digital circuits are made of multiple logic gates, which are devices that perform can perform Boolean logic. These circuits can perform mathematical calculations using just electrical signals. + +## Table of Contents +- [How digital circuits changed the world](#how-digital-circuits-changed-the-world) +- [Logic gates](#logic-gates) +- [Types of digital circuits](#types-of-digital-circuits) + +# How digital circuits changed the world + +Digital circuits, while they may seem not very useful at first glance, are the foundation for modern electronics and computers. They enable computers to process information and perform complex mathematics with high level of precision. + +These circuits allow us to build complex machines that can even simulate intelligence. So digital circuits are quite important for our modern world. + +# Logic gates + +These devices are the building blocks of digital circuits. They are capable of performing Boolean logic. They basically represent a Boolean function. + +These logic gates can be connected to each other the same way Boolean logic can be cascaded together to perform complex Boolean algebra calculations and output precise results. + +Any algorithms and mathematics that can be describe with Boolean logic can be represented using digital circuits made up of logic gates. So a Boolean logic equation can be translated to a digital circuits, with each Boolean expression being represented by a logic gate. + +# Types of digital circuits + +There are 2 types of digital circuits: Combinational and Sequential + +- **Combinational Circuits**: In this type of digital circuit, the output is reliant on the input it receives at an instant. This type of circuit will stay constant to its input. +- **Sequential Circuits**: In this type of digital circuit, the output is reliant on not only the input it receives at an instant but also the previous input that it received. The output generated from the previous input is transferred into the output of the current input diff --git a/README.md b/README.md index ca0d0777..297563e4 100644 --- a/README.md +++ b/README.md @@ -29,6 +29,7 @@ If you're interested in contributing to this project, please take a moment to re - [Introduction](#introduction) - [Electronic Computer](#electronic-computer) - [Boolean Logic](#boolean-logic) +- [Digital Circuits](#digital-circuits) - [Number Systems](#number-systems) - [Central Processing Unit(CPU)](#central-processing-unit-cpu) - [Registers, Cache, and RAM](#registers-cache-and-ram) @@ -85,6 +86,26 @@ Boolean logic is a branch of mathematics that deals with the values of truth and | ⊽ | NOR | Returns **true** if all operands are false. | | ⊼ | NAND | Returns **false** only if both values of its two inputs are true. | +## [Digital Circuits](Digital%20Circuits/readme.md) + +Digital circuits deal with Boolean signals (1 and 0). They are the fundatmental building blocks of a computer. They are the components and circuits used to create processor units and memory units essential to a computer system. + +### Truth tables + +Truth tables are mathematical tables used in logic and digital circuit design. They help to map out the functionality of a circuit. We can use them to help design complex digital circuits. + +Truth tables have 1 column for each input variable and 1 final column showing all of the possible results of the logical operation that the table represents. + +### Types of digital circuits + +There are 2 types of digital circuits: Combinational and Sequential + +- **Combinational Circuits**: In this type of digital circuit, the output is reliant on the input it receives at an instant. This type of circuit will stay constant to its input. +- **Sequential Circuits**: In this type of digital circuit, the output is reliant on not only the input it receives at an instant but also the previous input that it received. The output generated from the previous input is transferred into the output of the current input + +### Design methodology + +When designing a digital circuit, especially complex ones. It is important to utilize Boolean algebra tools to help with the design process (example: Karnaugh map). It is also important to break everything down into smaller circuits and examine the truth table needed for that smaller circuit. Don't try to tackle the whole circuit at once, break it down and gradually put the pieces together. ## [Number Systems](Number%20System/readme.md#number-systems) Number systems are mathematical systems for expressing numbers. A number system consists of a set of symbols that are used to represent numbers and a set of rules for manipulating those symbols. The symbols used in a number system are called numerals.