Professional Documents
Culture Documents
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
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;
begin
s<=a xor b;
c<= a and b;
end halfdata;
Output
use ieee.std_logic_1164.all;
entity halfbehv is
port(a,b:in bit;
s,c:out bit);
end halfbehv;
p1:process(a,b)
begin
if a & b ="00"
end if;
end halfbehv;
Output
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);
end ha;
Output
EXPERIMENT NO 3
A half adder has three inputs, generally labelled A, B, and Cin, and two outputs,
the “sum” S and “carry flag” Cout.
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
use ieee.std_logic_1164.all;
entity fa is
port(a, b, c: in bit;
end fa;
architecture full_adder of fa is
begin
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;
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);
end gate;
Output waveform
use ieee.std_logic_1164.all;
entity fa is
end fa;
architecture fa_beh of fa is
begin
process (a,b,c)
begin
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.
use ieee.std_logic_1164.all;
entity mux4 is
port(d0,d1,d2,d3,s0,s1:in bit;
y:out bit);
end mux4;
begin
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
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;
begin
process(d0,d1,d2,d3,s0,s1)
begin
then y<=d0;
then y<=d1;
elsif(s0='1'and s1='0')
then y<=d2;
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
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;
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
end component;
signal x1,x2,x3,x4,x5,x6:bit;
begin
end gate;
Output waveform
EXPERIMENT NO 5
Decoder behavioural
library ieee;
use ieee.std_logic_1164.all;
entity decoder is
end decoder;
begin
process(a)
begin
case a is
end case;
end process;
end behaviour;
OUTPUT:
Decoder dataflow
library ieee;
use ieee.std_logic_1164.all;
entity decoder is
end decoder;
begin
end deco1;
OUTPUT
Decoder in structural
entity notg is
port(a:in bit;
b: out bit);
end notg;
architecture e1 of notg is
begin
b<= not a;
end architecture;
entity andg is
port(a,b,c:in bit;
d: out bit);
end andg;
architecture e2 of andg is
begin
end architecture;
entity main is
end main;
component notg is
port(a:in bit;
b: out bit);
end component;
component andg is
port(a,b,c:in bit;
d: out bit);
end component;
signal x,y,z:bit;
begin
end architecture;
OUTPUT
EXPERIMENT 6
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.
Truth table:
Clock D Q Qprev
Rising
0 0 X
edge
Rising
1 1 X
edge
Non-Rising X Qprev
use ieee.std_logic_1164.all;
entity diff is
port(d,clk:in bit;
q,qbar:inout bit);
end diff;
begin
process(d,clk)
begin
then
q<= d;
qbar<= not d;
end if;
end process;
end behav;
Output
T FLIP FLOP
INTRODUCTION: If the T input is high, the T flip-flop changes state ("toggles") whenever the
clock input is strobed. If the T input is low, the flip-flop holds the previous value. This behavior is
described by the characteristic equation:
1 0 1 toggle 0 1 1 Complement
1 1 0 toggle 1 0 1 Complement
T FLIP FLOP CODE
library ieee;
use ieee.std_logic_1164.all;
entity tiff is
port(t,clk:in bit;
q,qbar:inout bit);
end tiff;
begin
process(t,clk)
begin
then
q<=not t;
qbar<=t;
end if;
end process;
end behav;
Output
SR FLIP FLOP
INTRODUCTION : The fundamental latch is the simple SR flip-flop, where S and R stand
for set and reset, respectively. It can be constructed from a pair of cross-coupled NAND or NORlogic
gates. The stored bit is present on the output marked Q.
Normally, in storage mode, the S and R inputs are both low, and feedback maintains the Q and Q outputs
in a constant state, with Q the complement of Q. If S is pulsed high while R is held low, then the Q output
is forced high, and stays high even after S returns low; similarly, if R is pulsed high while S is held low,
then the Q output is forced low, and stays low even after R returns low.
0 1 Q=0 0 1 1 0 reset
1 0 Q=1 1 0 0 1 set
use ieee.std_logic_1164.all;
entity srff is
port(s,r,clk:in bit;
q,qbar:inout bit);
end srff;
begin
process(s,r,clk)
begin
g:= s&r;
then
case g is
when "11"=> assert r/='1' and s/='1'report "invalid condition" severity error;
end case;
end if;
end process;
end behav;
Output
JK FLIP FLOP
INTRODUCTION: The JK flip-flop augments the behavior of the SR flip-flop (J=Set, K=Reset) by
interpreting the S = R = 1 condition as a "flip" or toggle command. Specifically, the combination J = 1, K =
0 is a command to set the flip-flop; the combination J = 0, K = 1 is a command to reset the flip-flop; and
the combination J = K = 1 is a command to toggle the flip-flop, i.e., change its output to the logical
complement of its current value. Setting J = K = 0 does NOT result in a D flip-flop, but rather, will hold the
current state. To synthesize a D flip-flop, simply set K equal to the complement of J. The JK flip-flop is
therefore a universal flip-flop, because it can be configured to work as an SR flip-flop, a D flip-flop, or a T
flip-flop.
0 1 0 reset 0 1 1 X Set
1 0 1 set 1 0 X 1 Reset
use ieee.std_logic_1164.all;
library ieee;
use ieee.std_logic_1164.all;
entity jkff is
port(j,k,clk:in bit;
q,qbar:inout bit);
end jkff;
begin
process(j,k,clk)
begin
s:= j&k;
then
case s is
end case;
end if;
end process;
end behav;
OUTPUT
EXPERIMENT 7
AIM: To design shift registers in VHDL using structural.
INTRODUCTION: These are the simplest kind of shift registers. 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
0 0 0 0
output. The bit on the far right (i.e. 'Data Out') is shifted out and lost.
1 0 0 0
The data are stored after each flip-flop on the 'Q' output, so there are four storage
0 1 0 0
'slots' available in this arrangement, hence it is a 4-Bit Register. To give an idea of
1 0 1 0
the shifting pattern, imagine that the register holds 0000 (so all storage slots are
1 1 0 1
empty). As 'Data In' presents 1,0,1,1,0,0,0,0 (in that order, with a pulse at 'Data
0 1 1 0
Advance' each time. This is called clocking or strobing) to the register, this is the
0 0 1 1
result. The left hand column corresponds to the left-most flip-flop's output pin, and so
0 0 0 1
on.
0 0 0 0
So the serial output of the entire register is 10110000 (). As you can see if we were to
continue to input data, we would get exactly what was put in, but offset by four 'Data Advance'
cycles. This arrangement is the hardware equivalent of a queue. Also, at any time, the whole
register can be set to zero by bringing the reset (R) pins high.
This arrangement performs destructive readout - each datum is lost once it been shifted out of
the right-most bit.
SISO CODE
entity dff is
port(d,clk:in bit;
q:out bit);
end dff;
architecture e1 of dff is
begin
process(d, clk)
begin
end if;
end process;
end e1;
entity siso is
qout:out bit);
end siso;
architecture e1 of siso is
component dff
port(d,clk:in bit;
q:out bit);
end component;
signal q0,q1,q2:bit;
begin
end e1;
OUTPUT:
PIPO
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
q<=d;
end if;
end process;
end e1;
entity pipo is
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
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
q<=d;
end if;
end process;
end e1;
entity cont is
port(outf1,x,control: in 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
q0,q1,q2,q3: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;
end component;
begin
d0<=a;
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
q<=d;
end if;
end process;
end e1;
entity sipo is
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
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 IS
signal temp: std_logic_vector( 0 to 2):="000";
BEGIN
process ( clk, reset)
begin
if 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;