You are on page 1of 18

School of AI, Amrita Vishwa Vidyapeetham, Amritapuri 1 of 18

23AID102 Elements of Computing


Lecture Notes1
October 2023 Version 2

Prepared by Dr. Jayaraj Poroor

Digital circuits

The basic building block of a digital circuit is a switch with two states - ON and OFF. ON is
represented by a high voltage level (called the logic high) and OFF is represented by a low
voltage level (called the logic low). This is why it’s called digital since it has two discrete states.
The two switch states can be directly mapped to binary numbers (OFF = 0, ON = 1), hence the
importance of the binary number system in digital circuits and computers.

In digital circuits these switches are built from transistors. Unlike mechanical switches,
transistor-based switches are controlled by applying a voltage and can be quite tiny. A digital IC
(integrated circuit) may have tens, hundreds, thousands, millions, or billions of such transistor
switches.

Logic function concepts using switches

It is easy to see how conceptually we can build logic functions AND and OR using switches.

Two switches connected in series implements the conceptual AND function, i.e., the circuit is
completed only when switch 1 AND switch 2 are closed.

Two switches connected in parallel implements the conceptual OR function, i.e., the circuit is
completed when either switch 1 OR switch 2 are closed.

Schematic representation of circuits

Schematic is a diagrammatic representation of a circuit where circuit components are


represented by standardized symbols. When drawing a schematic, the positive terminal of the
power supply is often called Vcc and the negative terminal is called ground (GND).

Schematic representation of switches in parallel and series are shown below:

1
Most of the standard diagrams are taken from Internet sources and edited. Custom
diagrams/schematics and the textual content are prepared by the author.
School of AI, Amrita Vishwa Vidyapeetham, Amritapuri 2 of 18

Power supply

Digital circuits are typically powered by a low voltage power supply unit (could be a battery
pack). Typical voltages of 5v or 3.3v are common. It is important to check the datasheet of the
component to understand its voltage tolerance. Applying 5v to a 3.3v IC can damage it.

The commonly used schematic symbols for power supply, Vcc, Gnd are shown below:

Resistors

A resistor is a passive device that allows a certain amount of current to flow given an applied
voltage as given by the equation:

I = V / R.

Given an applied voltage V across a resistor R, the current I = V / R, where V is in volts, and
resistance is in Ohms and the current is in amperes.

If we can measure the current through a resistor, then we can obtain the voltage across the
resistor from the same equation above:
School of AI, Amrita Vishwa Vidyapeetham, Amritapuri 3 of 18

V = I x R.

e.g., if a current of 3 milli-ampere is flowing through a resistance of 1 kiloohm, then the voltage
V = 3 mA x 1 K = 3 x 10-3 x 1 x 103 = 3 volts.

Resistor divider

If we connect two resistors R1, R2 in series, apply a voltage (Vin) across both of them, and take
the mid-point voltage (Vout) at the junction of R1 and R2, we have a resistor divider circuit. The
schematic is shown below.

The combined resistance of R1 and R2 in series = R1 + R2

Current through the circuit = Vin/ (R1 + R2).

Now, the Voltage Vout = Current x Resistance R2 = Vin x R2/(R1 + R2)

In other words, Vout/Vin = R2/(R1+R2)

That is the mid-point voltage is a fraction of the input voltage and the ratio = R2/(R1+R2). Hence
it’s called a resistor divider.

For example, if Vin = 5, R1 = R2 = 1k, then Vout = 5*½ = 2.5v.

A resistor divider can be used to convert a 5v digital output to a 3.3v tolerant digital input.
School of AI, Amrita Vishwa Vidyapeetham, Amritapuri 4 of 18

Lighting an LED

An LED has two terminals - anode and cathode. LED (light emitting diode) will conduct and light
up only when the anode is at a certain amount of higher voltage than cathode - then the LED is
called forward biased. If anode is a lower voltage than cathode the LED is said to be reverse
biased and it will not conduct or light up.

The following figure shows a power supply (could be a battery) with a switch and an LED with
current limiting resistor. The resistor in series with the LED (typically 1Kohm) limits the current
through the circuit, so that that LED has enough current to glow but will not burn out. due to
excessive current

The schematic representation of the above circuit can be drawn as:

We can use Power and ground symbols and also draw the same schematic as shown below
(VCC represent the positive terminal an GND represent the negative terminal of the power
source):
School of AI, Amrita Vishwa Vidyapeetham, Amritapuri 5 of 18

Switches

A switch enables us to make or break a circuit using mechanical pressure. The following figure
shows an LED circuit with a push button switch. There are two kinds of switches: normally open
and normally closed. In this case, the switch is normally open. Moreover, in this case, we are
using a push button switch, which is engaged only when its pressed. When the button is
pressed, an electrical contact is made in the switch and the current flows through the circuit,
lighting the LED.

