VHDL
VHDL
Y (A nand B) = = A|B =
Y (A or B) = A + B
Y (A nor B) = =
Logic diagram and logic equation of NOT gate
Y (not A) = A’ =
Y (A exnor B) = = A’B’ + AB
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
entity ALLGATES_SOURCE is
Port ( A,B : in STD_LOGIC;
P, Q, R, S, T, U, V : out STD_LOGIC);
end ALLGATES_SOURCE;
begin
--- you have to remember the commands for boolean logic in VHDL as
shown below
P < = A and B;
Q < = A nand B;
R <= A or B;
S <= A nor B;
T <= not A;
U <= A xor B;
V <= A xnor B;
end dataflow;
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
entity and_or_top is
Port ( INA1 : in STD_LOGIC; -- AND gate input
INA2 : in STD_LOGIC; -- AND gate input
OA : out STD_LOGIC; -- AND gate output
end and_or_top;
entity and_or_top is
Port ( INO1 : in STD_LOGIC; -- OR gate input
INO2 : in STD_LOGIC; -- OR gate input
OO : out STD_LOGIC); -- OR gate output
end and_or_top;
The VHDL code for the full adder using the structural model:
-- fpga4student.com
-- FPGA projects, VHDL projects, Verilog projects
-- VHDL code for full adder
-- Structural code for full adder
library ieee;
use ieee.std_logic_1164.all;
entity Full_Adder_Structural_VHDL is
port(
X1, X2, Cin : in std_logic;
S, Cout : out std_logic
);
end Full_Adder_Structural_VHDL;
architecture structural of Full_Adder_Structural_VHDL is
signal a1, a2, a3: std_logic;
begin
a1 <= X1 xor X2;
a2 <= X1 and X2;
a3 <= a1 and Cin;
Cout <= a2 or a3;
S <= a1 xor Cin;
end structural;
The VHDL code for the full adder using the behavioral model:
library ieee;
use ieee.std_logic_1164.all;
entity fulladder is
port(a:in std_logic_vector(2 downto 0);
s,ca:out std_logic);
end fulladder;
A B Y3 Y2 Y1 Y0
0 0 0 0 0 1
0 1 0 0 1 0
1 0 0 1 0 0
1 1 1 0 0 0
From this truth table, we get the following logic equations for the outputs.
Y0 = A’B’
Y1 = A’B
Y2 = AB’
Y3 = AB
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
entity DECODER_SOURCE is
end DECODER_SOURCE;
architecture dataflow of DECODER_SOURCE is
begin
end dataflow;
flipflops
A Flip-flop is the basic element which is used to store information of one bit. Flip-flops have their content
change either at the rising or falling edge of the enable signal(usually the controlling clock signal).
Given below is a behavioral approach of writing the VHDL code for a SR Flip-flop.
library ieee;
use ieee. std_logic_1164.all;
use ieee. std_logic_arith.all;
use ieee. std_logic_unsigned.all;
entity SR-FF is
PORT( S,R,CLOCK,CLR,PRESET: in std_logic;
Q, QBAR: out std_logic);
end SR-FF;
elsif(PRESET='0')then
x:='1';
else
x:='1';
end if;
end if;
Q<=x;
QBAR<=not x;
end PROCESS;
end behavioral;
A D flip flop or Delay flip flop gives the same output as the input provided and thus the vhdl code
is much simpler.
Given below is a behavioral approach of writing the vhdl code for a D Flip-flop.
library ieee;
use ieee. std_logic_1164.all;
use ieee. std_logic_arith.all;
use ieee. std_logic_unsigned.all;
entity D-FF is
PORT( D,CLK,RST: in std_logic;
Q: out std_logic);
end D-FF;
begin
P1: process(RST,CLK)
begin
if(RST='1')then
Q<='0';
Given below is a behavioral approach of writing the VHDL code for a JK Flip-flop.
library ieee;
use ieee. std_logic_1164.all;
use ieee. std_logic_arith.all;
use ieee. std_logic_unsigned.all;
entity JK-FF is
PORT( J,K,CLK,PRST,CLR: in std_logic;
Q, QB: out std_logic);
end JK-FF;
elsif(PRST='0')then
x:='1';
end if;
end if;
Q<=x;
QB<=not x;
end PROCESS;
end behavioral;
The T in a t flip flop stands for toggle and this is exactly what this digital component does. It
simply toggles the value of a particular input. A basic not gate will solve the problem in the vhdl
code for this element.
Given below is a behavioral approach of writing the VHDL code for a T Flip-flop.
library ieee;
use ieee. std_logic_1164.all;
use ieee. std_logic_arith.all;
use ieee. std_logic_unsigned.all;
entity T-FF is
end T-FF;
begin
P1: process(CLK,PRST,RST)
variable x: std_logic;
begin
if(RST='0') then
x:='0';
x:='1';
x:= not x;
end if;
end if;
Q<=x;
end process;
end behavioral;