Deld Notes
Deld Notes
Deld Notes
Boolean algebra
Another approach is to express the logic function with logic equations. This is done with the use of Boolean
algebra (named after Boole, a 19th century mathematician). In Boolean algebra, all the variables have the values
0 or 1 and, in typical formulations, there are three operators:
• The AND operator is written as , as in . The result of an AND operator is 1 only if both inputs are 1. The
AND operator is also called logical product, since its result is 1 only if both operands are 1.
• The unary operator NOT is written as. The result of a NOT operator is 1 only if the input is 0. Applying
the operator NOT to a logical value results in an inversion or negation of the value (i.e., if the input is 0
the output is 1, and vice versa).
There are several laws of Boolean algebra that are helpful in manipulating logic equations.
In addition, there are two other useful theorems, called DeMorgan’s laws,
Any set of logic functions can be written as a series of equations with an output on the left-hand side of each
equation and a formula consisting of variables and the three operators above on the right-hand side.
DeMorgan's Theorems:
a. (A + B) = A* B
b. A*B = A + B
Note: * = AND operation
Prove: (A*B)*( A + B) =0
(A*B)*( A + B) = (A*B)*A + (A*B)*B) by distributive postulate
= (A*A)*B + A*(B*B) by associativity postulate
= 0*B + A*0 by complement postulate
= 0+0 by nullity theorem
= 0 by identity theorem
(A*B)*( A + B) = 0 Q.E.D.
If more positive voltage is taken as the 1 level and the other as the 0 level, the logic system is known as the
positive logic system.
If more negative voltage is taken to represent the 1 level and the other for the 0 level, the logic system is known
as negative logic system.
Logic gate
A logic gate is an idealized or physical device implementing a Boolean function, that is, it performs a logical
operation on one or more logic inputs and produces a single logic output. Depending on the context, the term
may refer to an ideal logic gate, one that has for instance zero rise time and unlimited fan-out, or it may refer to
a non-ideal physical device.
Logic gates are primarily implemented using diodes or transistors acting as electronic switches, but can also be
constructed using electromagnetic relays (relay logic), fluidic logic, pneumatic logic, optics, molecules, or even
mechanical elements.
Digital systems are said to be constructed by using logic gates. These gates are the AND, OR, NOT, NAND, NOR,
EXOR and EXNOR gates.
Input A Output Q
0 1
1 0
AND gate
• The output Q is true if input A AND input B are both true: Q = A AND B
• An AND gate can have two or more inputs, its output is true if all inputs are true.
• A dot (.) is used to show the AND operation i.e. A.B.
OR gate
• The output Q is true if input A OR input B is true (or both of them are true): Q = A OR B
• An OR gate can have two or more inputs, its output is true if at least one input is true.
• A plus (+) is used to show the OR operation.
Universal gates are the ones which can be used for implementing any gate like AND, OR and NOT, or any
combination of these basic gates; NAND and NOR gates are universal gates. To facilitate the conversion to
NAND and NOR logic, we have two new graphic symbols for these gates.
The table below shows the NAND gate equivalents of NOT, AND, OR and NOR gates:
NOT
AND
OR
NOR
Canonical form
• In Boolean algebra, any Boolean function can be expressed in a canonical form using the dual concepts
of minterms and maxterms.
• Minterms are called products because they are the logical AND of a set of variables, and maxterms are
called sums because they are the logical OR of a set of variables.
• These concepts are called duals because of their complementary-symmetry relationship as expressed by
De Morgan's laws, which state that AND(x,y,z,...) = NOR(x',y',z',...) and OR(x,y,z,...) = NAND(x',y',z',...)
• The dual canonical forms of any Boolean function are a "sum of minterms" and a "product of maxterms."
• The term "Sum of Products" or "SoP" is widely used for the canonical form that is a disjunction (OR) of
minterms.
• Its De Morgan dual is a "Product of Sums" or "PoS" for the canonical form that is a conjunction (AND)
of maxterms.
Minterms
For a boolean function of variables , a product term in which each of the variables appears
once (in either its complemented or uncomplemented form) is called a minterm. Thus, a minterm is a logical
expression of n variables that employs only the complement operator and the conjunction operator.
For example, , and are 3 examples of the 8 minterms for a Boolean function of the three variables
, and . The customary reading of the last of these is a AND b AND NOT-c.
There are 2n minterms of n variables, since a variable in the minterm expression can be in either its direct or its
complemented form—two choices per n variables.
Indexing minterms
In general, one assigns each minterm an index based on a conventional binary encoding of the complementation
pattern of the variables (where the variables in all the minterms are written in the same order, usually
alphabetical). This convention assigns the value 1 to the direct form ( ) and 0 to the complemented form ( ).
For example, we assign the index 6 to the minterm (110) and denote that minterm as . Similarly, of
the same three variables is (000), and is (111).
Functional equivalence
If one is given a truth table of a logical function, it is possible to write the function as a "sum of products". This is
a special form of disjunctive normal form. For example, if given the truth table for the arithmetic sum bit u of
one bit position's logic of an adder circuit, as a function of x and y from the addends and the carry in, ci:
ci x y u(ci,x,y)
0 0 0 0
0 0 1 1
0 1 0 1
0 1 1 0
1 0 0 1
1 0 1 0
1 1 0 0
1 1 1 1
Observing that the rows that have an output of 1 are the 2nd, 3rd, 5th, and 8th, we can write u as a sum of
minterms and . If we wish to verify this: u(ci, x, y) = = (ci' x' y) +
(ci' x y') + (ci x' y') + (ci x y) evaluated for all 8 combinations of the three variables will match the table.
Maxterms
For a boolean function of variables , a sum term in which each of the variables appears once
(in either its complemented or uncomplemented form) is called a maxterm. Thus, a maxterm is a logical
expression of n variables that employs only the complement operator and the disjunction operator. Maxterms
are a dual of the minterm idea (i.e., exhibiting a complementary symmetry in all respects). Instead of using
ANDs and complements, we use ORs and complements and proceed similarly.
For example, the following are two of the eight maxterms of three variables:
a+b'+c a'+b+c
There are again 2n maxterms of n variables, since a variable in the maxterm expression can also be in either its
direct or its complemented form—two choices per n variables.
Indexing maxterms
Each maxterm is assigned an index based on the opposite conventional binary encoding used for minterms. The
maxterm convention assigns the value 0 to the direct form and 1 to the complemented form . For
example, we assign the index 6 to the maxterm (110) and denote that maxterm as M6. Similarly M0
of these three variables is (000) and M7 is (111).
Functional equivalence
It is apparent that maxterm n gives a false value (i.e., 0) for just one combination of the input variables. For
example, maxterm 5, a' + b + c', is false only when a and c both are true and b is false—the input arrangement
where a = 1, b = 0, c = 1 results in 0.
If one is given a truth table of a logical function, it is possible to write the function as a "product of sums". This is
a special form of conjunctive normal form. For example, if given the truth table for the carry-out bit co of one bit
position's logic of an adder circuit, as a function of x and y from the addends and the carry in, ci:
Dualization
The complement of a minterm is the respective maxterm. This can be easily verified by using de Morgan's law.
For example:
Example: Obtain the truth table for a combinational circuit that accepts a three bit ‘number and generates an
output binary number equal to the square of the input number.
Ans. Truth table is as shown for inputs and the corresponding square outputs.
Minimization Technique
• Based on the Unifying Theorem: X + X' = 1
• The expression to be minimized should generally be in sum-of-product form (If necessary, the
conversion process is applied to create the sum-of-product form).
• The function is mapped onto the K-map by marking a 1 in those squares corresponding to the terms in
the expression to be simplified (The other squares may be filled with 0's).
• Pairs of 1's on the map which are adjacent are combined using the theorem Y(X+X') = Y where Y is any
Boolean expression
• The minimization procedure consists of recognizing those pairs and multiple pairs.
o These are circled indicating reduced terms.
o Groups which can be circled are those which have two (21) 1's, four (22) 1's, eight (23) 1's, and
so on.
o Note that because squares on one edge of the map are considered adjacent to those on the
opposite edge, group can be formed with these squares.
o Groups are allowed to overlap.
• The objective is to cover all the 1's on the map in the fewest number of groups and to create the largest
groups to do this.
• Once all possible groups have been formed, the corresponding terms are identified.
o A group of two 1's eliminates one variable from the original minterm.
o A group of four 1's eliminates two variables from the original minterm.
o A group of eight 1's eliminates three variables from the original minterm, and so on.
o The variables eliminated are those which are different in the original minterms of the group.
• In any K-Map, each square represents a minterm. Adjacent squares always differ by just one literal (So
that the unifying theorem may apply: X + X' = 1).
• For the 2-variable case (e.g.: variables X, Y), the map can be drawn as below. Two variable map is the
one which has got only two variables as input.
The diagram below illustrates the correspondence between the Karnaugh map and the truth table for the
general case of a two variable problem.
The values inside the squares are copied from the output column of the truth table, therefore there is one
square in the map for every row in the truth table. Around the edge of the Karnaugh map are the values of the
two input variable. A is along the top and B is down the left hand side. The diagram below explains this:
The values around the edge of the map can be thought of as coordinates. So as an example, the square on the top
right hand corner of the map in the above diagram has coordinates A=1 and B=0. This square corresponds to
the row in the truth table where A=1 and B=0 and F=1. Note that the value in the F column represents a
particular function to which the Karnaugh map corresponds.
Example
X'Y+XY F= X'Y+XY+XY'
F=Y F=X+Y
• There are 8 minterms for 3 variables (X, Y, Z). Therefore, there are 8 cells in a 3-variable K-map.
• One important thing to note is that K-maps follow the gray code sequence, not the binary one.
• Using gray code arrangement ensures that minterms of adjacent cells differ by only ONE literal.
• Each cell in a 3-variable K-map has 3 adjacent neighbors. In general, each cell in an n-variable K-map
has n adjacent neighbors.
Example
F = XYZ'+XYZ+X'YZ F(X,Y,Z) = (1,3,4,5,6,7)
F = XY + YZ
There are 16 cells in a 4-variable (W, X, Y, Z); K-map as shown in the figure below.
There are 2 wrap-around: a horizontal wrap-around and a vertical wrap-around. Every cell thus has 4
neighbours. For example, the cell corresponding to minterm m0 has neighbours m1, m2, m4 and m8.
Example
F(W,X,Y,Z) = (1,5,12,13) F(W,X,Y,Z) = (4, 5, 10, 11, 14, 15)
There are 32 cells in a 5-variable (V, W, X, Y, Z); K-map as shown in the figure below.
Inverse Function
• The 0's on a K-map indicate when the function is 0.
• We can minimize the inverse function by grouping the 0's (and any suitable don't cares) instead of the 1's.
• This technique leads to an expression which is not logically equivalent to that obtained by grouping the
1's (i.e., the inverse of X != X').
• Minimizing for the inverse function may be particularly advantageous if there are many more 0's than 1's
on the map.
• We can also apply De Morgan's theorem to obtain a product-of-sum expression.
Example: Reduce the following expression to minimum cost SOP and write the corresponding VHDL code.
f(a, b, c, d) = ∑ m (5, 6, 9, 10, 12, 13, 14, 15) + d(2, 4)
Solution.
cd 00 01 11 10
ab
00 x
01 x 1 1
11 1 1 1 1
10 1 1
F = b. c’ + c . d + a . b + a . c’. d
VHDL code:
library ieee;
use ieee.std_logic_1164.all;
entity FN is
port (a, b, c, d :in STD_LOGIC_VECTOR(15 DOWNTO 0);
f :out STD_LOGIC_VECTOR(15 DOWNTO 0);
end FN;
architecture FN_ARC of FN is
begin
f<= (b and not c) or ( c and d) or ( a and b) or( a and not c and d);
end FN_ARC;
Advantages
• The key advantage of VHDL, when used for systems design, is that it allows the behavior of the required
system to be described (modeled) and verified (simulated) before synthesis tools translate the design
into real hardware (gates and wires).
• Another benefit is that VHDL allows the description of a concurrent system. VHDL is a dataflow
language, unlike procedural computing languages such as BASIC, C, and assembly code, which all run
sequentially, one instruction at a time.
• VHDL project is multipurpose. Being created once, a calculation block can be used in many other
projects. However, many formational and functional block parameters can be tuned (capacity
parameters, memory size, element base, block composition and interconnection structure).
Building block
Figure: A VHDL entity consisting of an interface (entity declaration) and a body (architectural description).
a. Entity Declaration
The entity declaration defines the NAME of the entity and lists the input and output ports. The general form
is as follows,
entity NAME_OF_ENTITY is [ generic generic_declarations);]
port (signal_names: mode type;
signal_names: mode type;
:
signal_names: mode type);
end [NAME_OF_ENTITY] ;
An entity always starts with the keyword entity, followed by its name and the keyword is. Next are the
port declarations using the keyword port. An entity declaration always ends with the keyword end,
optionally [] followed by the name of the entity.
Example:
entity BUZZER is
port (DOOR, IGNITION, SBELT: in std_logic;
WARNING: out std_logic);
end BUZZER;
a. Architecture body
The architecture body specifies how the circuit operates and how it is implemented. An entity or circuit can be
specified in a variety of ways, such as behavioral, structural (interconnected components), or a combination of
the above.
The architecture body looks as follows,
architecture architecture_name of NAME_OF_ENTITY is
-- Declarations
-- components declarations
-- signal declarations
-- constant declarations
-- function declarations
-- procedure declarations
-- type declarations
:
begin
-- Statements
:
end architecture_name;
Behavioral model
The header line of the architecture body defines the architecture name, e.g. behavioral, and associates it with
the entity, BUZZER. The architecture name can be any legal identifier. The main body of the architecture starts
with the keyword begin and gives the Boolean expression of the function.
The “<= ” symbol represents an assignment operator and assigns the value of the expression on the right to the
signal on the left. The architecture body ends with an end keyword followed by the architecture name.
A few other examples follow. The behavioral description of a two-input AND gate is shown below.
entity AND2 is
port (in1, in2: in std_logic;
Concurrency
It is worth pointing out that the signal assignments in the above examples are concurrent statements. This
implies that the statements are executed when one or more of the signals on the right hand side change their
value (i.e. an event occurs on one of the signals).
For instance, when the input A changes, the internal signals X and Y change values that in turn causes the last
statement to update the output Z. There may be a propagation delay associated with this change.
Digital systems are basically data-driven and an event which occurs on one signal will lead to an event on
another signal, etc. The execution of the statements is determined by the flow of signal values. As a result, the
order in which these statements are given does not matter (i.e., moving the statement for the output Z ahead of
that for X and Y does not change the outcome). This is in contrast to conventional, software programs that
execute the statements in a sequential or procedural manner.
end structural;
Following the header is the declarative part that gives the components (gates) that are going to be used in the
description of the circuits. In our example, we use a two- input AND gate, two-input OR gate and an inverter.
These gates have to be defined first, i.e. they will need an entity declaration and architecture body. These can be
stored in one of the packages one refers to in the header of the file. The declarations for the components give
the inputs (e.g. in1, in2) and the output (e.g. out1). Next, one has to define internal nets (signal names). In our
example these signals are called DOOR_NOT, SBELT_NOT, B1, B2.
The statements after the begin keyword gives the instantiations of the components and describes how these are
interconnected. A component instantiation statement creates a new level of hierarchy. Each line starts with an
instance name (e.g. U0) followed by a colon and a component name and the keyword port map. This keyword
defines how the components are connected. In the example above, this is done through positional association:
DOOR corresponds to the input, in1 of the NOT1 gate and DOOR_NOT to the output. Similarly, for the AND2 gate
where the first two signals (IGNITION and DOOR_NOT) correspond to the inputs in1 and in2, respectively, and
the signal B1 to the output out1. An alternative way is to use explicit association between the ports, as shown
below.
U0: NOT1 port map (in1 => DOOR, out1 => DOOR_NOT);
U1: NOT1 port map (in1 => SBELT, out1 => SBELT_NOT);
U2: AND2 port map (in1 => IGNITION, in2 => DOOR_NOT, out1 => B1);
U3: AND2 port map (in1 => IGNITION, in2 => SBELT_NOT, B2);
U4: OR2 port map (in1 => B1, in2 => B2, out1 => WARNING);
In the world of digital electronic systems, there are three basic kinds of devices: memory,
microprocessors, and logic. Memory devices store random information such as the contents of a spreadsheet or
database. Microprocessors execute software instructions to perform a wide variety of tasks such as running a
word processing program or video game. Logic devices provide specific functions, including device-to-device
interfacing, data communication, signal processing, data display, timing and control operations, and almost
every other function a system must perform.
• Also, each chip contains only a few logic gates, which makes them inefficient for building large circuits.
• Programmable Logic Devices (PLDs) contain a relatively large amount of logic circuitry with a structure
that is not fixed.
• It can be considered as a "black box“ that contains logic gates and programmable switches which allow
the gates inside the device to be connected together to implement a specific logic circuit.
• Like the classification of standard chips (LSI, MSI, etc.) there are number of different classifications for
PLDS depending on their internal structures.
Logic devices can be classified into two broad categories - fixed and programmable. As the name
suggests, the circuits in a fixed logic device are permanent, they perform one function or set of functions - once
manufactured, they cannot be changed. On the other hand, programmable logic devices (PLDs) are standard,
off-the-shelf parts that offer customers a wide range of logic capacity, features, speed, and voltage
characteristics - and these devices can be changed at any time to perform any number of functions.
With programmable logic devices, designers use inexpensive software tools to quickly develop,
simulate, and test their designs. Then, a design can be quickly programmed into a device, and immediately
tested in a live circuit. The PLD that is used for this prototyping is the exact same PLD that will be used in the
final production of a piece of end equipment, such as a network router, a DSL modem, a DVD player, or an
automotive navigation system.
Another key benefit of using PLDs is that during the design phase customers can change the circuitry as
often as they want until the design operates to their satisfaction. That's because PLDs are based on re-writable
memory technology - to change the design, the device is simply reprogrammed. Once the design is final,
customers can go into immediate production by simply programming as many PLDs as they need with the final
software design file.
The mask-programmable types are programmed when they are manufactured whereas the user sets up
the field-programmable device with some form of programmer. Mask-programmable devices are expensive in
low production runs but are relatively cheap for large production runs, which is opposite for the field-
programmable devices. An erasable device allows the stored set-up to be changed whereas the non-erasable
type is permanent.
A programmable logic array (PLA) is a kind of programmable logic device used to implement combinational
logic circuits. The PLA has a set of programmable AND gate planes, which link to a set of programmable OR gate
planes, which can then be conditionally complemented to produce an output. This layout allows for a large
number of logic functions to be synthesized in the sum of products (and sometimes product of sums) canonical
forms.
The first developed PLD was the programmable logic array (PLA). Based on the idea that logic functions can be
realized in sum-of products form, a PLA comprises a collection of AND gates that feeds a set of OR gates.
In commercially available PLAs, several methods of realizing the programmable connections exist.
• Programming the PLA involves blowing the fuses along the paths that must be removed in order to obtain the
desired logic function.
• Like the classification of standard chips (LSI, MSI, etc.) there are number of different classifications for PLDS
depending on their internal structures.
• The following figure shows a PLA with 3 inputs, four product terms, and two outputs.
• A signal connected to a gate is indicated by an X at the crossing of a vertical and horizontal line.
• Circuits implemented using PLAs and PALs are limited to fairly modest sizes, typically the total number of
inputs and outputs is less than 32.
• For circuits requiring more inputs and/or outputs, either multiple PLAs or PALs are used or a more
sophisticated type of chip, called a Complex Programmable Device (CPLD), can be employed.
• CPLD can be used to implement designs which would require up to 20,000 individual gates.
FPGAs contain programmable logic components called "logic blocks", and a hierarchy of reconfigurable
interconnects that allow the blocks to be "wired together"—somewhat like many (changeable) logic gates that
can be inter-wired in (many) different configurations. Logic blocks can be configured to perform complex
combinational functions, or merely simple logic gates like AND and XOR. In most FPGAs, the logic blocks also
include memory elements, which may be simple flip-flops or more complete blocks of memory.
For circuits which require an even larger numberof individual gates (>20,000), FPGA technology issued.
• An FPGA is a programmable device that supports the implementation of relatively large logic circuits.
• Rather than AND and OR planes, it provides logic blocks for implementing the required functions.
• The logic blocks are arranged in a two-dimensional array and the interconnection wires are organized as
horizontal and vertical routing channels between the rows and columns of blocks.
• The channels contain programmable switches that allow the logic blocks to be interconnected.
• For circuits requiring more inputs and/or outputs, either multiple PLAs or PALs are used or a more
sophisticated type of chip, called a Complex Programmable Device (CPLD), can be employed.
• FPGAs can be used to implement logic circuits which would require more than a hundred thousand equivalent
gates.
• Two examples of FPGAs are the Altera FLEX 10K and the Xilinx XC4000.
• Each logic block within the FPGA typically has a small number of inputs and one output.
• The most commonly used logic block is a lookup table (LUT)which contains storage (memory) cells that are
used to implement a small logic function.
The two major types of programmable logic devices are field programmable gate arrays (FPGAs) and complex
programmable logic devices (CPLDs). Of the two, FPGAs offer the highest amount of logic density, the most
features, and the highest performance. CPLDs, by contrast, offer much smaller amounts of logic - up to about
10,000 gates. But CPLDs offer very predictable timing characteristics and are therefore ideal for critical control
applications. FPGAs and CPLDs are both programmable logic. However the main difference lies in the
architecture of the chips.
CPLDs have several programmable PLDs which are interconnected via a programmable connections at the
global interconnection matrix.
Compare the FPGA way of programming individual AND, OR, NOT logic functions and then putting them
together to implement a complete logic function, to the CPLD way of programming several complete logic
functions at once on inividual PLDs and then bringing these PLDs together via programmable connections.
Combinational logic
In digital circuit theory, combinational logic (sometimes also referred to as combinatorial logic) is a type of
digital logic which is implemented by boolean circuits, where the output is a pure function of the present input
only. This is in contrast to sequential logic, in which the output depends not only on the present input but also
on the history of the input. In other words, sequential logic has memory while combinational logic does not.
Combinational logic is used in computer circuits to do boolean algebra on input signals and on stored data.
Practical computer circuits normally contain a mixture of combinational and sequential logic. For example, the
part of an arithmetic logic unit, or ALU, that does mathematical calculations is constructed using combinational
logic. Other circuits used in computers, such as half adders, full adders, half subtractors, full subtractors,
multiplexers, demultiplexers, encoders and decoders are also made by using combinational logic.
The single bits are added together and "0 + 0", "0 + 1", or "1 + 0" results in a sum of "0" or "1" until you get to "1
+ 1" then the sum is equal to "2". For a simple 1-bit addition problem like this, the resulting carry bit could be
ignored which would result in an output truth table resembling that of an Ex-OR Gate as seen in the Logic Gates
section and whose result is the sum of the two bits but without the carry.
An Ex-OR gate only produces an output "1" when either input is at logic "1", but not both. However, all
microprocessors and electronic calculators require the carry bit to correctly calculate the equations so we need
to rewrite them to include 2 bits of output data as shown below.
From the above equations we know that an Ex-OR gate will only produce an output "1" when "EITHER" input is
at logic "1", so we need an additional output to produce a carry output, "1" when "BOTH" inputs "A" and "B" are
at logic "1" and a standard AND Gate fits the bill nicely. By combining the Ex-OR gate with the AND gate results
in a simple digital binary adder circuit known commonly as the "Half Adder" circuit.
S (X,Y) = (1,2)
S = X'Y + XY'
S = X⊕Y
CARRY(X,Y) = (3)
CARRY = XY
From the truth table we can see that the SUM (S) output is the result of the Ex-OR gate and the Carry-out (Cout)
is the result of the AND gate.
One major disadvantage of the Half Adder circuit when used as a binary adder, is that there is no provision for a
"Carry-in" from the previous circuit when adding together multiple data bits. For example, suppose we want to
add together two 8-bit bytes of data, any resulting carry bit would need to be able to "ripple" or move across the
bit patterns starting from the least significant bit (LSB). The most complicated operation the half adder can do is
"1 + 1" but as the half adder has no carry input the resultant added value would be incorrect. One simple way to
overcome this problem is to use a Full Adder type binary adder circuit.
library ieee;
use ieee.std_logic_1164.all;
entity bejoy_ha is
port (a, b : in bit ;
s, c : out bit);
end bejoy_ha;
The 1-bit Full Adder circuit above is basically two half adders connected together and consists of three Ex-OR
gates, two AND gates and an OR gate, six logic gates in total. The truth table for the full adder includes an
additional column to take into account the Carry-in input as well as the summed output and carry-output. But
what if we wanted to add together two n-bit numbers, then n 1-bit full adders need to be connected together to
produce what is known as the Ripple Carry Adder.
Kmap-SUM Kmap-CARRY
SUM = X Y Z
A full adder can be implemented in many different ways such as with a custom transistor-level circuit or
composed of other gates. One example implementation is with and
.
In this implementation, the final OR gate before the carry-out output may be replaced by an XOR gate without
altering the resulting logic. Using only two types of gates is convenient if the circuit is being implemented using
simple IC chips which contain only one gate type per chip. In this light, Cout can be implemented as
.
LIBRARY ieee ;
USE ieee.std_logic_1164.all ;
ENTITY fulladd IS
PORT ( Cin, x, y : IN STD_LOGIC ;
s, Cout : OUT STD_LOGIC ) ;
END fulladd ;
The half-subtractor is a combinational circuit which is used to perform subtraction of two bits. It has two inputs,
X (minuend) and Y (subtrahend) and two outputs D (difference) and B (borrow).
Truth table
X Y D B
0 0 0 0
0 1 1 1
1 0 1 0
1 1 0 0
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
entity hs1 is
Port ( a : in STD_LOGIC;
b : in STD_LOGIC;
diff : out STD_LOGIC;
borrow : out STD_LOGIC);
end hs1;
The full-subtractor is a combinational circuit which is used to perform subtraction of three bits. It has three
inputs, X (minuend) and Y (subtrahend) and Z (subtrahend) and two outputs D (difference) and B (borrow).
B = 1 If X<(Y+Z)
Symbol
Truth table
From the above expression, we can draw the circuit below. If you look carefully, you will see that a full-
subtractor circuit is more or less same as a full-adder with slight modification.
library ieee;
use ieee.std_logic_1164.all;
entity bejoy_fs is
port(x,y,bi: in bit; b2,do,bo: out bit; d,b: inout bit);
end bejoy_fs;
Multiple full adder circuits can be cascaded in parallel to add an N-bit number. For an N- bit parallel adder, there
must be N number of full adder circuits. A ripple carry adder is a logic circuit in which the carry-out of each full
adder is the carry in of the succeeding next most significant full adder. It is called a ripple carry adder because
each carry bit gets rippled into the next stage. In a ripple carry adder the sum and carry out bits of any half
adder stage is not valid until the carry in of that stage occurs. Propagation delays inside the logic circuitry is the
reason behind this. Propagation delay is time elapsed between the application of an input and occurrence of the
corresponding output. Consider a NOT gate, When the input is “0″ the output will be “1″ and vice versa. The
time taken for the NOT gate’s output to become “0″ after the application of logic “1″ to the NOT gate’s input is
the propagation delay here. Similarly the carry propagation delay is the time elapsed between the application of
the carry in signal and the occurance of the carry out (Cout) signal. Circuit diagram of a 4-bit ripple carry adder
is shown below.
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
entity adder1 is
port( num1 : in std_logic_vector(3 downto 0);
num2 : in std_logic_vector(3 downto 0);
sum : out std_logic_vector(3 downto 0);
carry : out std_logic );
end adder1;
--architecture of entity
architecture Behavioral of adder1 is
end Behavioral;
library ieee;
use ieee.std_logic_1164.all;
-- 4-bit adder
library ieee;
use ieee.std_logic_1164.all;
entity FOURBITADD is
port (a, b: in std_logic_vector(3 downto 0);
Cin : in std_logic;
sum: out std_logic_vector (3 downto 0);
Cout, V: out std_logic);
end FOURBITADD;
The Boolean expression for this 4-to-1 Multiplexer above with inputs A to D and data select lines a, b is given
as:
Cascading Muxes
Using 2-to-1 Muxes to build a 4-to-1 Mux A 16-to-1 16 to Mux/Selector
C)Example:
F(A,B,C) = m0 + m2 + m6 + m7
= A' B' C' + A' B C' + A B C' + A B C
= A' B' (C') + A' B (C') + A B' (0) + A B (1)
f = w1’w2w3+w1w2’w3+w1w2’w3+w1w2w3
= w1’(w2w3)+w1(w2’w3+w2w3’+w2w3)
= w1’(w2w3)+w1(w2+w3)
For 30: 1 MUX, 5 select lines are required. 4 select lines are for 16 : 1 MUX’s and 1 select line for 2: 1 MUX. =
M formula is used. Where n = number of select lines and M are the number of inputs for a MUX.
2/4 DELD, IT DEPT, M. V. S. R. E. C Faculty: S Ch Vijaya Bhaskar Page 63
= 32.Thus, 5 select lines are needed.
F(A,B,C,D) = S(1,3,4,11,12,13,14,15)
2. The first n – 1 variables in the table are applied to the selection inputs of the multiplexer.
3. For each combination of the selection variables, we evaluate the output as a function of the last variable.
Library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_arith.all;
entity 4x1mux1 is
port(a, b, c, d : in std_logic;
s0, s1 : in std_logic;
q : out std_logic);
end 4x1mux1;
Ma i n p r o gr a m:
Library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_arith.all;
entity 16x1mux is
port(a: in std_logic_vector(15 downto 0);
s: in std_logic_vector(3 downto 0);
Z: o u t s t d _ lo gic ) ;
E n d 1 6x 1 mu x ;
A rc h it e c tu re 1 6 x1 m ux1 o f 1 6x 1 m ux is
s ign a l z 1 , z 2 , z 3 , z 4 : s t d_ l o gic ;
component kanhe_4x1mux is
port(a,b,c,d,s0,s1:in std_logic;
Q:out std_logic);
E n d c o m po n e n t ;
Begin
M 1 : kanhe_4x1mux p o rt m a p ( a (0 ) , a (1 ) , a( 2 ) , a(3 ) , s (0 ) , s( 1 ) , z1 ) ;
m 2 : kanhe_4x1mux po rt m a p ( a (4 ) , a (5 ) , a( 6 ) , a(7 ) , s (0 ) , s( 1 ) , z2 ) ;
m 3 : kanhe_4x1mux po rt m a p ( a (8 ) , a (9 ) , a( 1 0) , a( 1 1) , s (0 ) , s (1 ) , z3 ) ;
m 4 : kanhe_4x1mux po rt m a p ( a (1 2 ) , a( 13 ) , a (1 4) , a ( 15 ) , s( 0 ) , s( 1) , z 4 ) ;
m 5 : kanhe_4x1mux po rt m a p ( z 1 , z 2 , z3 , z 4 , s( 2 ) ,s ( 3 ) , z) ;
E n d 1 6x 1 mu x 1 ;
The Boolean expression for this 1-to-4 Demultiplexer above with outputs A to D and data select lines a, b is
given as: F = ab A + abB + abC + abD
The function of the Demultiplexer is to switch one common data input line to any one of the 4 output data lines
A to D in our example above. As with the multiplexer the individual solid state switches are selected by the
binary input address code on the output select pins "a" and "b" and by adding more address line inputs it is
possible to switch more outputs giving a 1-to-2n data line outputs.
Decoders
One logic block that we will use in building larger components is a decoder. The most common type of decoder
has an n-bit input and 2n outputs, where only one output is asserted for each input combination. This decoder
translates the n-bit input into a signal that corresponds to the binary value of the n-bit input. The outputs are
thus usually numbered, say, Out0, Out1, . . . , Out2n– 1. If the value of the input is i, then Outi will be true and all
other outputs will be false.
A binary decoder converts coded inputs into coded outputs, where the input and output codes are different and
decoders are available to "decode" either a Binary or BCD (8421 code) input pattern to typically a Decimal
output code.
The decoder is enabled when E = 0. The output whose value = 0 represents the minterm is selected by inputs A
and B.
A Decoder with enable input is called a decoder/demultiplexer. Demultiplexer receives information from a
single line and directs it to the output lines.
ENTITY dec2to4 IS
PORT ( w : IN STD_LOGIC_VECTOR(1 DOWNTO 0) ;
En : IN STD_LOGIC ;
y : OUT STD_LOGIC_VECTOR(0 TO 3) ) ;
END dec2to4 ;
In this simple example of a 2-to-4 line binary decoder, the binary inputs A and B determine which output line
from D0 to D3 is "HIGH" at logic level "1" while the remaining outputs are held "LOW" at logic "0" so only one
output can be active (HIGH) at any one time. Therefore, whichever output line is "HIGH" identifies the binary
code present at the input, in other words it "de-codes" the binary input and these types of binary decoders are
commonly used as Address Decoders in microprocessor memory applications
Solution.
One of the main disadvantages of standard digital encoders is that they can generate the wrong output code
when there is more than one input present at logic level "1". For example, if we make inputs D1 and D2 HIGH at
logic "1" at the same time, the resulting output is neither at "01" or at "10" but will be at "11" which is an output
binary number that is different to the actual input present. Also, an output code of all logic "0"s can be
generated when all of its inputs are at "0" OR when input D0 is equal to one.
One simple way to overcome this problem is to "Prioritise" the level of each input pin and if there was more
than one input at logic level "1" the actual output code would only correspond to the input with the highest
designated priority. Then this type of digital encoder is known commonly as a Priority Encoder or P-encoder
for short.
Priority Encoders
Priority Encoders solve the problem mentioned above by allocating a priority level to each input. The encoder
output corresponds to the currently active input with the highest priority. So when an input with a higher
priority is present, all other inputs with a lower priority will be ignored. Priority encoders come in many forms
with an example of an 8-input priority encoder along with its truth table shown below.
Solution. Priority encoder in a special type of encoder. It has priorities given to the input lines from highest
priority input line to lowest priority input line, If two or more input lines are active i.e. ‘1’ or high at the same
time, then the input line with highest priority will be considered first
The Boolean expression for this 8-to-3 encoder above with inputs D0 to D7 and outputs Q0, Q1, Q2 is given as:
Q0 = D1 + D3 + D5 + D7
Q1 = D2 + D3 + D6 + D7
Q2 = D4 + D5 + D6 + D7
Then the implementation of these Boolean expression outputs above using individual OR gates is as follows.
ENTITY compare IS
PORT ( A, B : IN SIGNED(3 DOWNTO 0) ;
AeqB, AgtB, AltB : OUT STD_LOGIC ) ;
END compare ;
LIBRARY IEEE;
USE IEEE.STD_LOGIC_1164.ALL;
ENTITY comp4 IS
PORT(A,B:IN BIT_VECTOR(3 DOWNTO 0);
F1,F2,F3:OUT BIT);
END comp4;
Gray code is a type of unit distance code. In unit distance code the bit patterns for two consecutive numbers will
differ in one bit position. We can also say it as Cyclic codes.
1. Most significant bit (B1) is same as the most significant bit in Gray Code (B1 = G1)
2. To find next bit perform Ex-OR (Exclusive OR) between the Current binary bit and previous bit.
Gn = Bn (Ex-OR) Bn-1
3. Look the below Image for Binary to Gray code Conversion
1. Most significant bit (G1) is same as the most significant bit in Binary Code (G1 = B1)
2. The next number can be obtain by taking Exclusive OR operation between the previous binary bit, and
the current gray code bit and write down the value.
Repeat the Above Step until you find Bn
Library ieee;
use ieee.std_logic_1164.all;
MAIN program
library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_unsigned.all;
entity kanhe_g_to_bi is
port(b:in std_logic_vector(3 downto 0);
g:out std_logic_vector(3 downto 0));
end kanhe_g_to bi;
The input variables are BCD’s (A, B, C and D) and output variables are excess-3 code (E3, E2, E1 and E0)
Truth Table
After ‘9’ i.e. 1001 BCD, mark don’t care i.e. ‘X’.
E3 = A + BD + BS
For E2 ◊
For E0 ◊
For E1 ◊
Circuit Diagram:
Digital electronics is classified into combinational logic and sequential logic. Combinational logic output depends
on the inputs levels, whereas sequential logic output depends on previous outputs (on stored levels) and also the
input levels. Combinational circuits are fast as compared to sequential circuits since the combinational circuits
do not have any memory elements.
The memory elements are devices capable of storing binary info. The binary info stored in the memory elements
at any given time defines the state of the sequential circuit. The input and the present state of the memory
element determine the output. Memory elements next state is also a function of external inputs and present
state. A sequential circuit is specified by a time sequence of inputs, outputs, and internal states.
There are two types of sequential circuits. Their classification depends on the timing of their signals:
Gate-type asynchronous systems are basically combinational circuits with feedback paths. Because of the
feedback among logic gates, the system may, at times, become unstable. Consequently they are not often used.
This type of system uses storage elements called flip-flops that are employed to change their binary value only at
discrete instants of time. Synchronous sequential circuits use logic gates and flip-flop storage devices. Sequential
circuits have a clock signal as one of their inputs. All state transitions in such circuits occur only when the clock
value is either 0 or 1 or happen at the rising or falling edges of the clock depending on the type of memory
elements used in the circuit. Synchronization is achieved by a timing device called a clock pulse generator. Clock
pulses are distributed throughout the system in such a way that the flip-flops are affected only with the arrival of
the synchronization pulse. Synchronous sequential circuits that use clock pulses in the inputs are called clocked-
sequential circuits. They are stable and their timing can easily be broken down into independent discrete steps,
each of which is considered separately.
A clock signal is a periodic square wave that indefinitely switches from 0 to 1 and from 1 to 0 at fixed intervals.
Clock cycle time or clock period: the time interval between two consecutive rising or falling edges of the
clock.
Clock Frequency = 1 / clock cycle time (measured in cycles per second or Hz)
Example:
Clock cycle time = 10ns clock frequency = 100M
A sequential circuit is combinational logic with some feedback to maintain its current value, like a memory cell.
To understand the basics let's consider the basic feedback logic circuit below Figure 4, which is a simple NOT
gate whose output is connected to its input. The effect is that output oscillates between HIGH and LOW (i.e. 1 and
0). Oscillation frequency depends on gate delay and wire delay. Assuming a wire delay of 0 and a gate delay of
10ns, then oscillation frequency would be (on time + off time = 20ns) 50 MHz.
Level Sensitive: The circuit below is a modification of the above one to have level sensitive enable input. Enable,
when LOW, masks the input S and R. When HIGH, presents S and R to the sequential logic input . Thus Enable,
when HIGH, transfers input S and R to the sequential cell transparently, so this kind of sequential circuits are
called transparent Latch. The memory element we get is an RS Latch with active high Enable.
An RS Latch
Edge Sensitive: The circuit below is a cascade of two level sensitive memory elements, with a phase shift in the
enable input between first memory element and second memory element. The first RS latch (i.e. the first
memory element) will be enabled when CLK input is HIGH and the second RS latch will be enabled when CLK is
LOW. The net effect is input RS is moved to Q and Q' when CLK changes state from HIGH to LOW, this HIGH to
LOW transition is called falling edge. So the Edge Sensitive element we get is called negative edge RS flip-flop.
: An RS Flip-flop
Latches are designed to be transparent. That is, input signal changes cause immediate changes in output.
Alternatively, additional logic can be added to a simple transparent latch to make it non-transparent or
opaque when another input (e.g., an "enable" input) is not asserted. In digital circuits, a flip-flop is a term
referring to an electronic circuit that has two stable states and thereby is capable of serving as one bit of
computer storage.... can be implemented.
It includes:
1. Gated SR latch
2. Gated D-latch
S-R Latch
RS latch have two inputs, S and R. S is called set and R is called reset. The S input is used to produce HIGH on Q (
i.e. store binary 1 in flip-flop). The R input is used to produce LOW on Q (i.e. store binary 0 in flip-flop). Q' is Q
complementary output, so it always holds the opposite value of Q. The output of the S-R latch depends on current
as well as previous inputs or state, and its state (value stored) can change as soon as its inputs change. The
circuit and the truth table of RS latch are shown below.
S R Q Q+
0 0 0 0
0 0 1 1
0 1 X 0
1 0 X 1
1 1 X 0
An S-R Latch
The operation has to be analyzed with the 4 inputs combinations together with the 2 possible previous states.
• When S = 0 and R = 0: If we assume Q = 1 and Q' = 0 as initial condition, then output Q after input is
applied would be Q = (R + Q')' = 1 and Q' = (S + Q)' = 0. Assuming Q = 0 and Q' = 1 as initial condition,
then output Q after the input applied would be Q = (R + Q')' = 0 and Q' = (S + Q)' = 1. So when both S and
R inputs are LOW, the output is retained as before the application of inputs. (i.e. there is no state
change).
• When S = 1 and R = 0: If we assume Q = 1 and Q' = 0 as initial condition, then output Q after input is
applied would be Q = (R + Q')' = 1 and Q' = (S + Q)' = 0. Assuming Q = 0 and Q' = 1 as initial condition,
then output Q after the input applied would be Q = (R + Q')' = 1 and Q' = (S + Q)' = 0. So in simple words
when S is HIGH and R is LOW, output Q is HIGH.
• When S = 0 and R = 1: If we assume Q = 1 and Q' = 0 as initial condition, then output Q after input is
applied would be Q = (R + Q')' = 0 and Q' = (S + Q)' = 1. Assuming Q = 0 and Q' = 1 as initial condition,
then output Q after the input applied would be Q = (R + Q')' = 0 and Q' = (S + Q)' = 1. So in simple words
when S is LOW and R is HIGH, output Q is LOW.
• When S = 1 and R =1 : No matter what state Q and Q' are in, application of 1 at input of NOR gate always
results in 0 at output of NOR gate, which results in both Q and Q' set to LOW (i.e. Q = Q'). LOW in both the
outputs basically is wrong, so this case is invalid.
The waveform in figure 7 shows the operation of NOR gates based RS Latch.
It is possible to construct the RS latch using NAND gates. The only difference is that NAND is NOR gate dual form.
So in this case the R = 0 and S = 0 case becomes the invalid case (NOR based latch inputs are normally 0 and must
be pulsed to the 1 stat 9active HIGH) to change the state of the latch outputs. The circuit and Truth table of RS
latch using NAND is shown in figure 8. This latch is also called as S-R Latch. The NAND latch inputs are normally
1 and must be pulsed to 0 state (active low) to change the flip-flop output state.
S R Q Q+ Comments
1 1 0 0
No Change
1 1 1 1
0 1 X 0 Reset
1 0 X 1 Set
0 0 X 1 Invalid case
State Diagram
The circuit in figure 10 shows the level sensitive RS latch. Control signal "Enable" E is used to gate the input S
and R to the RS Latch. When Enable E is HIGH, both the AND gates act as buffers and thus R and S appears at the
RS latch input and it functions like a normal RS latch. When Enable E is LOW, it drives LOW to both inputs of RS
latch. As discussed, when both inputs of a NOR latch are low, values are retained (i.e. the output does not
change).
Figure 9 The graphical symbol for gated SR latch Figure 10: Gated SR latch with NOR and AND gates
The characteristic table for a gated SR latch which describes its behavior is as follows.
The outputs of NAND gates 1 & 2 stay at the logic 1 level as long as the clock input remains at 0. This 1 level at
the inputs of NAND based basic S R latch retains the present state i.e no change occurs. The S & R inputs control
the state of the latch in the same manner as for unclocked S-R flip-flop. However, the latch does not respond to
these inputs until the rising edge of the clock signal occurs. The clock pulse input acts as an enable signal for the
2 inputs.
Figure 12 shows an example timing diagram for gated SR latch (assuming negligible propagation delays through
the logic gates). Notice that during the last clock cycle when Clk = 1, both R = 1 and S = 1. So as Clk returns to 0,
the next state will be uncertain. This explains why we need to avoid the setting in the last row of the above
characteristic table in normal operation of a gated SR latch.
A common problem involving switches is the occurrence of contact bounce (caused by springiness of the
contacts):
A switch debouncer circuit and the corresponding waveforms are shown below:
The RS latch seen earlier contains ambiguous state; to eliminate this condition we can ensure that S and
R are never equal. This is done by connecting S and R together with an inverter. A D latch is like an S-R latch with
only one input: the "D" input. Activating the D input sets the circuit, and de-activating the D input resets the
circuit. Thus we have D Latch: the same as the RS latch, with the only difference that there is only one input,
instead of two (R and S). This input is called D or Data input. D latch is called D transparent latch or data latch, or
gated latch or Delay flip-flop or delay latch
The truth table shows that when the gate/enable input is 0, the D input has no effect on the output.
When E is high, the output equals D.
Figure 16: D latch using AND and NOR gates D = Data Input: E = Enable/clock: Q = Output: Q' = Inverse of Q
Below is the D latch waveform, which is similar to the RS latch one, but with R removed.
Figure 19 shows an example timing diagram for gated D latch (assuming negligible propagation delays
through the logic gates).
library ieee;
use ieee.std_logic_1164.all;
ENTITY D_latch IS
PORT( D, Clk : IN STD_LOGIC;
Q: OUT STD_LOGIC);
END D_latch;
END IF;
END PROCESS;
END behavioral;
The ambiguous state output in the RS latch was eliminated in the D latch by joining the inputs with an inverter.
But the D latch has a single input. JK latch is similar to RS latch in that it has 2 inputs J and K as shown figure 20.
The ambiguous state has been eliminated here: when both inputs are high, output toggles. The only difference
we see here is output feedback to inputs, which is not there in the RS latch.
J K Q
1 1 0
1 1 1
1 0 1
0 1 0
When the two inputs of JK latch are shorted, a T Latch is formed. It is called T latch as, when input is held HIGH,
output toggles.
T Q Q+
1 0 1
1 1 0
0 1 1
0 0 0
Flip-flops are synchronous bistable devices. The term synchronous means the output changes state only when
the clock input is triggered. That is, changes in the output occur in synchronization with the clock.
Flip-flop is a kind of multivibrator. There are three types of multivibrators:
1. Monostable multivibrator (also called one-shot) has only one stable state. It produces a single
pulse in response to a triggering input.
2. Bistable multivibrator exhibits two stable states. It is able to retain the two SET and RESET states
indefinitely. It is commonly used as a basic building block for counters, registers and memories.
In a bistable multivibrator, the condition of Q=1 and not-Q=0 is defined as set. A condition of Q=0 and
not-Q=1 is conversely defined as reset. If Q and not-Q happen to be forced to the same state (both 0 or
both 1), that state is referred to as invalid.
3. Astable multivibrator has no stable state at all. It is used primarily as an oscillator to generate
periodic pulse waveforms for timing purposes.
The bistable multivibrators are called flip-flops and are the basic memory devices used in sequential logic.
Other two-state devices include the astable multivibrator which serves as an oscillator and the monostable
multivibrator ("one-shot" multivibrator) which can serve as a pulse source.
• A race condition is a state in a sequential system where two mutually-exclusive events are
simultaneously initiated by a single cause.
Flip-Flop is a bi-stable element with inputs, which can change the state of the element. It has two types of
inputs:
1. Asynchronous inputs
Input change of sufficient magnitude and duration produces immediate change in the state of flip-flop
2. Synchronous inputs
Change in inputs does not immediately affect the state of the flip-flop. Inputs affect state only after a
control
The normal data inputs to a flip flop (D, S and R, or J and K) are referred to as synchronous inputs because they
have effect on the outputs (Q and not-Q) only in step, or in sync, with the clock signal transitions. These extra
inputs are called asynchronous because they can set or reset the flip-flop regardless of the status of the clock
signal. Typically, they're called preset and clear:
When the preset input is activated, the flip-flop will be set (Q=1, not-Q=0) regardless of any of the synchronous
inputs or the clock. When the clear input is activated, the flip-flop will be reset (Q=0, not-Q=1), regardless of any
of the synchronous inputs or the clock. What happens if both preset and clear inputs are activated? We get an
invalid state on the output, where Q and not-Q go to the same state, the same as the S-R latch!
Edge-Triggered Flip-flops
An edge-triggered flip-flop changes states either at the positive edge (rising edge) or at the negative
edge (falling edge) of the clock pulse on the control input. The three basic types are introduced here: S-R, J-K
and D.
The small triangle, called the dynamic input indicator, is used to identify an
edge-triggered flip-flop.
The three basic types of pulse-triggered flip-flops are S-R, J-K and D. Their logic symbols are shown in
figure 22. Notice that they do not have the dynamic input indicator at the clock input but have postponed
output symbols at the outputs.
A master-slave flip-flop is constructed from two separate flip-flops. One circuit serves as a master and
the other as a slave. The logic diagram of an SR flip-flop is shown in Figure 23. The master flip-flop is enabled on
the positive edge of the clock pulse CP and the slave flip-flop is disabled by the inverter. The information at the
external R and S inputs is transmitted to the master flip-flop. When the pulse returns to 0, the master flip-flop is
disabled and the slave flip-flop is enabled. The slave flip-flop then goes to the same state as the master flip-flop.
The timing relationship is shown in Figure 24 and is assumed that the flip-flop is in the clear state prior
to the occurrence of the clock pulse. The output state of the master-slave flip-flop occurs on the negative
transition of the clock pulse.
Operating Characteristics
The operating characteristics mention here applies to all flip-flops regardless of the particular form of the
circuit..
Propagation Delay Time - is the interval of time required after an input signal has been applied for the resulting
output change to occur. Propagation delays (tpLH & tpHL) in an SR latch are illustrated below:
Set-Up Time - is the minimum interval required for the logic levels to be maintained constantly on the inputs (J
and K, or S and R, or D) prior to the triggering edge of the clock pulse in order for the levels to be reliably
clocked into the flip-flop.
Hold Time - is the minimum interval required for the logic levels to remain on the inputs after the triggering
edge of the clock pulse in order for the levels to be reliably clocked into the flip-flop.
If data makes transition within this setup window and before the hold window, then the flip-flop output is not
predictable, and flip-flop enters what is known as meta stable state. In this state flip-flop output oscillates
between 0 and 1. It takes some time for the flip-flop to settle down. The whole process is called metastability.
Maximum Clock Frequency - is the highest rate that a flip-flop can be reliably triggered.
Pulse Widths - are the minimum pulse widths specified by the manufacturer for the Clock, SET and CLEAR
inputs.
A possible circuit and symbol for a negative-edge-triggered master-slave D flip-flop is shown in Figure 28 and
Figure 29.
Figure 28: A negative−edge−triggered master−slave D clip−clop Figure 29: The graphical symbol for
negative−edge−triggered D clip−clop
The master-slave D flip-flop shown in Figure 28 responds on the negative edge (i.e., the edge where the
clock signal changes from 1 to 0) of the clock signal. Hence it is negative-edge-triggered. The circuit can be
changed to respond to the positive clock edge by connecting the slave stage directly to the clock and the master
stage to the complement of the clock.
A Positive-edge-triggered D Flip-Flop
a positive-edge-triggered master-slave D flip-flop is presented in Figure 31. It requires only six NAND gates and,
hence, fewer logic gates.
The operation of the circuit in Figure 31 is as follows. When Clock = 0, the outputs of gates 2 and 3 are high.
Thus P1 = P2 = 1, which maintains the output latch, comprising gates 5 and 6, in its present state. At the same
time, the signal P3 is equal to D, and P4 is equal to its complement D’. When Clock changes to 1, the following
changes take place. The values of P3 and P4 are transmitted through gates 2 and 3 to cause P1 = D’ and P2 = D,
which sets Q = D and Q’ = D’. To operate reliably, P3 and P4 must be stable when Clock changes from 0 to 1.
Hence the setup time of the flip-flop is equal to the delay from the D input through gates 4 and 1 to P3. The hold
time is given by the delay through gate 3 because once P2 is stable; the changes in D no longer matter.
For proper operation it is necessary to show that, after Clock changes to 1, any further changes in D will not
affect the output latch as long as Clock = 1. We have to consider two cases. Suppose first that D = 0 at the
positive edge of the clock. Then P2 = 0, which will keep the output of gate 4 equal to 1 as long as Clock = 1,
regardless of the value of the D input. The second case is if D = 1 at the positive edge of the clock. Then P1 = 0,
which forces the outputs of gates 1 and 3 to be equal to 1, regardless of the D input. Therefore, the flip-flop
ignores changes in the D input while Clock = 1.
In using flip-flops, it is often necessary to force the flip-flops into a known initial state. A simple way of
providing the clear and present capability is to add extra input to the flip-flops. Figure 15 shows a masterslave D
flip-flop with Clear and Preset. Placing a 0 on the Clear input will force the flip-flop into the state Q = 0. If Clear =
1, then this input will have no effect on the NAND gates. Similarly, Preset = 0 forces the flip-flop into the state Q =
1, while Preset = 1 has no effect. To denote that the Clear and Preset inputs are active when their value is 0, we
placed an overbar on the names in Figure 16. Note that the circuit that uses this flip-flop should not try to force
both Clear and Preset to 0 at the same time. A graphical symbol for this flip-flop is shown in Figure 35.
Figure 35: The graphical symbol for master−slave D clip−clop with Clear and Preset
A similar modification can be done on the positive-edge-triggered D flip-flop, as indicated in Figure 34. A
graphical symbol for this flip-flop is shown in Figure 36. Again, both Clear and Preset inputs are active low. They
do not disturb the flip-flop when they are equal to 1.
Figure 36: A positive−edge−triggered D clip−clop with Clear and Preset Figure 37: The graphical symbol
for positive−edge−triggered D flip−clop with Clear and Preset
In the circuits in Figures 35, the effect of a low signal on either the Clear or Preset input is immediate. For
example, if Clear = 0 then the flip-flop goes into the state Q = 0 immediately, regardless of the value of the clock
signal. In such a circuit, where the Clear signal is used to clear a flip-flop without regard to the clock signal, we
say that the flip-flop has an asynchronous clear. In practice, it is often preferable to clear the flip-flops on the
active edge of the clock. Such synchronous clear can be accomplished as shown in Figure 38. The flip-flop
entity example is
port( Q : out std_logic; -- Data output
CLK :in std_logic; -- Clock input
CE :in std_logic; -- Clock enable input
RESET :in std_logic; -- Synchronous reset input
D :in std_logic; -- Data input
SET : in std_logic -- Synchronous set input );
end example;
architecture Behavioral of example is --architecture of the circuit.
begin
process(CLK)
begin
if ( rising_edge(CLK) ) then --This makes the process synchronous(with clock)
LIBRARY ieee ;
USE ieee.std_logic_1164.all ;
ENTITY flipflop IS
PORT ( D, Resetn, Clock : IN STD_LOGIC ;
Q : OUT STD_LOGIC) ;
END flipflop ;
library ieee;
use ieee.std_logic_1164.all;
ENTITY dff IS
PORT( D, Clk, Clr, Pre : IN STD_LOGIC;
Q, Qbar : OUT STD_LOGIC);
END dff;
ARCHITECTURE behavioral OF dff IS
BEGIN
PROCESS(Clk)
BEGIN
IF (Clk'event) AND (Clk='1') THEN -- Positive Edge
Q <= D;
Qbar <= not D;
END IF;
END PROCESS;
END behavioral;
An interesting modification of the D flip-flop leads to a T flip-flop, which is shown in Figure 21. The graphical
symbol for this T flip-flop is shown in Figure 22.
Figure 21: A circuit for T flip−clop Figure 22: The graphical symbol for T clip−clop
The circuit uses a positive-edge-triggered D flip-flop. The feedback connections make the input signal D equal to
either the value of Q or Q’ under the control of the signal that is labeled T. On each positive edge of the clock, the
flip-flop may change its state Q. The characteristic table for a T flip-flop which describes its behavior is as
follows.
Figure 23 shows an example timing diagram for T flip-flop (assuming negligible propagation delays through the
logic gates).
T flip-flops are single input version of JK flip-flops. This modified form of JK flip-flop is obtained by connecting
both inputs J and K together. These flip-flops are called T (Toggle) flip-flops because of their ability to
complement its state (i.e.) Toggle.
When T=1 and CP=1, the flip-flop complements its output, regardless of the present state of the Flip-flop. In this
case the next state is the complement of the present state.
When T=0, there is no change in the state of the flip-flop (i.e.) the next state is same as the present state of the
flip-flop. From the characteristic table and characteristic equation it is quite evident that when T=0, the next
sate is same as the present state.
All sequential circuits discussed had a problem called race condition (All level sensitive sequential circuits have
this problem). Before the enable input changes state from HIGH to LOW (assuming HIGH is ON and LOW is OFF
state), if inputs changes, then another state transition occurs for the same enable pulse. This sort of multiple
transition problem is called racing.
Figure 26: JK Master Slave Flip-Flop Figure 27: JK Master Slave Flip-Flop using gates
In the figure 26, there are two latches, the first latch on the left is called master latch and the one on the right is
called slave latch. Master latch is positively clocked and slave latch is negatively clocked.
JK Flip-Flop
Another interesting modification of the D flip-flop leads to a JK flip-flop, which is shown in Figure 24. The
graphical symbol for this JK flip-flop is shown in Figure 25.
Figure 25: The graphical symbol for JK flip−clop (positive edge and negative edge triggered)
In the circuit in Figure 24, instead of using a single control input, T, we use two inputs, J and K. For this circuit
the input D is
The characteristic table for a JK flip-flop which describes its behavior is as follows.
A J-K flip-flop is nothing more than an S-R flip-flop with an added layer of feedback. This feedback selectively
enables one of the two set/reset inputs so that they cannot both carry an active signal to the multivibrator
circuit, thus eliminating the invalid condition.
When both J and K inputs are activated, and the clock input is pulsed, the outputs (Q and not-Q) will swap states.
That is, the circuit will toggle from a set state to a reset state, or vice versa.
Essentially, this is a modified version of an S-R flip-flop with no "invalid" or "illegal" output state.
What used to be the S and R inputs are now called the J and K inputs, respectively. The old two-input AND gates
have been replaced with 3-input AND gates, and the third input of each gate receives feedback from the Q and
not-Q outputs. What this does for us is permit the J input to have effect only when the circuit is reset, and permit
the K input to have effect only when the circuit is set. In other words, the two inputs are interlocked, to use a
relay logic term, so that they cannot both be activated simultaneously. If the circuit is "set," the J input is
inhibited by the 0 status of not-Q through the lower AND gate; if the circuit is "reset," the K input is inhibited by
the 0 status of Q through the upper AND gate.
When both J and K inputs are 1, however, something unique happens. Because of the selective inhibiting action
of those 3-input AND gates, a "set" state inhibits input J so that the flip-flop acts as if J=0 while K=1 when in fact
both are 1. On the next clock pulse, the outputs will switch ("toggle") from set (Q=1 and not-Q=0) to reset (Q=0
and not-Q=1). Conversely, a "reset" state inhibits input K so that the flip-flop acts as if J=1 and K=0 when in fact
both are 1. The next clock pulse toggles the circuit again from reset to set.
D Latch in VHDL
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
entity jkff1 is
Port ( in1 : in STD_LOGIC;
in2 : in STD_LOGIC;
clock : in STD_LOGIC;
2/4 DELD, IT DEPT, M. V. S. R. E. C Faculty: S Ch Vijaya Bhaskar Page 108
output : out STD_LOGIC);
end jkff1;
begin
process(in1,in2,clock)
begin
Table below shows the state diagrams of the four types of flip-flops.
• Latch is a level triggered device but flip flop is a edge triggered device.
• Latch takes less gates but flipflop takes more.
• Latch faster flipflop slower.
• Latch does'nt have a clock signal but flip flop depends on theclock signal but both are having one bit memory.
• Latches: They are sensitive to the duration of pulse and can transfer data until they are switched on. They hold
the last logic at the output if we put it off (bring the strobe pin to low). They are used as temporary buffers.
• FF: They are sensitive to signal change (low to high or high to low) and not the level. Hence they transfer data
only at that instant and it cannot be changed until next signal change. Due to this they are used as registers.
In digital circuits a shift register is a group of flip flops set up in a linear fashion which have their inputs and
outputs connected together in such a way that the data is shifted down the line when the circuit is activated. Shift
registers, like counters, are a form of sequential logic, unlike combinational logic is not only affected by the present
inputs, but also, by the prior history.
Shift registers produce a discrete delay of a digital signal or waveform. A waveform synchronized to a clock, a
repeating square wave, is delayed by "n" discrete clock times, where "n" is the number of shift register stages. The
stages in a shift register are delay stages, typically type "D" Flip-Flops or type "JK" Flip-flops.
Basic shift registers are classified by structure according to the following types:
• Serial-in/serial-out
• Parallel-in/serial-out(PISO)
• Serial-in/parallel-out(SIPO)
• Universal parallel-in/parallel-out
• Ring counter
In order to get the data out of the register, they must be shifted out serially.
This type of Shift Register also acts as a temporary storage device or as a time delay device, with the amount of time
delay being controlled by the number of stages in the register, 4, 8, 16 etc or by varying the application of the clock
pulses.
This can be done destructively or non-destructively. For destructive readout, the original data is lost and at the end of
the read cycle, all flip-flops are reset to zero.
Destructive readout
These are the simplest kind of shift register. The data string is presented at 'Data In', and is shifted right one
stage each time 'Data Advance' is brought high. At each advance, the bit on the far left (i.e. 'Data In') is shifted into the
first flip-flop's output. The bit on the far right (i.e. 'Data Out') is shifted out and lost.
Non-destructive readout
Non-destructive readout can be achieved using the configuration shown in figure 3. Another input line is
added - the Read/Write Control. When this is high (i.e. write) then the shift register behaves as normal, advancing the
input data one place for every clock cycle, and data can be lost from the end of the register. However, when the R/W
control is set low (i.e. read), any data shifted out of the register at the right becomes the next input at the left, and is
kept in the system. Therefore, as long as the R/W control is set low, no data can be lost from the system
To avoid the loss of data, an arrangement for a non-destructive reading can be done by adding two AND gates, an OR
gate and an inverter to the system.
Figure 6: Serial in parallel out 4 bit shift register with D Flip flop
Above, four data bits will be shifted in from "data in" by four clock pulses and be available at QA through QD
for driving external circuitry.
After the first clock, the data at "data in" appears at QA. After the second clock, The old QA data appears at
QB; QA receives next data from "data in". After the third clock, QB data is at QC. After the fourth clock, QC data is at
QD. This stage contains the data first present at "data in". The shift register should now contain four data bits.
The effect of each clock pulse is to shift the DATA contents of each stage one place to the right, and this is
shown in the following table until the complete DATA is stored, which can now be read directly from the outputs of
QA to QD. Then the DATA has been converted from a Serial Data signal to a Parallel Data word.
Clock Pulse No QA QB QC QD
0 0 0 0 0
1 1 0 0 0
2 0 1 0 0
3 0 0 1 0
4 0 0 0 1
5 0 0 0 0
Figure 7: Parallel in Serial out 4 bit shift register with D Flip flop
Data is loaded into all stages at once of a parallel-in/serial-out shift register. The data is then shifted out via
"data out" by clock pulses. Since a 4- stage shift register is shown above, four clock pulses are required to shift out all
of the data. In the diagram above, stage D data will be present at the "data out" up until the first clock pulse; stage C
data will be present at "data out" between the first clock and the second clock pulse; stage B data will be present
between the second clock and the third clock; and stage A data will be present between the third and the fourth clock.
After the fourth clock pulse and thereafter, successive bits of "data in" should appear at "data out" of the shift register
after a delay of four clock pulses.
As this type of Shift Register converts parallel data, such as an 8-bit data word into serial data it can be used to
multiplex many different input lines into a single serial DATA stream which can be sent directly to a computer or
transmitted over a communications line.
A four-bit parallel in - serial out shift register with NAND gates is shown in figure 9. The circuit uses D flip-
flops and NAND gates for entering data (ie writing) to the register.
Figure 9: Parallel in Serial out 4 bit shift register with D Flip flop and NAND gates
D0, D1, D2 and D3 are the parallel inputs, where D0 is the most significant bit and D3 is the least significant bit. To
write data in, the mode control line is taken to LOW and the data is clocked in. The data can be shifted when the mode
control line is HIGH as SHIFT is active high.
Figure 11: Parallel in Parallel out 4 bit shift register with D Flip flop
A parallel-in/parallel-out shift register combines the function of the parallel-in, serial-out shift register with the
function of the serial-in, parallel-out shift register to yields the universal shift register.
Data presented at PA through PD is parallel loaded into the registers. This data at QA through QD may be
shifted by the number of pulses presented at the clock input. The shifted data is available at QA through QD. The
"mode" input, which may be more than one input, controls parallel loading of data from PA through PD, shifting of
data, and the direction of shifting. There are shift registers which will shift data either left or right.
Instead of using the normal shift register connection, the D input of each flip-flop is connected to two different
sources. One source is the preceding flip-flop which is needed for the shift register operation. The other source is the
external input that corresponds to the bit that is to be loaded into the flip-flop as part of the parallel-load operation. The
controlled signal is used to select the mode of operation. If the =0, then the circuit operates as
The contents of the register can be accessed in parallel by observing the outputs of all flip-flops. The flip-flops can also
be access serially, by observing the values of Q0 during consecutive clock cycles while the contents are being shifted.
A circuit in which data can be loaded in series and then accessed in parallel is called a series to parallel converter.
Similarly, the opposite type of circuit is a parallel to series converter.
A bidirectional, or reversible, shift register is one in which the data can be shift either left or right. A four-bit
bidirectional shift register using D flip-flops is shown below.
Here a set of NAND gates are configured as OR gates to select data inputs from the right or left adjacent bistables, as
selected by the LEFT/RIGHT control line.
The animation below performs right shift four times, then left shift four times. Notice the order of the four output bits
are not the same as the order of the original four input bits.
Example: The clock frequency is 2MHz. How long will it take to serial load the eight shift register?
Solution:
n=8
A sequential circuit that goes through a prescribed sequence of states upon the application of input pulses is
called a counter. The input pulses, called count pulses, may be clock pulses. In a counter, the sequence of states may
follow a binary count or any other sequence of states. A counter that follows the binary sequence is called a binary
counter. An n-bit binary counter consists of n flip-flops and can count in binary from 0 to 2n - 1.
In practice, there are two types of counters:
• up counters which increase (increment) in value
• down counters which decrease (decrement) in value
Counters Types
In electronics, counters can be implemented quite easily using register-type circuits such as the flip-flop, and a
wide variety of designs exist, e.g:
• Asynchronous (ripple) counters
• Synchronous counters
• Johnson counters
• Decade counters
• Up-Down counters
• Ring counters
Synchronous counters
Where a stable count value is important across several bits, which is the case in most counter systems,
synchronous counters are used. These also use flip-flops, either the D-type or the more complex J-K type, but here,
each stage is clocked simultaneously by a common clock signal. Logic gates between each stage of the circuit control
data flow from stage to stage so that the desired count behavior is realized.
Decade counters
Decade counters are a kind of counter that counts in tens rather than having a binary representation. Each output will
go high in turn, starting over after ten outputs have occurred. This type of circuit finds applications in multiplexers and
demultiplexers, or wherever a scanning type of behaviour is useful.
Up-Down Counters
It is a combination of up counter and down counter, counting in straight binary sequence. There is an up-down
selector. If this value is kept high, counter increments binary value and if the value is low, then counter starts
decrementing the count. The Down counters are made by using the complemented output to act as the clock for the
next flip-flop in the case of Asynchronous counters. An Up counter is constructed by linking the Q out of the J-K Flip
flop and putting it into a Negative Edge Triggered Clock input. A Down Counter is constructed by taking the Q output
and putting it into a Positive Edge Triggered input
Johnson counters
A Johnson counter (or switch tail ring counter, twisted-ring counter, walking-ring counter, or Moebius counter) is a
modified ring counter, where the output from the last stage is inverted and fed back as input to the first stage. A pattern
of bits equal in length to twice the length of the shift register thus circulates indefinitely. These counters find specialist
applications, including those similar to the decade counter, digital to analogue conversion, etc.
Ring Counters
A ring counter is a counter that counts up and when it reaches the last number that is designed to count up to, it will
reset itself back to the first number. For example, a ring counter that is designed using 3 JK Flip Flops will count
starting from 001 to 010 to 100 and back to 001. It will repeat itself in a 'Ring' shape and thus the name Ring Counter
is given.
A ring counter is a shift register (a cascade connection of flip-flops) with the output of the last one connected to the
input of the first, that is, in a ring. Typically a pattern consisting of a single 1 bit is circulated, so the state repeats every
N clock cycles if N flip-flops are used. It can be used as a cycle counter of N states.
Ring Counters
A ring counter is a type of counter composed of a circular shift register. The output of the last shift register is fed to
the input of the first register.
• A straight ring counter or Overbeck counter connects the output of the last shift register to the first shift
register input and circulates a single one (or zero) bit around the ring. For example, in a 4-register one-hot
counter, with initial register values of 1000, the repeating pattern is: 1000, 0100, 0010, 0001, 1000... .
The following is a 4-bit ring counter constructed from D flip-flops. The output of each stage is shifted into the next
stage on the positive edge of a clock pulse. If the CLEAR signal is high, all the flip-flops except the first one FF0 are
reset to 0. FF0 is preset to 1 instead.
Figure: Ring counter, whose shift register outputs are fed back as inputs
Since the count sequence has 4 distinct states, the counter can be considered as a mod-4 counter. But the major
advantage of a ring counter over a binary counter is that it is self-decoding. No extra decoding circuit is needed to
determine what state the counter is in.
• A twisted ring counter or Johnson counter connects the complement of the output of the last shift register to
its input and circulates a stream of ones followed by zeros around the ring. For example, in a 4-register
counter, with initial register values of 0000, the repeating pattern is: 0000, 1000, 1100, 1110, 1111, 0111,
0011, 0001, 0000... .
Figure: Ring counter, whose shift register complemented outputs are fed back as inputs
Johnson counters are a variation of standard ring counters, with the inverted output of the last stage fed back to the
input of the first stage. An n-stage Johnson counter yields a count sequence of length 2n, so it may be considered to be
a mod-2n counter. The circuit above shows a 4-bit Johnson counter.
Again, the apparent disadvantage of this counter is that the maximum available states are not fully utilized. Only eight
of the sixteen states are being used.
• Counters often have a parallel-load capability for transferring an initial binary number into the counter
prior to the count an initial binary number into the counter prior to the count operation.
• This can be accomplished via the clear and preset inputs of the ppp flip-flops.
• To accomplish this, a carryout can be generated if the output of all flip-flops is equal to 1 while the count
input is enabled all flip flops is equal to 1 while the count input is enabled.
• The carry-out is connected to the count input of the counter holding the next higher-order bits.gg
• A counter with parallel load can be used to produce any desired number of count sequences.
• A modulo-N (or mod-N) counter is a counter that generates a repeated sequence of N counts, e.g. a 4-bit binary
counter is a mod-16 countermod 16 counter.
• A modulo-N (or mod-N) counter is a counter that generates a repeated sequence of N counts e g a 4-bit
binary counter is a repeated sequence of N counts, e.g. a 4 bit binary counter is a mod-16 counter.
• The most straightforward approach is to recognize when the count reaches five and then reset the counter
count reaches five and then reset the counter.
• An AND gate can be used to detect the occurrence of the count of five of five.
• Because the counter is reset on the active edge of the clock, this type of counter has a synchronous reset.
• The implementation of a synchronous reset can be accomplished via either the clear feature of individual
flip- flops, or a parallel load approach.flops, or a parallel load approach.
• Note that generally synchronous reset is a better choice than asynchronous reset.
As discussed in the combinational circuits section, how to design a combinational circuit from the given problem. We
convert the problem into a truth table, then draw K-map for the truth table, and then finally draw the gate level circuit
for the problem. Similarly we have a flow for the sequential circuit design. The steps are given below.
• State Diagram
The state diagram is constructed using all the states of the sequential circuit in question. It builds up the relationship
between various states and also shows how inputs affect the states.
let's consider designing the 2 bit up counter (Binary counter is one which counts a binary sequence) using the T flip-
flop. Below is the state diagram of the 2-bit binary counter.
The state table is the same as the excitation table of a flip-flop, i.e. what inputs need to be applied to get the required
output. In other words this table gives the inputs required to produce the specific outputs.
• K-map
The K-map is the same as the combinational circuits K-map. Only difference: we draw K-map for the inputs i.e. T1 and
T0 in the above table. From the table we deduct that we don't need to draw K-map for T0, as it is high for all the state
combinations. But for T1 we need to draw the K-map as shown below, using SOP.
There is nothing special in drawing the circuit, it is the same as any circuit drawing from K-map output. Below is the
circuit of 2-bit up counter using the T flip-flop.
A finite state machine (FSM) or finite state automaton or simply a state machine, is a model of behavior
composed of a finite number of states, transitions between those states, and actions. It is similar to a "flow
graph" where we can inspect the way in which the logic runs when certain conditions are met. A finite state
machine is an abstract model of a machine with a primitive internal memory.
• Finite State Machines (FSMs) are a useful abstraction for sequential circuits with centralized “states” of
operation
• At each clock edge, combinational logic computes outputs and next state as a function of inputs and
present state
• FSMs divide their complexity into chunks called states
• Each state is simpler than the overall object
• Because each state is simpler, it is more understandable and predictable
• FSMs simplify the system into smaller pieces
• Smaller pieces are easier to code
– They are easy to write the code for
– They are easier to “get right”
– They are easy to explain in peer reviews
Transducers generate output based on a given input and/or a state using actions. They are used for control
applications and in the field of computational linguistics. Here two types are distinguished:
• Moore machine
• Mealy machine
Moore machine
In the theory of computation, a Moore machine is a finite state transducer where the outputs are determined
by the current state alone (and do not depend directly on the input). The state diagram for a Moore machine
will include an output signal for each state. Compare with a Mealy machine, which maps transitions in the
machine to outputs.
Most digital electronic systems are designed as clocked sequential systems. Clocked sequential systems
are a restricted form of Moore machine where the state changes only when the global clock signal changes.
Typically the current state is stored in flip-flops, and a global clock signal is connected to the "clock" input of the
flip-flops. Clocked sequential systems are one way to solve metastability problems. A typical electronic Moore
machine includes a combinatorial logic chain to decode the current state into the outputs (lambda). The instant
the current state changes, those changes ripple through that chain, and almost instantaneously the outputs
change (or don't change). There are design techniques to ensure that no glitches occur on the outputs during
that brief period while those changes are rippling through the chain, but most systems are designed so that
glitches during that brief transition time are ignored or are irrelevant. The outputs then stay the same
indefinitely, until the Moore machine changes state again.
Formal definition
Mealy machine
In the theory of computation, a Mealy machine is a finite state transducer that generates an output
based on its current state and input. This means that the state diagram will include both an input and output
signal for each transition edge. In contrast, the output of a Moore finite state machine depends only on the
machine's current state; transitions are not directly dependent upon input. However, for each Mealy machine
there is an equivalent Moore machine.
Formal definition
A binary-encoded FSM design only requires as many flip-flops as are needed to uniquely encode the
number of states in the state machine.
A onehot FSM design requires a flip-flop for each state in the design and only one flip-flop (the flip-flop
representing the current or "hot" state) is set at a time in a onehot FSM design. For a state machine with 9-
16 states, a binary FSM only requires 4 flip-flops while a onehot FSM requires a flip-flop for each state in
the design (9-16 flip-flops).
Serial Adder
• A serial adder that computes the sum of two n-bit unsigned numbers an-1 ... a1 a0 and bn-1 ... b1 b0 is
described by the block diagram. The sum bits si are calculated 1 bit in one clock cycle beginning with the LSB.
• The addends and the sum are stored in shift registers which have parallel-load capability.
• In clock cycle i the adder FSM inputs are bit ai and bit bi. The sum bit si is computed by the two inputs and the
carry bit ci-1 which was produced while generating sum bit si-1.
• The adder FSM circuit has to remember the carry bit from the previous clock cycle.
Two States:
• State G: carry-in = 0
• State H: carry-in = 1
State Diagram