High-side and low-side switches.

When the switch is connected between the positive terminal of the power source and the load it
is called a high-side switch.

When the switch is connected between the negative terminal of the power source and the load it
is called a load-side switch.

The following figure shows high-side and low-side switches (also note the schematic symbol of
a switch).

N-channel MOSFET

In digital circuits, transistors are used as electronic switches. A common type of transistor used
is a MOSFET (Metal Oxide semiconductor Field Effect Transistor). There are different kinds of
MOSFETs. N-channel Enhancement type is a commonly used type. It’s schematic symbol is
given below:
School of AI, Amrita Vishwa Vidyapeetham, Amritapuri 6 of 18

A MOSFET has 3 terminals: Gate (G), Drain (D), and Source (S). The control voltage is applied
to the gate terminal. In N-channel enhancement type MOSFET, normally there is no conducting
channel between the Drain and Source terminals (represented by the dotted line between D and
S in the schematic symbol). When a voltage greater than a threshold voltage is applied to the
gate terminal (called the gate-source or Vgs threshold voltage) then a conducting channel is
formed between D and S. This enables the MOSFET to act as a voltage-controlled switch.

MOSFET as a low-side switch.

For N-channel enhancement type MOSFET, S must be at a lower voltage than D. Therefore, S
is usually grounded (i.e., connected to the negative terminal of the power source) and the load
is connected to the D terminal. Therefore N-channel enhancement MOSFET is typically used as
a low-side switch.

Switching DC motor with MOSFET switch.

We may connect any type of load to the Drain of the MOSFET, within the voltage and current
limits of the MOSFET. In robotic or electro-mechanical systems, DC motors are used to move
arms, or rotate wheels. MOSFET can be used to switch a DC motor on or off. The following
School of AI, Amrita Vishwa Vidyapeetham, Amritapuri 7 of 18

schematic shows MOSFET with a DC motor load (the symbol marked with ‘M’ represents a DC
motor).

Since a DC motor’s copper winding is an inductive load, when the MOSFET is switched off, a
high voltage is induced at the MOSFET terminal (due the energy stored in the magnetic field),
which can damage the MOSFET. To avoid this, a diode is connected across the motor. This
diode will bypass this induced voltage to the power supply’s positive terminal.

MOSFET as inverter.

A MOSFET with a resistor load acts as an inverter (the specific value of the resistor and the part
number of the MOSFET are not important for our discussion here). The schematic is shown
below.

When the input to the gate G is high, the MOSFET is in “ON” state. This pulls the output to low.
When the input to the gate G is low, the MOSFET is in “OFF” state. As a result, the voltage Vcc
(high) appears at the output. Therefore, when input is low the output is high and when input is
high the output is low. This is the inverting action.
School of AI, Amrita Vishwa Vidyapeetham, Amritapuri 8 of 18

We show the same circuit below with a simplified schematic symbol for the MOSFET. You may
use this simplified schematic symbol in circuits, unless you are specifically asked to draw the full
symbol.

Logic gates and truth tables

Logic gates are the building blocks of digital logic circuits. Logic gates are constructed from
MOSFETs, however we won’t go into the internals of how gates are built from MOSFETs.

The 3 basic gates are: AND, OR, and NOT (also called an inverter). An AND gate with an
inverter function is called a NAND gate (AND + NOT) and an OR gate with an inverter function
is called a NOR gate (OR + NOT).

A table listing the input vs output for a logic gate (or any digital circuit) is called its truth table.

The truth tables for the various basic gates are shown below.
School of AI, Amrita Vishwa Vidyapeetham, Amritapuri 9 of 18

NAND gate as universal gate.

NAND gate is a universal gate, in that all other basic logic gates - AND, OR, NOT can be
constructed by combining two or more NAND gates. NOR gate is also a universal gate - we will
not discuss it in further detail here.

The following figure shows how to implement AND, OR, NOT functions using NAND gate.
School of AI, Amrita Vishwa Vidyapeetham, Amritapuri 10 of 18

The advantage of using a universal gate is that from a single type of gate (like NAND) we can
construct the entire circuit.

Active high and active low

Note that, a signal that is normally high and goes low when active is called “active low” and a
signal that is normally low and goes high when active is called “active high”.

Switch as a digital input

In order to use switch as a digital input, we can either:

(a) Pull up one of its terminals to Vcc and take the input from this terminal. In this case the
switch is normally high and when the switch is pressed it goes low (is pulled to the
ground potential).
(b) Pull down one of its terminals to GND and take the input from this terminal. In this case
the switch is normally low and when the switch is pressed it goes high (is pulled up to the
Vcc).

Schematics for these are shown below:

