9c22432fexp 1-10
9c22432fexp 1-10
Aim: Write down VHDL program for half adder and full adder.
System Description:
In electronics, an adder or summer is a digital circuit that performs addition of binary numbers.
In many computers and other kinds of processors, adders are used not only in the arithmetic logic
unit(s), but also in other parts of the processor, where they are used to calculate addresses, table
indices, and similar operations.
Half Adder: Half adder is a combinational arithmetic circuit that adds two numbers and
produces a sum bit (S) and carry bit (C) as the output. If A and B are the input bits, then sum bit
(S) is the X-OR of A and B and the carry bit (C) will be the AND of A and B. From this it is
clear that a half adder circuit can be easily constructed using one X-OR gate and one AND gate.
Half adder is the simplest of all adder circuit, but it has a major disadvantage. The half adder can
add only two input bits (A and B) and has nothing to do with the carry if there is any in the input.
So if the input to a half adder have a carry, then it will be neglected it and adds only the A and B
bits. That means the binary addition process is not complete and that’s why it is called a half
adder.
Full Adder: Full adder is a conditional circuit which performs full binary addition that means it
adds two bits and a carry and outputs a sum bit and a carry bit. Any bit of augend can either be 1
or 0 and we can represent with variable A, similarly any bit of addend we represent with variable
B. The carry after addition of same significant bit of augend and addend can represent by C.
Logic Diagram:
Figure 1.1 Half Adder Circuit Diagram Figure 1.2 Full Adder Circuit Diagram
Truth Table
Inputs Outputs
A B Cin Cout S
0 0 0 0 0
1 0 0 0 1
0 1 0 0 1
1 1 0 1 0
0 0 1 0 1
1 0 1 1 0
0 1 1 1 0
1 1 1 1 1
SCHEMATIC:
Figure 1.3
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
entity halfadder1 is
e : in STD_LOGIC;
end halfadder1;
begin
process(a,b,e)
begin
end process ;
end Behavioral;
entityfulladderbehavioural is
e : in STD_LOGIC;
endfulladderbehavioural;
begin
process(a,b,c,e)
begin
end process ;
end Behavioral;
OUTPUT
:
System Description:
A digital MUX is a combinational circuit that selects one input out of several inputs and directs it
to a single output. The particular input section is controlled by a set of select inputs.
Logic Diagram:
Truth Table
Select Output
Input’s
S1 S0 Y
0 0 I0
0 1 I1
1 0 I2
1 1 I3
SCHEMATIC:
Figure 2.2
VHDL CODE
entity mux41 is
e : in STD_LOGIC;
y : out STD_LOGIC);
end mux41;
begin
process(x,e)
begin
y <= x(0);
y <= x(1);
y <= x(2);
y <= x(3);
end if;
else
y <= 'X';
end if;
end process;
end Behavioral;
OUTPUT
Figure 2.3
4 : 1 Multiplexer Output
EXPERIMENT 3
Aim: Write down VHDL program for D flip flop and T flip flop.
System Description:
The D Flip Flop is by far the most important of the clocked flip-flops as it ensures that ensures
that inputs S and R are never equal to one at the same time. The D-type flip flop are constructed
from a gated SR flip-flop with an inverter added between the S and the R inputs to allow for a
single D (data) input.
Then this single data input, labelled D, is used in place of the “set” signal, and the inverter is
used to generate the complementary “reset” input thereby making a level-sensitive D-type flip-
flop from a level-sensitive RS-latch as now S = D and R = not D as shown.
T flip flop is also known as “Toggle Flip – flop”. To avoid the occurrence of intermediate state
in SR flip – flop, we should provide only one input to the flip – flop called Trigger input or
Toggle input (T). Then the flip – flop acts as a Toggle switch. Toggling means ‘Changing the
next state output to complement of the present state output’.
We can design the T flip – flop by making simple modifications to the JK flip – flop. The T flip
– flop is a single input device and hence by connecting J and K inputs together and giving them
with single input called T we can convert a JK flip – flop into T flip – flop. So a T flip – flop is
sometimes called as single input JK flip – flop.
SCHEMATIC:
Figure 3.1
----------------------------------------------------------------------------------
-- Company:
-- Engineer:
--
-- Design Name:
-- Project Name:
-- Target Devices:
-- Tool versions:
-- Description:
--
-- Dependencies:
--
-- Revision:
-- Additional Comments:
--
----------------------------------------------------------------------------------
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
--use IEEE.NUMERIC_STD.ALL;
--library UNISIM;
--use UNISIM.VComponents.all;
entity Dfflop is
x : in STD_LOGIC;
pr : in STD_LOGIC;
clr : in STD_LOGIC;
q : out STD_LOGIC) ;
end Dfflop;
process(clk,clr,pr)
begin
q <= 'X';
q <= '1';
q <= '0';
if(rising_edge(clk)) then
q <= x;
end if;
end if;
end process;
end Behavioral;
----------------------------------------------------------------------------------
-- Company:
-- Engineer:
--
-- Design Name:
-- Project Name:
-- Target Devices:
-- Tool versions:
-- Description:
--
-- Dependencies:
--
-- Revision:
-- Additional Comments:
--
----------------------------------------------------------------------------------
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
--use IEEE.NUMERIC_STD.ALL;
--library UNISIM;
--use UNISIM.VComponents.all;
entity Tflipflop is
x : in STD_LOGIC;
pr : in STD_LOGIC;
clr : in STD_LOGIC;
q : inout STD_LOGIC);
end Tflipflop;
begin
process(clk,clr,pr)
begin
q <= '1';
q <= '0';
q <= 'X';
if(rising_edge(clk)) then
q <= not(q);
q <= q;
end if;
end if;
end if;
end process;
end Behavioral;
OUTPUT:
D flip flop
T flip flop
EXPERIMENT 4
System Description:
An encoder is a device which converts familiar numbers or characters or symbols into a coded
format. It accepts the alphabetic characters and decimal numbers as inputs and produces the
outputs as a coded representation of the inputs.It encodes the given information into a more
compact form. In other words, it is a combinational circuit that performs the opposite function of
a decoder.
The block diagram and truth table of a 4 input encoder is shown in below figure. The truth table
consists of four rows , since , it is assumed that only one input is the value of 1 then the
corresponding binary code associated with that enabled input is displayed at the outputs. It is to
be observed from the table is the output Yo is 1 when either input w1 or w3 is 1, also the output
Y1 is set to 1 when either input w2 or w3 is 1.
VHDL CODE
entityencoderdataflow is
e : in STD_LOGIC;
endencoderdataflow;
begin
process(x,e)
begin
case x is
when "0001" => o <= "00";
end case;
else
o <= "XX";
end if;
end process ;
end Behavioral;
OUTPUT
EXPERIMENT 5
System Description:
The Binary Decoder is another combinational logic circuit constructed from individual logic
gates and is the exact opposite to that of an “Encoder” we looked at in the last tutorial. The name
“Decoder” means to translate or decode coded information from one format into another, so a
digital decoder transforms a set of digital input signals into an equivalent decimal code at its
output.
SCHEMATIC:
RTL schematic of decoder
VHDL CODE
entitydecoderbehavioural is
e : in STD_LOGIC;
enddecoderbehavioural;
begin
process(x,e)
begin
case x is
end case ;
else
o <= "XXXX";
end if;
end process ;
end Behavioral;
Output
EXPERIMENT 6
System Description:
A digital comparator or magnitude comparator is a hardware electronic device that takes two
numbers as input in binary form and determine whether one number is greater than, less than or
equal to the other number. Comparators are used in a central processing units (CPU) and
microcontrollers. Examples of digital comparator include the CMOS 4063 and 4585 and the TTL
7485 and 74682-’89.
The analog equivalent of digital comparator is the voltage comparator. Many microcontrollers
have analog comparators on some of their inputs that can be read or trigger an interrupt.
SCHEMATIC:
entity comparator is
e: in STD_LOGIC;
end comparator;
begin
process(a,b,e)
begin
if (a>b) then
else
end if ;
end if;
end process ;
end Behavioral;
Output
EXPERIMENT 7
System Description:
A digital comparator or magnitude comparator is a hardware circuit that takes two numbers as
input in binary form and determines whether one number is equal to , less than or greater than
the other number. Comparator are used in CPU and microcontroller. Examples of digital
comparator include CMOS 4063 and 4858 and TTL 7485 and 74682-‘89
The analog equivalent of digital comparator is the voltage comparator. Many microcontrollers
have analog comparators on some of their inputs that can be read or trigger an interrupt.
SCHEMATIC:
RTL schematic of 4-bit comparator
VHDL CODE
entitycomparator_four is
e : in STD_LOGIC;
x : out STD_LOGIC;
y : out STD_LOGIC;
z : out STD_LOGIC);
endcomparator_four;
begin
process(a,b,e)
begin
if(a>b)
else
x<='0'; y<='1';z<='0';
end if;
else
x <= 'X';
y <= 'X';
z <= 'X';
end if;
end process;
end Behavioral;
Output
EXPERIMENT 8
Aim: Write down VHDL program for 3-bit Binary to gray Code Convertor.
System Description:
The reflected binary code, also known as gray code after frank gray, is a binary numerical system
where two successive values differ in only one bit.It is a non-weighted code.
The reflected binary system was originally designed to prevent spurious output from
electromechanical switches. Today, Gray codes are widely used to facilitate error correction in
digital communication such as digital terrestrial and some cable TV systems.
LOGIC DIAGRAM:
TRUTH TABLE:
VHDL CODE
entity b2gray is
e : in STD_LOGIC;
end b2gray;
begin
process(x,e)
begin
end if;
end process;
end Behavioral;
OUTPUT
EXPERIMENT 9
Aim: Write down VHDL program for BCD to Seven Segment Decoder.
System Description:
A seven segment display is a form of electronic display device for displaying decimal numerical
that is an alternative to the more complex dot matrix displays. Seven-segment displays are
widely used in digital clocks, electronic meters, and other electronic devices for displaying
numerical information.
The idea of the seven segment display is quite old. In 1910, for example, seven segment display
illuminated by incandescent bulbs were used on a power plant boiler room signal panel.
Truth Table:
0 0 0 0 1 1 1 0 1 1 1
0 0 0 1 0 0 1 0 0 1 0
0 0 1 0 1 0 1 1 1 0 1
0 0 1 1 1 0 1 1 0 1 1
0 1 0 0 0 1 1 1 0 1 0
0 1 0 1 1 1 0 1 0 1 1
0 1 1 0 1 1 0 1 1 1 1
0 1 1 1 1 0 1 0 0 1 0
1 0 0 0 1 1 1 1 1 1 1
1 0 0 1 1 1 1 1 0 1 1
SCHEMATIC:
VHDL CODE
entity bcd2seven is
e : in STD_LOGIC;
end bcd2seven;
architecture Behavioral of bcd2seven is
begin
process(x,e)
begin
if (e = '1') then
case x is
end case ;
else
o <= "XXXXXXX";
end if;
end process;
end Behavioral;
OUTPUT
EXPERIMENT 10
AIM: Write down VHDL program for Serial in Parallel out (SIPO) register using Behavioral
Modelling style.
SYSTEM DESCRIPTION:
A serial-in/parallel-out shift register is similar to the serial-in/ serial-out shift register in that it
shifts data into internal storage elements and shifts data out at the serial-out, data-out, pin. It is
different in that it makes all the internal stages available as outputs. Therefore, a serial-
in/parallel-out shift register converts data from serial format to parallel format.
The practical application of the serial-in/parallel-out shift register is to convert data from serial
format on a single wire to parallel format on multiple wires. Perhaps, we will illuminate four
LEDs (Light Emitting Diodes) with the four outputs
LOGIC DIAGRAM:
The truth table and following waveforms show the propagation of the logic “1” through the
register from left to right as follows:
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
SCHEMATIC:
OUTPUT :
SYSTEM DESCRIPTION:
In digital logic and computing, a counter is a device which stores (and sometimes displays) the
number of times a particular event or process has occurred, often in relationship to a clock signal.
A counter that can change state in either direction, under the control of an up or down selector
input, is known as an up/down counter. When the selector is in the up state, the counter
increments its value. When the selector is in the down state, the counter decrements the count.
CIRCUIT DIAGRAM
C qc qb qa QC QB QA
1 0 0 0 0 0 1
1 0 0 1 0 1 0
1 0 1 0 0 1 1
1 0 1 1 1 0 0
1 1 0 0 1 0 1
1 1 0 1 1 1 0
1 1 1 0 1 1 1
1 1 1 1 0 0 0
0 0 0 0 1 1 1
0 0 0 1 0 0 0
0 0 1 0 0 0 1
0 0 1 1 0 1 0
0 1 0 0 0 1 1
0 1 0 1 1 0 0
0 1 1 0 1 0 1
0 1 1 1 1 1 0
SCHEMATIC:
entity counter is
port( reset,c,clk : in std_logic;
q : inout integer range 0 to 7);
end counter;
process(clk,reset)
variable ctr: std_logic:='1';
begin
end process;
end Behavioral;
OUTPUT:
AIM: Write a VHDL program for 3 bit even parity checker using Behavioral modeling style.
SYSTEM DESCRIPTION:
It is a logic circuit that checks for possible errors in the transmission. This circuit can be an even
parity checker or odd parity checker depending on the type of parity generated at the
transmission end. When this circuit is used as even parity checker, the number of input bits must
always be even.
When a parity error occurs, the ‘sum even’ output goes low and ‘sum odd’ output goes high. If
this logic circuit is used as an odd parity checker, the number of input bits should be odd, but if
an error occurs the ‘sum odd’ output goes low and ‘sum even’ output goes high.
Consider that three input message along with even parity bit is generated at the transmitting end.
These 4 bits are applied as input to the parity checker circuit which checks the possibility of error
on the data. Since the data is transmitted with even parity, four bits received at circuit must have
an even number of 1s.
If any error occurs, the received message consists of odd number of 1s. The output of the parity
checker is denoted by PEC (parity error check).
The below table shows the truth table for the even parity checker in which PEC = 1 if the error
occurs, i.e., the four bits received have odd number of 1s and PEC = 0 if no error occurs, i.e., if
the 4-bit message has even number of 1s.
CIRCUIT DIAGRAM
The above logic expression for the even parity checker can be implemented by using three Ex-
OR gates as shown in figure. If the received message consists of five bits, then one more Ex-OR
gate is required for the even parity checking.
TRUTH TABLE
e x3 x2 x1 x0 o
0 X X X X X
1 0 0 0 1 1
1 0 0 1 0 1
1 0 0 1 1 0
1 0 1 0 0 1
1 0 1 0 1 0
1 0 1 1 0 0
1 0 1 1 1 1
1 1 0 0 0 1
1 1 0 0 1 0
1 1 0 1 0 0
1 1 0 1 1 1
SCHEMATIC:
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
entitythreebit is
Port ( x : in STD_LOGIC_VECTOR(3 downto 0);
e : in STD_LOGIC;
o : out STD_LOGIC);
endthreebit;
begin
process(x,e)
begin
if(e = '1') then
o <= x(3) xor x(2) xor x(1) xor x(0);
elsif(e = '0') then
o <= 'X';
end if;
end process;
end Behavioral;
OUTPUT:
AIM: Write a VHDL program for 4:2 Priority Encoder using Behavioral modeling style.
SYSTEM DESCRIPTION:
A 4-bit priority encoder (also sometimes called a priority decoder). This circuit basically
converts the 4-bit input into a binary representation. If the input n is active, all lower inputs (n-1
.. 0) are ignored.
The circuit operation is simple. Each output is driven by an OR-gate which is connected to the
NAND-INV outputs of the corresponding input lines. The NAND gate of each stages receives its
input bit, as well as the NAND gate outputs of all higher priority stages. This structure implies
that an active input on stage n effectively disables all lower stages n-1 to 0.
Note that the circuit function as specified here does not depend at all on the least significand
input bit.
A common use of priority encoders is for interrupt controllers, to select the most critical out of
multiple interrupt requests. Due to electrical reasons (open collector outputs), priority encoders
with active-low inputs are also often used in practice.
CIRCUIT DIGRAM
TRUTH TABLE
VHDL CODE:
entitypriorityencoder is
Port ( e : in STD_LOGIC;
x : in STD_LOGIC_VECTOR(3 downto 0);
y : out STD_LOGIC_VECTOR(1 downto 0)
);
endpriorityencoder;
begin
process(x,e)
begin
if(e = '1') then
if(x(3) = '1') then
y <= "11";
elsif(x(2) = '1') then
y <= "10";
elsif(x(1) = '1') then
y <= "01";
elsif(x(0) = '1') then
y <= "00";
else
y <= "XX";
end if;
elsif(e = '0') then
y <= "XX";
end if;
end process;
end Behavioral;
OUTPUT