EXPERIMENT NO 2 AIM: To implement HALF ADDER in VHDL using dataflow, behavioral and structural style of modeling. INTRODUCTION: Half adder is the most basic digital arithmetic circuit. It is a logical circuit that performs an addition operation on two binary digits. It is a combinational circuit which produces a sum and a carry value, which are both binary digits. A half adder has two inputs, generally labeled A and B, and two outputs, the “sum” S and “carry flag” C. S is the two-bit “XOR gate” of A and B, and C is the “AND gate” of A and B. S= A xor B C=A and B Following is the truth table for a half adder is – A B S C
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
EXPERIMENT NO 2
AIM: To implement HALF ADDER in VHDL using dataflow, behavioral and structural style of modeling.
INTRODUCTION:
Half adder is the most basic digital arithmetic circuit. It is a logical circuit that performs an addition operation on two binary digits. It is a combinational circuit which produces a sum and a carry value, which are both binary digits.
A half adder has two inputs, generally labeled A and B, and two outputs, the “sum” S and “carry flag” C.
S is the two-bit “XOR gate” of A and B, and C is the “AND gate” of A and B.
S= A xor B
C=A and B
Following is the truth table for a half adder is –
A B S C
0 0 0 0
0 1 1 0
1 0 1 0
1 1 0 1
Dataflow code for half adder
library ieee;
use ieee.std_logic_1164.all;
entity halfdata is
port(a,b:in bit;
s,c:out bit);
end halfdata;
architecture halfdata of halfdata is
begin
s<=a xor b;
c<= a and b;
end halfdata;
Output
Behaviuoral code for half adder
library ieee;
use ieee.std_logic_1164.all;
entity halfbehv is
port(a,b:in bit;
s,c:out bit);
end halfbehv;
architecture halfbehv of halfbehv is
begin
p1:process(a,b)
begin
if a & b ="00"
then s<='0'; c<='0';
elsif a & b ="01"
then s<='1'; c<='0';
elsif a & b ="10"
then s<='1'; c<='0';
else s<='0'; c<='1';
end if;
end process p1;
end halfbehv;
Output
Structural code for half adder
library ieee;
use ieee.std_logic_1164.all;
entity andg is
port(a,b:in bit;
z:out bit);
end andg;
architecture e1 of andg is
begin
z<= a and b;
end e1;
entity xorg is
port(a,b:in bit;
z:out bit);
end xorg;
architecture e2 of xorg is
begin
z<= a xor b;
end e2;
entity ha is
port(a,b:in bit;
s,c:out bit);
end ha;
architecture ha of ha is
component andg
port(a,b:in bit;
z:out bit);
end component;
component xorg
port(a,b:in bit;
z:out bit);
end component;
begin
a1 : andg port map(a,b,c);
a2 : xorg port map(a,b,s);
end ha;
Output
EXPERIMENT NO 3
AIM: To implement FULL ADDER in VHDL using dataflow, behavioral and structural style of modeling.
INTRODUCTION:
Full adder is a combinational circuit that performs an addition operation on three binary digits. It produces a sum and a carry value, which are both binary digits.
A half adder has three inputs, generally labelled A, B, and Cin, and two outputs, the “sum” S and “carry flag” Cout.
S is the two-bit “XOR gate” of A, B, and Cin.
S= A xor B xor Cin
Cout=A.B+ (A xor B) Cin
Following is the truth table for a full adder is-
A B Cin S Cout
0 0 0 0 0
0 0 1 1 0
0 1 0 1 0
0 1 1 0 1
1 0 0 1 0
1 0 1 0 1
1 1 0 0 1
1 1 1 1 1
Dataflow code for full adder
library ieee;
use ieee.std_logic_1164.all;
entity fa is
port(a, b, c: in bit;
sum, carry : out bit);
end fa;
architecture full_adder of fa is
begin
sum <= a xor b xor c;
carry <= (a and b)or(b and c)or(c and a);
end full_adder;
Output waveform
Structural code for full adder
library ieee;
use ieee.std_logic_1164.all;
entity xor2 is
port(a,b:in bit;
y:out bit);
end xor2;
architecture e3 of xor2 is
begin
y<= a xor b;
end architecture;
entity and2 is
port(a,b:in bit;
y:out bit);
end and2;
architecture e2 of and2 is
begin
y<= a and b;
end architecture;
entity or3input is
port(d,e,f:in bit;
y:out bit);
end or3input;
architecture e1 of or3input is
begin
y<=d or e or f;
end architecture;
entity fastr is
port(a,b,c:in bit;
sum,carry:out bit);
end fastr;
architecture gate of fastr is
component xor2
port(a,b:in bit;
y:out bit);
end component;
component and2
port(a,b:in bit;
y:out bit);
end component;
component or3input
port(d,e,f:in bit;
y:out bit);
end component;
signal y1,x1,x2,x3:bit;
begin
u0:xor2 port map(a,b,y1);
u1:and2 port map(a,b,x1);
u2:and2 port map(b,c,x2);
u3:and2 port map(c,a,x3);
u4:xor2 port map(y1,c,sum);
u5:or3input port map(x1,x2,x3,carry);
end gate;
Output waveform
Behavioural code for full adder
library ieee;
use ieee.std_logic_1164.all;
entity fa is
port (a, b, c : in bit;
sum,carry: out bit);
end fa;
architecture fa_beh of fa is
begin
process (a,b,c)
begin
if a & b & c ="000"
then sum<='0'; carry<='0';
elsif a & b & c ="001"
then sum<='1'; carry<='0';
elsif a & b & c ="010"
then sum<='1'; carry<='0';
elsif a & b & c ="011"
then sum<='0'; carry<='1';
elsif a & b & c ="100"
then sum<='1'; carry<='0';
elsif a & b & c ="101"
then sum<='0'; carry<='1';
elsif a & b & c ="110"
then sum<='0'; carry<='1';
elsif a & b & c ="111"
then sum<='1'; carry<='1';
end if;
end process;
end fa_beh;
Output waveform
EXPERIMENT NO 4
AIM: To implement a 4X1 multiplexer in VHDL using dataflow, behavioral and structural style of modeling.
INTRODUCTION: In electronics, a multiplexer or mux is a device that performs multiplexing; it selects one of many analog or digital input signals and forwards the selected input into a single line. A multiplexer of 2n inputs has n select lines, which are used to select which input line to send to the output.
An electronic multiplexer makes it possible for several signals to share one device or resource, for example one A/D converter or one communication line, instead of having one device per input signal.
y<=((d0 and (not s0) and (not s1)) or(d1 and (not s1) and s0) or(d2 and
s1 and (not s0)) or (d3 and s0 and s1));
end gate;
Output waveform
Behavioral code for 4 to 1 multiplexer
TRUTH TABLE:
I/P O/P
S0 S1 Y
0 0 D0
0 1 D1
1 0 D2
1 1 D3
Behavioral code:
library ieee;
use ieee.std_logic_1164.all;
entity mux4beh is
port(d0,d1,d2,d3,s0,s1:in bit;
y:out bit);
end mux4beh;
architecture gate of mux4beh is
begin
process(d0,d1,d2,d3,s0,s1)
begin
if(s1='0' and s0='1')
then y<=d0;
elsif(s0='0' and s1='1')
then y<=d1;
elsif(s0='1'and s1='0')
then y<=d2;
elsif(s0='1' and s0='1')
then y<=d3;
end if;
end process;
end gate;
Output waveform
Structural code for 4*1 mux
library ieee;
use ieee.std_logic_1164.all;
entity not1 is
port(a:in bit;
y:out bit);
end not1;
architecture e1 of not1 is
begin
y<= not a;
end architecture;
entity and3 is
port(a,b,c:in bit;
y:out bit);
end and3;
architecture e2 of and3 is
begin
y<= a and b and c;
end architecture;
entity or4 is
port(a,b,c,d:in bit;
y:out bit);
end or4;
architecture e3 of or4 is
begin
y<= a or b or c or d;
end architecture;
entity mux4str is
port(d0,d1,d2,d3,s0,s1:in bit;
y:out bit);
end mux4str;
architecture gate of mux4str is
component not1
port(a:in bit;
y:out bit);
end component;
component and3
port(a,b,c:in bit;
y:out bit);
end component;
component or4
port(a,b,c,d:in bit; y:out bit);
end component;
signal x1,x2,x3,x4,x5,x6:bit;
begin
u0:not1 port map(s0,x1);
u1:not1 port map(s1,x2);
u2:and3 port map(x1,x2,d0,x3);
u3:and3 port map(x1,s1,d1,x4);
u4:and3 port map(x2,s0,d2,x5);
u5:and3 port map(s0,s1,d3,x6);
u6:or4 port map(x3,x4,x5,x6,y);
end gate;
Output waveform
EXPERIMENT NO 5
AIM: To implement a 3X8 decoder in VHDL using dataflow, behavioral and structural style of modeling.
INTRODUCTION: A decoder is a device which does the reverse of an encoder, undoing the encoding so that the original information can be retrieved. The same method used to encode is usually just reversed in order to decode.
In digital electronics, a decoder can take the form of a multiple-input, multiple-output logic circuit that converts coded inputs into coded outputs, where the input and output codes are different. e.g. n-to-2n, binary-coded decimal decoders. Enable inputs must be on for the decoder to function, otherwise its outputs assume a single "disabled" output code word. Decoding is necessary in applications such as data multiplexing, 7 segment display and memoryaddress decoding.
AIM: To implement a D, T, S-R, J-K Flip Flop using behavioural style of modeling.
INTRODUCTION:
D FLIP FLOP : The Q output always takes on the state of the D input at the moment of a rising clock edge (or falling edge if the clock input is active low).[7] It is called the D flip-flop for this reason, since the output takes the value of
the D input or Data input, and Delays it by one clock count. The D flip-flop can be interpreted as a primitive memory cell, zero-order hold, or delay line.
INTRODUCTION: The PARALLEL IN/PARALLEL OUT shift register is loaded with four bits simultaneously, in parallel.They are also clocked out simultaneously, in parallel.
PIPO CODE
library ieee;
use ieee.std_logic_1164.all;
entity dff is
port(d,clk:in bit;
q:out bit);
end dff;
architecture e1 of dff is
begin
process(d, clk)
begin
if clk='1' and clk'event then
q<=d;
end if;
end process;
end e1;
entity pipo is
port( a,b,c,d,clk:in bit;
q0,q1,q2,q3:out bit);
end pipo;
architecture e1 of pipo is
component dff
port(d,clk:in bit;
q:out bit);
end component;
begin
n1:dff port map(a,clk,q0);
n2:dff port map(b,clk,q1);
n3:dff port map(c,clk,q2);
n4:dff port map(d,clk,q3);
end e1;
OUTPUT:
PISO
INTRODUCTION: This configuration has the data input on lines D1 through D4 in parallel format. To write the data to the register, the Write/Shift control line must be held LOW. To shift the data, the W/S control line is brought HIGH and the registers are clocked. The arrangement now acts as a SISO shift register, with D1 as the Data Input. However, as long as the number of clock cycles is not more than the length of the data-string, the Data Output, Q, will be the parallel data read off in order.
PISO CODE
library ieee;
use ieee.std_logic_1164.all;
entity dff is
port(d,clk:in bit;
q:out bit);
end dff;
architecture e1 of dff is
begin
process(d, clk)
begin
if clk='1' and clk'event then
q<=d;
end if;
end process;
end e1;
entity cont is
port(outf1,x,control: in bit;
inpf2: out bit);
end cont;
architecture e1 of cont is
begin
process(x,control,outf1)
begin
if control='1' then
inpf2<=x;
else
inpf2<=outf1;
end if;
end process;
end architecture;
entity piso is
port( a,b,c,d,clk,control:in bit;
q0,q1,q2,q3:inout bit;
d0,d1,d2,d3: inout bit);
end piso;
architecture e1 of piso is
component dff
port(d,clk:in bit;
q:out bit);
end component;
component cont is
port(outf1,x,control: in bit;
inpf2: out bit);
end component;
begin
d0<=a;
n1:dff port map(a,clk,q0);
n2:cont port map(q0,b,control,d1);
n3:dff port map(d1,clk,q1);
n4:cont port map(q1,c,control,d2);
n5:dff port map(d2,clk,q2);
n6:cont port map(q2,d,control,d3);
n7:dff port map(d3,clk,q3);
end e1;
OUTPUT
Output when cntrl=1
Output when control=0
SIPO
INTRODUCTION: This configuration allows conversion from serial to parallel format. Data is
input serially, as described in the SISO section above. Once the data has been input, it may be either read off at each output simultaneously, or it can be shifted out and replaced.
SIPO CODE:
library ieee;
use ieee.std_logic_1164.all;
entity dff is
port(d,clk:in bit;
q:out bit);
end dff;
architecture e1 of dff is
begin
process(d, clk)
begin
if clk='1' and clk'event then
q<=d;
end if;
end process;
end e1;
entity sipo is
port( input,clk:in bit;
q0,q1,q2,q3:inout bit);
end sipo;
architecture e1 of sipo is
component dff
port(d,clk:in bit;
q:out bit);
end component;
begin
n1:dff port map(input,clk,q0);
n2:dff port map(q0,clk,q1);
n3:dff port map(q1,clk,q2);
n4:dff port map(q2,clk,q3);
end e1;
OUTPUT
Bcd
LIBRARY ieee;USE ieee.std_logic_1164.all;USE ieee.std_logic_arith.all;USE ieee.std_logic_unsigned.all;ENTITY binary_counter IS port( clk, reset:in bit; count:out std_logic_vector( 0 to 2));
END ENTITY binary_counter;
--ARCHITECTURE binary OF binary_counter ISsignal temp: std_logic_vector( 0 to 2):="000";BEGINprocess ( clk, reset)beginif reset='1' then temp<="000";else if clk='1' and clk'event then temp<= temp+ 1; end if; end if; end process; count<= temp;END ARCHITECTURE binary;