Switch bounce and debouncing

When a switch is pressed, there is a mechanical bounce of the switch which will result in the
switch making and breaking contact multiple times during a very short interval (like
microseconds). These can appear as multiple ON/OFF inputs to a digital circuit when using
switch as digital input. In some cases, the bounce may not have an impact on the function and
can be ignored. In some cases, we need to “debounce” the switch either in software (if the
switch is input to a microcontroller) or in hardware using a capacitor to filter out the bounce
signals.
School of AI, Amrita Vishwa Vidyapeetham, Amritapuri 11 of 18

Output of a NOT gate to drive an LED

NOT gate’s output can be used to drive an LED in two ways:

In the following circuit when NOT gate input is high and its output is low the LED is forward
biased and lights up. When NOT gate input is low and its output is high the LED is not forward
biased and the LED won’t light up.

In the following circuit, when the input to the NOT gate is low and output is high the LED lights
up. When input to the NOT gate is high and output is low LED does not light up.

Simple application circuits using logic gates.

We can construct simple to complex application circuits by combining logic gates. We will look
at only some simple application circuits here.

Application Circuit

Let us say, we have an IR sensor with a digital output that is normally high and goes low when
its field is obstructed (i.e, it senses an obstacle or an object nearby). i.e., its output is active low.

Also note that the IR sensor’s output will be high again once the obstacle is removed from its
vicinity. So it gives a pulse output which remains low as long as the obstacle is present but
comes high again once the obstacle is removed (we may call this an active low pulse).
School of AI, Amrita Vishwa Vidyapeetham, Amritapuri 12 of 18

We want to light an LED when the obstacle is detected. The circuit schematic is shown below:

Application Circuit

We want to light the LED when the IR sensor detects an obstacle and also when a switch is in
ON state (which can be used to ‘arm’ the system). The schematic is given below:

SR Latch

Latches are the fundamental memory elements in a digital circuit. Latches can be built from
gates (typically NAND or NOR gates). There are different types of latch circuits. SR latch is a
basic latch circuit, which can be built from NAND or NOR gates.

The following schematic shows SR latch built from NAND gates. When S = 1, R = 1 the circuit’s
output holds onto the previous value - hence this is called the latch state. S= 0, R= 1, Q gets set
to 1. S = 1, R = 0, Q gets set to 0. S = 0, R = 0 is invalid input.
School of AI, Amrita Vishwa Vidyapeetham, Amritapuri 13 of 18

Application Circuit

Let’s say we want to design an intruder alarm system using the IR sensor. When the IR sensor
detects an object in the vicinity (it gives an active low pulse) the alarm should go off. We will use
an LED as an indicator for the alarm - instead of an LED we could use a buzzer to generate the
audio alarm. The alarm LED should remain lighted even after the IR sensor goes back high
again (obstacle is removed). A security officer must be able to come and reset the alarm LED
using a push button switch (which of course will be kept in a secure enclosure).

The circuit is given below. In the circuit, both inputs to the SR latch (built from 2 NAND gates)
are high after power up (switch is pulled high and the IR sensor’s output is normally high). This
results both inputs to the latch to be 1, which is the latch state (i.e., the output retains the
previous value). Here there is no stable previous value to latch. Therefore, we add a capacitor
across the switch. At power up, the capacitor is at ground potential, pulling the R input to the
latch to 0, setting Q to 0. After power up, in steady state the capacitor is charged and the supply
voltage (high) appears at the switch input, setting both inputs of the latch to 1. Since there is a
well-defined prior state (Q = 0). The latch output will have Q = 0 after power up.

When an obstacle is detected the IR sensor OUT will go low, setting Q = 1. To reset, press the
switch which will connect the R input to the GND, which will reset the latch, setting Q= 0.

Note that if the switch is pressed when the IR sensor’s OUT is low the latch goes into an
undefined state. Once the IR sensor’s OUT is high, we may push the switch to low to reset the
latch to a reset state.

The capacitor also has the effect of debouncing the switch, although in this circuit, bounce does
not have any adverse effect on the circuit function.
School of AI, Amrita Vishwa Vidyapeetham, Amritapuri 14 of 18

Schmitt trigger inverter.

A digital input has a threshold voltage (called the “logic threshold voltage”) above which it will
consider the input to be “high” and below which it will consider the input to be “low”. If the input
is near the threshold, it could go slightly above or below due to noise etc, causing the output to
undesirably go back and forth between high and low (a kind of undesirable oscillation).

In order to prevent this in situations where this could happen, some logic ICs have what’s called
a Schmitt trigger input. Schmitt trigger input uses two thresholds - a high and low threshold.
The following is the schematic symbol of an inverter with Schmitt trigger input (called a schmitt
trigger inverter):

