Académique Documents
Professionnel Documents
Culture Documents
Logic Diagram:
Full Adder
A 0 1 0 1 0 1 0 1
Inputs B 0 0 1 1 0 0 1 1
Cin 0 0 0 0 1 1 1 1
Outputs Cout 0 0 0 1 0 1 1 1
S 0 1 1 0 1 0 0 1
1|Page
Full Subtractor
A 0 0 0 0 1 1 1 1
B 0 0 1 1 0 0 1 1
BorIN 0 1 0 1 0 1 0 1
D 0 1 1 0 1 0 0 1
BorOUT 0 1 1 1 0 0 0 1
2|Page
ENTITY full_adder IS PORT(A,B,Ci:instd_logic; S,Co:outstd_logic); END ENTITY full_adder; ARCHITECTURE DF OF full_adder IS BEGIN S<= A XOR (B XOR Ci); Co<= (A AND B) OR (Ci AND B) OR (Ci AND A) ; END ARCHITECTURE DF;
FULL SUBTRACTOR
4|Page
PROGRAM-2
Aim: Write down VHDL program for 4 to 1 Multiplexer using Behavioural Model, Structural
Model and Data Flow Model.
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 Inputs S1 0 0 1 1
5|Page
Output Y I0 I1 I2 I3
S0 0 1 0 1
entity mux_4to1 is Port ( I0 : in std_logic; I1 : in std_logic; I2 : in std_logic;I3 : in std_logic; S0 : in std_logic; S1 : in std_logic; y : out std_logic); end mux_4to1; architecturemux_behavioral of mux_4to1 is begin process(I0,I1,I2,I3,S0,S1) begin if(S1='0' and S0='0') then y<=I0; elsif(S1='0' and S0='1') then y<=I1; elsif(S1='1' and S0='0') then y<=I1; elsif(S1='1' and S0='1') then y<=I1; end if; end process; endmux_behavioral;
6|Page
signalS0bar,S1bar,u,v,w,x,z: std_logic;
begin a0: and3 port map(I0,S1bar,S0bar,u); a1: and3 port map(I1,S1bar,S0,v); a2: and3 port map(I2,S1,S0bar,w); a3: and3 port map(I3,S1,S0,x); a4: or4 port map(u,v,w,x,y);
endmux_structure;
8|Page
OUTPUT: MUX4X1
9|Page
PROGRAM-3
Aim:Write a vhdl code for 2 to 4 decoder using structural , behavioral and Data Flow model System Description:
A decoder is a device which does the reverse operation 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. It is a combinational circuit that converts binary information from n input lines to a maximum of 2n unique output lines. 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. Decoding is necessary in applications such as data multiplexing, 7 segment display and memory address decoding.
Logic Diagram
TRUTH TABLE:
Enable X1 X0 Y0 Y1 Y2 Y3 1 1 1 1 0 0 0 1 1 x 0 1 0 1 x 1 0 0 0 0 0 1 0 0 0 0 0 1 0 0 0 0 0 1 0
10 | P a g e
(B)Data Flow
library IEEE; use IEEE.STD_LOGIC_1164.ALL;
11 | P a g e
use IEEE.STD_LOGIC_ARITH.ALL; use IEEE.STD_LOGIC_UNSIGNED.ALL; entity decoder_2_4 is port (X1,X0 Enable : in std_logic ; Y : out std_logic_vector(3 downto 0) ); end decoder_2_4;
architecture df of decoder_2_4 is begin Y(0) <= Enable and (not X0 and not X1); Y(1) <= Enable and (X0 and not X1); Y(2) <= Enable and (not X0 and X1); Y(3) <= Enable and (X0 and X1); end df;
(C) Structural
library IEEE; use IEEE.STD_LOGIC_1164.ALL; use IEEE.STD_LOGIC_ARITH.ALL; use IEEE.STD_LOGIC_UNSIGNED.ALL;
entity decoder_2_4 is port (X0,X1, en : in bit ; Y : out bit_vector(3 downto 0) ); end decoder_2_4;
component INV
12 | P a g e
component AND3 port (In1, In2 , In3: in bit ; Out1 : out bit ); end component;
begin I0 : INV port map (X0, X0_sig); I1 : INV port map (X1, X1_sig); U3 : AND3 port map (X0_sig, X1_sig,en, Y(0) ); U4 : AND3 port map (X0, X1_sig,en, Y(1) ); U5 : AND3 port map (X0_sig, X1,en, Y(2) ); U6 : AND3 port map (X0, X1 ,en, Y(3) );
13 | P a g e
Output:DECODER2TO4
14 | P a g e
PROGRAM-4
AIM:
Write down VHDL program for 1-bit comparator using Behavioural Model and Data Flow Model
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.
Logic Diagram:
TRUTH TABLE: A 0 0 1 1
15 | P a g e
B 0 1 0 1
RESULT(0) 0 0 1 0
RESULT(1) 1 0 0 1
RESULT(2) 0 1 0 0
"010"when(A=B)else
"001";
end dataflow;
(b)BEHAVIORAL
library IEEE; use IEEE.STD_LOGIC_1164.ALL;
16 | P a g e
architectureBehavioral of comparator is
begin process(A,B)
begin if A>B then RESULT<=100; elsif A<B then RESULT<=001; elsif A=B then RESULT <=010; end if; end process; endBehavioral;
17 | P a g e
18 | P a g e
PROGRAM-5 Aim: Write a VHDL programme for a 4bit comparator using behavioural model
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.
Logic Diagram:
19 | P a g e
VHDL CODE:
library IEEE; use IEEE.STD_LOGIC_1164.ALL; use IEEE.STD_LOGIC_ARITH.ALL; use IEEE.STD_LOGIC_UNSIGNED.ALL; entity comp4 is port ( a,b: in bit_vector(3 downto 0); -- deines a vector of 4 values a3 to a0, b3 to b0 aeqb,agtb,altb: end comp4; out bit);
architecturebehavioral of comp4 is -- the architecture is being described by its behavior begin comp: process (a,b) begin if a=b then aeqb<= '1'; agtb<='0'; altb<='0'; else if a<b then aeqb<= '0'; agtb<='0'; altb<='1'; else aeqb<= '0'; agtb<='1'; altb<='0'; end if; end if; end process comp; endbehavioral; -- comp is an optional label identifying the process
20 | P a g e
21 | P a g e
PROGRAM-6 AIM:
Write down VHDL program for 3-bit Binary to gray Code Converter using Behavioural Model,and Data Flow Model
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:
22 | P a g e
VHDL CODE
(a) BEHAVIORAL
library IEEE; use IEEE.STD_LOGIC_1164.ALL;
entitybinary_to_gray is Port ( b0 : in STD_LOGIC; b1 : in STD_LOGIC; b2 : in STD_LOGIC; b3 : in STD_LOGIC; g0 : out STD_LOGIC; g1 : out STD_LOGIC; g2 : out STD_LOGIC; g3: out STD_LOGIC ); endbinary_to_gray;
architectureBehavioral of binary_to_gray is begin g3<=b3; g2<=(b3 xor b2); g1<=(b2 xor b1); g0<=(b1 xor b0); endBehavioral;
23 | P a g e
(b)DATAFLOW
entitybinary_to_gray is Port ( B0 : in STD_LOGIC; B1 : in STD_LOGIC; B2: in STD_LOGIC; G0: out STD_LOGIC; G1: out STD_LOGIC; G2: out STD_LOGIC); endbinary_to_gray;
architecture dataflow of binary_to_gray is begin G2<=B2; G1<=B2 XOR B1; G0<=B1 XOR B0; end dataflow;
24 | P a g e
25 | P a g e
PROGRAM-7
Aim: Write down VHDL program for BCD to Seven Segment Decoder using Behavioral
Model, Structural Model and Data Flow Model.
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:
Bcd(3) Bcd(2) Bcd(1) Bcd(0) 0 0 0 0 0 0 0 0 1 1 0 0 0 0 1 1 1 1 0 0 0 0 1 1 0 0 1 1 0 0 0 1 0 1 0 1 0 1 0 1 A 1 0 1 1 0 1 1 1 1 1 B 1 1 1 1 1 0 0 1 1 1 C 1 1 0 1 1 1 1 1 1 1 D 1 0 1 1 0 1 1 0 1 1 E 1 0 1 0 0 0 1 0 1 0 F 1 0 0 0 1 1 1 0 1 1 G 0 0 1 1 1 1 0 0 1 1
26 | P a g e
entity seven_segment_display is Port ( clk : in std_logic; bcd : in std_logic_vector;(3 downto 0); segment7 : out std_logic(6 downto 0) ); end seven_segment_display;
architecture Behavioral of seven_segment_display is begin process (clk,bcd) begin if(clkevent and clk=1) then case bcd is when 0000=>segment7<=1111110; when 0001=>segment7<=0110000; when 0010=>segment7<=1101101; when 0011=>segment7<=1111001; when 0100=>segment7<=0110011; when 0101=>segment7<=1011011;
27 | P a g e
when 0110=>segment7<=1011111; when 0111=>segment7<=1110000; when 1000=>segment7<=1111111; when 1001=>segment7<=1111011; when others =>segment7<=0000000; end case; end if; end process; end Behavioral;
entity seven_seg_decoder is Port( bcd: in std_logic_vector(0 to 3); led: out std_logic_vector(0 to 6)); end seven_seg_decoder;
begin led<=1111110 when bcd=0000 else 0110000 when bcd=0001 else 1101101 when bcd=0010 else
28 | P a g e
1111001 when bcd=0011 else 0110011 when bcd=0100 else 1011011 when bcd=0110 else 1110000 when bcd=0111 else 1111111 when bcd=1000 else 1111011 when bcd=1001 ; end seven_dataflow;
architecture seven_structure of seven_segment_decoder is component decoder port(input: in bit_vector (0 to 3); output:out bit_vector(0 to 6)); end component
29 | P a g e
30 | P a g e
PROGRAM-8
AIM: Write down VHDL program SR flip flop and JK flip flop SYSTEM DESCRIPTION:
In electronics, a flip-flop or latch is a circuit that has two stable states and can be used to store state information. A flip-flop is a bistablemultivibrator. The circuit can be made to change state by signals applied to one or more control inputs and will have one or two outputs. It is the basic storage element in sequential logic. Flip-flops and latches are a fundamental building block of digital electronics systems used in computers, communications, and many other types of systems.
LOGIC CIRCUITS:
31 | P a g e
VHDL Code:
(a)
SR Flip Flop
process(pr,clk,cr,s,r) begin if(pr='0') then q<='1'; qbar<='0'; elsif(cr='0')then q<='0'; qbar<='1'; elsif(clk='1' and clk'event) then if(S='0' and R='0') then q<=q; qbar<=qbar; elsif(s='0' and r='1') then q<='0'; qbar<='1';
32 | P a g e
elsif(S='1' and R='0') then q<='1'; qbar<='1'; end if; end if; end process; END ARCHITECTURE behavi;
ENTITY jk IS port(J, K,pr,clr,clk: in std_logic; Q, Qbar:outstd_logic); END ENTITY jk; -ARCHITECTURE struct OF jk IS signalqss: std_logic;
33 | P a g e
qss<=qss; elsif(J='0' and K='1') then qss<='0'; elsif(J='0' and K='1')then qss<='1'; elsif(J='1' and K='1')then qss<=not qss; end if; end if; end process; Q<=qss; Qbar<=not qss;
34 | P a g e
OUTPUT:
SR Flip Flop
JK Flip Flop
35 | P a g e
PROGRAM-9
AIM:
Write down VHDL program for bi-directional Shift Register
SYSTEM DESCRIPTION:
In digital circuits, a shift register is a cascade of flip flops, sharing the same clock, in which the output of each flip-flop is connected to the "data" input of the next flip-flop in the chain, resulting in a circuit that shifts by one position the "bit array" stored in it, shifting in the data present at its input and shifting out the last bit in the array, at each transition of the clock input. More generally, a shift register may be multidimensional, such that its "data in" and stage outputs are themselves bit arrays: this is implemented simply by running several shift registers of the same bit-length in parallel. A bidirectional shift register is one in which the data can be shifted either left or right. It can be implemented by using gate logic that enables the transfer of a data bit from one stage to the next stage to the right or to the left, depending on the level of control line.
LOGIC DIAGRAM:
36 | P a g e
VHDL Code:
-ARCHITECTURE shift OF bidirect IS signal s1,s2,s3:std_logic; BEGIN process (pr,dr,M,clr,clk) begin if (pr='0')then s1<='1'; s2<='1'; s3<='1'; y<='1'; elsif (clr='0') then s1<='0'; s2<='0'; s3<='0'; y<='0'; elsif(clk='1' and clk'event) then if(M='0') then s1<=dr; s2<=s1; s3<=s2;
37 | P a g e
y<=s3; elsif(M='1') then s3<=dr; s2<=s3; s1<=s2; y<=s1; end if ; end if; end process;
38 | P a g e
39 | P a g e
PROGRAM-10
AIM:
Write down VHDL program for 4 bit UP/DOWN Counter
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.
LOGIC DIAGRAM:
40 | P a g e
VHDL Code:
Library IEEE; use IEEE.STD_LOGIC_1164.ALL; use IEEE.STD_LOGIC_ARITH.ALL; use IEEE.STD_LOGIC_UNSIGNED.ALL; entityupdowncount is port(reset,c,clk:in std_logic; Q:inoutstd_logic_vector(3 downto 0)); endupdowncount; architectureBehavioral of updowncount is begin process(reset,c,clk,s) begin if reset='1' then Q<="0000"; elsif c='1' and rising_edge(clk) then Q<=Q+1; elsif c='0' and rising_edge(clk) then Q<=Q-1; end if; end process; endBehavioral ;
41 | P a g e
42 | P a g e