Documente Academic
Documente Profesional
Documente Cultură
ASSIGNMENT
1. Write a VHDL code for D , T and JK flip flop using behavioural modelling.
2. Write a VHDL code for 4 bit Johnson Counter
3. Write a VHDL code for MOD-16 up-counter.
4. Write a VHDL code for MOD-16 up-down counter.
1.Write a short note on Introduction to Hardware Descriptive
Languages and their softwares.
Hardware description language (HDL) is a specialized computer language used to program electronic
and digital logic circuits. The structure, operation and design of the circuits are programmable using
HDL. HDL includes a textual description consisting of operators, expressions, statements, inputs and
outputs. Instead of generating a computer executable file, the HDL compilers provide a gate map.
The gate map obtained is then downloaded to the programming device to check the operations of
the desired circuit. The language helps to describe any digital circuit in the form of structural,
behavioural and gate level.
The three common HDLs are Verilog, VHDL, and SystemC. The HDLs allow fast design and better
verification. In most of the industries, Verilog and VHDL are common. Verilog, one of the main
Hardware Description Language is used for designing all types of circuits. It consists of modules and
the language allows Behavioural, Dataflow and Structural Description. VHDL (Very High Speed
Integrated Circuit Hardware Description Language) is standardized by IEEE1164. The design is
composed of entities consisting of multiple architectures. SystemC is a language that consist a set of
C++classes and macros. It allows electronic system level and transaction modelling.
All the goals like power, throughput, latency (delay), test coverage, functionality and area
consumption required for a design can be known by using HDL. As a result, the designer can make
the necessary engineering tradeoffs and can develop the design in a better and efficient way.
Compiler for Universal Programming Language (CUPL) is generally used for logic device
programming. Handel-C is used for programming FPGA’s. Hardware Join Java (HJJ) helps in
reconfigurable computing applications. Impulse C, subset of C supports parallel programming. Just-
Another Hardware Description Language (JHDL) uses an object oriented programming
approach. LavaHDL helps in specifying layout of circuits mainly. Lola HDL is basically used for
synchronous digital circuits. M, is another HDL from Mentor Graphics. PALASM is used as a HDL for
Programmable Array Logic (PAL) devices. Finally System Verilog is an extension to Verilog.
HDLs for analog circuit design: The HDLs used for analog circuits include Analog Hardware
Description Language (AHDL), Spectre High Level Description Language (SpectreHDL), Verilog for
Analog and Mixed Signal (Verilog – AMS), VHDL with analog and mixed signal extension (VHDL –
AMS) and finally HDL-A. AHDL is most commonly used as a HDL language for analog circuits.
SpectreHDL is a high level description language that uses functional description text files to model
the behaviour of the systems. Verilog-AMS is an industry standard modelling language that contains
continuous an event driven simulators for analog, digital and analog/digital circuits. VHDL-AMS is
good for verifying complex analog, mixed signal and RF (radio frequency) circuits. HDL-A is a
proprietary HDL for mixed and analog circuits.
HDL for Printed Circuit Design: PHDL (Printed Circuit Board HDL) is generally used for modeling text
based schematics for PCBs. It allows generating massive buses and re-uses device definitions easily.
Benefits of HDL
The major benefit of the language is fast design and better verification. The Top-down design and
hierarchical design method allows the design time; design cost and design errors to be reduced.
Another major advantage is related to complex designs, which can be managed and verified easily.
HDL provides the timing information and allows the design to be described in gate level and register
transfer level. Reusability of resources is one of the other advantages
.
1. Write and simulate the VHDL code for logic gates.
And Gate :
entity aand1_gate is
Port ( a,b : in STD_LOGIC;
c : out STD_LOGIC);
end aand1_gate;
begin
c <= a and b;
end Behavioral;
RTL Schematic
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
entity or2_gate is
Port ( a,b : in STD_LOGIC;
c : out STD_LOGIC);
end or2_gate;
RTL Schematic
NOT GATE
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
entity not3_gate is
Port ( a : in STD_LOGIC;
b : out STD_LOGIC);
end not3_gate;
architecture Behavioral of not3_gate is
begin
b <= not a ;
end Behavioral;
RTL Schematic
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
entity nnand3_gate is
Port ( a,b : in STD_LOGIC;
c : out STD_LOGIC);
end nnand3_gate;
begin
c <= a nand b;
end Behavioral;
RTL Schematic
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
entity nor1_gate is
Port ( a ,b : in STD_LOGIC;
c : out STD_LOGIC);
end nor1_gate;
end Behavioral;
RTL Schematic
.
Test Bench WaveForm
XOR GATE:
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
entity xxor1_gate is
Port ( a,b : in STD_LOGIC;
c : out STD_LOGIC);
end xxor1_gate;
begin
c <= a xor b;
end Behavioral;
RTL Schematic
Test Bench WaveForm
end Behavioral;
RTL Schematic
Test Bench WaveForm
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
entity fa is
Port ( a : in STD_LOGIC;
b : in STD_LOGIC;
c : in STD_LOGIC;
s : out STD_LOGIC;
car : out STD_LOGIC);
end fa;
architecture Behavioral of fa is
begin
s<=a xor b xor c;
car<= (a and b) or (b and c) or (c and a);
end Behavioral;
RTL Schematic
entity full_adder1 is
Port ( x,y,z : in STD_LOGIC;
t,u : out STD_LOGIC);
end full_adder1;
end Behavioral;
RTL Schematic
entity hs_hs1 is
Port ( a : in STD_LOGIC;
b : in STD_LOGIC;
d : out STD_LOGIC;
bor : out STD_LOGIC);
end hs_hs1;
architecture Behavioral of hs_hs1 is
begin
d<= a xor b;
bor<= a and not b;
end Behavioral;
RTL Schematic
entity de is
Port ( a : in STD_LOGIC;
b : in STD_LOGIC;
c : in STD_LOGIC;
d : out STD_LOGIC;
bor : out STD_LOGIC);
end de;
architecture Behavioral of de is
begin
end Behavioral;
RTL Schematic
Test Bench WaveForm
entity RCA is
Port ( a : in STD_LOGIC_vector(3 downto 0);
b : in STD_LOGIC_vector(3 downto 0);
ci : in STD_LOGIC;
sum : out STD_LOGIC_vector(3 downto 0);
carry : out STD_LOGIC);
end RCA;
begin
FA1: full_add port map( A(0), B(0), ci, sum(0), s1);
FA2: full_add port map( A(1), B(1), s1, sum(1), s2);
FA3: full_add port map( A(2), B(2), s2, sum(2), s3);
FA4: full_add port map( A(3), B(3), s3, sum(3), carry);
end Behavioral;
RTL Schematic
2x4 Decoder
STRUCTURAL
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
entity decoderTFstr is
Port ( s : in STD_LOGIC_vector(1 downto 0);
y : out STD_LOGIC_vector(3 downto 0));
end decoderTFstr;
component not2 is
port(a : in std_logic;
c : out std_logic);
end component;
end Behavioral;
Structural Modelling (RTL)
BEHAVIORAL
library IEEE;
use IEEE.STD_LOGIC_1164.all;
entity decoder1 is
port(
a : in STD_LOGIC_VECTOR(1 downto 0);
b : out STD_LOGIC_VECTOR(3 downto 0) );
end decoder1;
architecture bhv of decoder1 is
begin
process(a)
begin
if (a="00") then
b <= "0001";
elsif (a="01") then
b <= "0010";
elsif (a="10") then
b <= "0100";
else
b <= "1000";
end if;
end process;
end behavioral;
Behavioral Modelling (RTL)
DATAFLOW
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
entity dec1 is
Port ( a : in STD_LOGIC_VECTOR (1 downto 0);
b: out STD_LOGIC_VECTOR (3 downto 0));
end dec1;
end Behavioral;
Data Flow Modelling(RTL)
STRUCTURAL
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
entity TEstr is
Port ( a : in STD_LOGIC_vector(2 downto 0);
b : out STD_LOGIC_vector(7 downto 0));
end TEstr;
begin
X1:and_gt port map(not a(2),not a(1),not a(0),b(0));
X2:and_gt port map(not a(2), not a(1),a(0),b(1));
X3:and_gt port map( not a(2), a(1),not a(0),b(2));
X4:and_gt port map( not a(2), a(1),a(0),b(3));
X5:and_gt port map( a(2), not a(1),not a(0),b(4));
X6:and_gt port map( a(2), not a(1),a(0),b(5));
X7:and_gt port map( a(2) ,a(1),not a(0),b(6));
X8:and_gt port map( a(2),a(1),a(0),b(7));
end Behavioral;
library IEEE;
use IEEE.STD_LOGIC_1164.all;
entity decoder2 is
port( a : in STD_LOGIC_VECTOR(2 downto 0);
b : out STD_LOGIC_VECTOR(7 downto 0) );
end decoder2;
architecture behavioral of decoder2 is
begin
process(a)
begin
if (a="000") then
b <= "00000001";
elsif (a="001") then
b <= "00000010";
elsif (a="010") then
b <= "00000100";
elsif (a="011") then
b <= "00001000";
elsif (a="100") then
b <= "00010000";
elsif (a="101") then
b <= "00100000";
elsif (a="110") then
b <= "01000000";
elsif (a="111") then
b <= "10000000";
end if;
end process;
end behvioral;
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
entity dec2 is
Port ( a : in STD_LOGIC_VECTOR (2 downto 0);
b: out STD_LOGIC_VECTOR (7 downto 0));
end dec2;
BEHAVIORAL
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
entity ETe is
Port ( a : in STD_LOGIC_vector(7 downto 0);
b : out STD_LOGIC_vector(2 downto 0));
end ETe;
DATAFLOW
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
entity ETen is
Port ( a : in STD_LOGIC_vector(7 downto 0);
b : out STD_LOGIC_vector(2 downto 0));
end ETen;
begin
b(0) <= a(4) or a(5) or a(6) or a(7);
b(1) <= a(2) or a(3) or a(6) or a(7);
b(2) <= a(1) or a(3) or a(5) or a(7);
end Behavioral;
Data Flow Modelling(RTL)
STRUCTURAL
entity enc8x3 is
Port ( p : out STD_LOGIC;
q : out STD_LOGIC;
r : out STD_logic;
s: in STD_LOGIC;
t: in STD_LOGIC;
u: in STD_LOGIC;
v: in STD_LOGIC;
w : in STD_LOGIC;
x : in STD_LOGIC;
y : in STD_LOGIC;
z : in STD_LOGIC);
end enc8x3;
STRUCTURAL
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
entity mux4x1 is
Port ( i0,i1,i2,i3 : in std logic;
s1 : in STD_LOGIC;
s0: in STD_LOGIC;
o: out std_logic);
end mux4x1;
BEHAVIORAL
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
entity mux is
Port ( I0,I1,I2,I3: in STD_LOGIC;
S0,S1 : in STD_LOGIC;
Y : out STD_LOGIC);
end mux;
architecture Behavioral of mux is
begin
process(I0,I1,I2,I3,S0,S1)
begin
if (S0='0'and S1='0')then
Y<= I0;
elsif (S0='0'and S1='1') then
Y<= I1;
elsif (S0='1'and S1='0') then
Y<= I2;
else
Y<= I3;
end if;
end process;
end Behavioral;
DATAFLOW
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
entity mux41 is
Port ( s : in STD_LOGIC_VECTOR (1 downto 0);
i : in STD_LOGIC_VECTOR (3 downto 0);
y : out STD_LOGIC);
end mux41;
y<= (not s(1) and not s(0) and i(0)) or (not s(1) and s(0) and i(1)) or (s(1) and not s(0) and i(2)) or (s(1)
and s(0) and i(3));
end Behavioral;
RTL Schematic
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
use IEEE.NUMERIC_STD.ALL;
entity priority_en is
Port ( a : in STD_ULOGIC_vector(3 downto 0);
e : in Std_logic;
b : out STD_LOGIC_vector(1 downto 0));
end priority_en;
begin
process (a,e)
begin
if (e ='1') then
if (std_match(a,"1---")) then
b <= "11";
elsif (std_match(a,"01--")) then
b <= "10";
elsif (std_match(a,"001-")) then
b <= "01";
elsif (std_match(a,"0001")) then
b <= "00";
end if;
else
b <= "00";
end if;
end process;
end Behavioral;
RTL Schematic
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
entity btg is
Port ( b : in STD_LOGIC_vector(3 downto 0);
g : out STD_LOGIC_vector(3 downto 0));
end gtb;
begin
g(3)<= g(3);
g(2)<= g(3) xor g(2);
g(1)<= g(2) xor g(1);
g(0)<= g(1) xor g(0);
end Behavioral;
RTL Schematic
Test Bench WaveForm
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
entity gtb is
Port ( g : in STD_LOGIC_vector(3 downto 0);
b : out STD_LOGIC_vector(3 downto 0));
end gtb;
begin
b(3)<= g(3);
b(2)<= g(3) xor g(2);
b(1)<= g(3) xor g(2)xor g(1);
b(0)<= g(3) xor g(2)xor g(1) xor g(0);
end Behavioral;
RTL Schematic
entity seven is
Port ( bcd : in STD_LOGIC_vector(3 downto 0);
seg7 : out STD_LOGIC_vector(6 downto 0));
end seven;
begin
process(bcd)
begin
if(bcd="0000") then
seg7<="1111110";
elsif(bcd="0001") then
seg7<="0000110";
elsif(bcd="0010") then
seg7<="1011011";
elsif(bcd="0011") then
seg7<="1001111";
elsif(bcd="0100") then
seg7<="0100111";
elsif(bcd="0101") then
seg7<="1101101";
elsif(bcd="0110") then
seg7<="1111101";
elsif(bcd="0111") then
seg7<="1000110";
elsif(bcd="1000") then
seg7<="1111111";
elsif(bcd="1001") then
seg7<="1101111";
else seg7<="0000000";
end if;
end process;
end Behavioral;
RTL Schematic
entity xs3 is
Port ( bcd : in STD_LOGIC_vector(3 downto 0);
exst : out STD_LOGIC_vector(3 downto 0));
end xs3;
architecture Behavioral of xs3 is
begin
process(bcd)
begin
if(bcd="0000") then
exst<="0011";
elsif(bcd="0001") then
exst<="0100";
elsif(bcd="0010") then
exst<="0101";
elsif(bcd="0011") then
exst<="0110";
elsif(bcd="0100") then
exst<="0111";
elsif(bcd="0101") then
exst<="1000";
elsif(bcd="0110") then
exst<="1001";
elsif(bcd="0111") then
exst<="1010";
elsif(bcd="1000") then
exst<="1011";
elsif(bcd="1001") then
exst<="1100";
end if;
end process;
end Behavioral;
RTL Schematic
ASSIGNMENT
1. Write a VHDL code for D , T and JK flip flop using behavioural modelling.
D Flip Flop –
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
entity Dff is
Port ( clk,D : in STD_LOGIC;
Q,Qnot : out STD_LOGIC);
end Dff;
begin
process(clk,D)
begin
if clk='0' and clk'event then
Q <= D;
Qnot <= not D;
end if;
end process;
end Behavioral;
RTL Schematic
Test Bench WaveForm
JK Flip Flop –
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
entity JKff is
Port ( J,K,clk : in STD_LOGIC;
Q,Qnot : out STD_LOGIC);
end JKff;
architecture Behavioral of JKff is
begin
process(clk)
variable temp: std_logic;
begin
if clk='0' and clk'event then
if (J='0' and K='0') then
temp:= temp;
elsif (J='1' and K='1') then
temp:= not temp;
elsif (J='0' and K='1') then
temp:= '0';
else
temp:= '1';
end if;
end if;
Q <= temp;
Qnot <= not temp;
end process;
end Behavioral;
RTL Schematic
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
entity Tff is
Port ( clk ,T : in STD_LOGIC;
Q,Qnot : out STD_LOGIC);
end Tff;
RTL Schematic
Test Bench WaveForm
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
entity johnson_cntr is
end johnson_cntr;
begin
process(clk,rst)
begin
if (rising_edge(clk)) then
if (rst='1') then
else
end if;
end process;
Q <= temp;
end Behavioral;
RTL Schematic
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
entity counter is
port( clk:in std_logic;
output:out std_logic_vector(3 downto 0)
);
end counter;
architecture Behavioral of counter is
component D_flipflop
port( clk:in std_logic;
D:in std_logic;
Q:out std_logic;
Qnot:out std_logic
);
end component;
signal temp:std_logic_vector(3 downto 0);
signal nottemp:std_logic_vector(3 downto 0) := "1111";
begin
F1: D_flipflop port map (clk,nottemp(0),temp(0),nottemp(0));
F2: D_flipflop port map (temp(0),nottemp(1),temp(1),nottemp(1));
F3: D_flipflop port map (temp(1),nottemp(2),temp(2),nottemp(2));
F4: D_flipflop port map (temp(2),nottemp(3),temp(3),nottemp(3));
output <= temp;
end Behavioral;
RTL Schematic
Test Bench WaveForm
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
entity mod16_ud_counter is
port( clk,ud : in std_logic;
output : out std_logic_vector(3 downto 0));
end mod16_ud_counter;
architecture Mixed of mod16_ud_counter is
component JK_flipflop
port( J,K,clk : in std_logic;
Q,Qnot : out std_logic);
end component;
signal temp:std_logic_vector(3 downto 0);
signal nottemp:std_logic_vector(3 downto 0);
signal upordown:std_logic_vector(3 downto 0);
begin
updown: process(ud)
begin
if ud = '1' then
upordown <= temp;
else
upordown <= nottemp;
end if;
end process;
F1: JK_flipflop port map ('1','1',clk,temp(0),nottemp(0));
F2: JK_flipflop port map ('1','1',upordown(0),temp(1),nottemp(1));
F3: JK_flipflop port map ('1','1',upordown(1),temp(2),nottemp(2));
F4: JK_flipflop port map ('1','1',upordown(2),temp(3),nottemp(3));
output <= temp;
end Mixed;
RTL Schematic