The input-output voltage graph for the schmitt trigger inverter is shown below. When input
voltage is going up, when the input voltage > a high-threshold the output goes low (being an
inverter). When the input voltage starts coming down, when the input voltage < a low-threshold
(lower than the high threshold) the output goes high.

Due to the two thresholds, the undesirable output oscillation is prevented when the input is near
the thresholds.
School of AI, Amrita Vishwa Vidyapeetham, Amritapuri 15 of 18

RC time constant.

A capacitor stores energy in the form of an electric field between its plates. Due to this, when a
voltage is applied across a capacitor, a current (i.e., energy) temporarily flows into the plates to
build up the electric field and it takes some time for the voltage in the capacitor plates to come
up to the applied voltage. By connecting a series resistor we can control the amount of current
flow and in turn control the amount of time required to charge the capacitor to a certain voltage.

If a resistor R is connected in series to a capacitor C and a voltage is applied across the R, C


combination, then the product R x C is called the time constant (represented by ‘tau’ greek
symbol). The time constant is the amount of time (in secons) required to bring up the voltage
across the capacitor to 63.2% of the applied voltage. This is illustrated in the following diagram:

Oscillator using Schmitt trigger inverter and RC.

A clock is a fundamental input to a digital circuit and is used to keep time and also to progress
computations. An oscillator is a circuit that generates periodic high-low pulses and forms the
source of the clocks in a digital circuit.
School of AI, Amrita Vishwa Vidyapeetham, Amritapuri 16 of 18

We can build an oscillator using a NOT gate with an RC feedback as given below:

Here, initially the capacitor is at ground potential and input to the NOT gate is low, making its
output high. This will start charging the capacitor through the resistor. After a certain amount of
time (as determined by the RC time constant) the capacitor’s voltage crosses the logic high
threshold (of the schmitt trigger inverter), causing input to the NOT gate to be high and output
goes low (i.e, ground potential). This will start discharging the capacitor through the resistor.
After a certain amount of time the capacitor’s voltage becomes lower than the logic low
threshold (of the schmitt trigger inverter), causing the input to the NOT gate to be low and the
output to be high. This cycle repeats to generate periodic oscillations at the output of the NOT
gate.

By connecting a resistor-LED to the NOT gate output, we can see the LED blinking in time with
the oscillations (provided the time period is within visual limits).

Decade counter

A decade counter is an IC that counts the number of pulses it has received in its clock input
cyclically from 1 - 10 (or 0-9). Typically the IC gives a decoded output as logic high in outputs
numbered 1 - 10 (or 0 - 9). i.e., output N is represented as high at output pin N and low at all
other outputs.

The following circuit shows a counter IC with LEDs connected to each outputs. So when count =
N, then the Nth LED will be lighted.

The IC also has a reset input, a high on the reset input will reset the count back to 1. It also has
another active low input called clock enable (or disable). When clock enable is low the IC
operation is enabled and it does counting, if it’s high then the counting is disabled.
School of AI, Amrita Vishwa Vidyapeetham, Amritapuri 17 of 18

Terminal count (carry) and cascading

Typically the IC will also have a carry (or terminal count - TC) output, which goes high after the
10th count and goes low again after 5 clock counts. This allows us to connect the TC as clock
input to another decade counter. This will cause the second decade counter to count in the 10th
decimal place and the first one to count in the unit place. This is called cascading of counters.
We can have any number of cascaded stages. e.g., we can connect the TC of the 2nd counter
to clock input of a 3rd counter in which case the 3rd counter will start counting in the 100th
place, and so on.

Timing diagram

The timing diagram showing clock input, count outputs and the TC output is shown below:
School of AI, Amrita Vishwa Vidyapeetham, Amritapuri 18 of 18

Counting modulo N

By default, the decade counter will count modulo 10 (i.e., in cycles of 1-10-1-10..). We can make
it count module N (where N is between 1 and 9) by connecting the Nth output to the reset input.
This will reset the counter when Nth output goes high and it will start counting from 1.

Application Circuit - Clock divider

A decade counter can be used to divide a clock input by 10 (or by N < 10). The oscillator output
is given as clock input and the TC output is taken as the divided clock output.

Application Circuit - Counting items

Let’s say we have a conveyor through which items are being passed. An IR sensor is fixed by
the side of the conveyor. When an item passes near the sensor its output goes low (considering
it to have an active low output). We may pass this output through an inverter and give as clock
input to the counter. This will enable us to count the number of items passed. We can use LEDs
as indicators for the count.

Let’s say we want to light an LED (or raise an alarm) when at least N (N < 10) items have
passed. Then we can take the Nth output and give as input to a latch and the output of the latch
can be used to drive an LED (or drive a buzzer). We can extend this to any N by having
cascaded counting.

You might also like