VHDL From Botros
VHDL From Botros
VHDL From Botros
component xor2
--The above statement is a component statement
port(I1, I2 : in bit;
O1 : out bit);
end component;
component and2
port(I1, I2 : in bit;
O1 : out bit);
end component;
begin
X1 : xor2 port map (a, b, sum);
A1 : and2 port map (a, b, cout);
end struct_exple;
entity halfadder is
port (
a: in bit;
b: in bit;
s: out bit;
c: out bit);
end halfadder;
architecture HA_DtFl of halfadder is
begin
s <= a xor b;
c <= a and b;
end HA_DtFl;
DATA FLOW
mutiplexer
multiplier
entity D_Latch is
port (D, E : in std_logic;
Q, Qbar : buffer std_logic);
-- Q and Qbar are declared as buffer because they act as
--both input and output, they appear on the right and left
--hand side of signal assignment statements. inout or
-- linkage could have been used instead of buffer.
end D_Latch;
begin
if Gbar = '0' then
if SEL = '1' then
temp := B;
else
temp := A;
end if;
Y <= temp;
else
Y <= 'Z';
end if;
end process;
end MUX_bh;
VHDL 2x1 Multiplexer Using ELSE-IF
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
entity MUXBH is
port (A, B, SEL, Gbar : in std_logic;
Y : out std_logic);
end MUXBH;
architecture MUX_bh of MUXBH is
begin
process (SEL, A, B, Gbar)
variable temp : std_logic;
begin
if (Gbar = '0') and (SEL = '1') then
temp := B;
elsif (Gbar = '0') and (SEL = '0')then
temp := A;
else
temp := 'Z'; -- Z is high impedance.
end if;
Y <= temp;
end process;
end MUX_bh;
D-LATCH
entity Dltch_sig is
port (d, E : in bit; Q : buffer bit; Qb : out bit);
--Q is declared as a buffer because it is an input/output
--signal; it appears on both the left and right
-- hand sides of assignment
--statements.
end Dltch_sig;
architecture DL_sig of Dltch_sig is
begin
process (d, E)
begin
if E = '1' then
Q <= d; -- signal assignment
Qb <= not Q; -- signal assignment
end if;
end process;
end DL_sig;
JK FLIPFLOP
VHDL Positive Edge-Triggered JK Flip-Flop Using Case
library ieee;
use ieee.std_logic_1164.all;
entity JK_FF is
port(JK : in bit_vector (1 downto 0);
clk : in std_logic; q, qb : out bit);
end JK_FF;
end JK_BEH;
VHDL 3-Bit Binary Counter Case Statement Description
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
entity CT_CASE is
port (clk, clr : in std_logic;
q : buffer std_logic_vector (2 downto 0));
end CT_CASE;
architecture ctr_case of CT_CASE is
begin
ctr : process(clk)
variable temp : std_logic_vector (2 downto 0) := "101";
--101 is the initial value, so the counter starts from 110
begin
if rising_edge (clk) then
if clr = '0' then
case temp is
when "000" => temp := "001";
when "001" => temp := "010";
when "010" => temp := "011";
when "011" => temp := "100";
when "100" => temp := "101";
when "101" => temp := "110";
when "110" => temp := "111";
when "111" => temp := "000";
when others => temp := "000";
end case;
else
temp := "000";
end if;
end if;
q <= temp;
end process ctr;
end ctr_case;
struct
VHDL Half Adder Descri with its component
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
entity xor2 is
port(I1, I2 : in std_logic; O1 : out std_logic);
end xor2;
architecture Xor2_0 of xor2 is
begin
O1 <= I1 xor I2;
end Xor2_0;
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
entity and2 is
port (I1, I2 : in std_logic; O1 : out std_logic);
end and2;
architecture and2_0 of and2 is
begin
O1 <= I1 and I2;
end and2_0;
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
entity half_add is
port (a, b : in std_logic; S, C : out std_logic);
end half_add;
architecture HA_str of half_add is
component xor2
port (I1, I2 : in std_logic; O1 : out std_logic);
end component;
component and2
port (I1, I2 : in std_logic; O1 : out std_logic);
end component;
begin
X1 : xor2 port map (a, b, S);
A1 : and2 port map (a, b, C);
end HA_str;
VHDL Code for Several Gates
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
entity bind1 is
port (I1 : in std_logic; O1 : out std_logic);
end bind1;
architecture inv_0 of bind1 is
begin
O1 <= not I1; --This is an inverter with zero delay
end inv_0;
architecture inv_7 of bind1 is
begin
O1 <= not I1 after 7 ns; --This is an inverter with a 7-ns delay
end inv_7;
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
entity bind2 is
port (I1, I2 : in std_logic; O1 : out std_logic);
end bind2;
architecture xor2_0 of bind2 is
begin
O1 <= I1 xor I2; --This is exclusive-or with zero delay.
end xor2_0;
architecture and2_0 of bind2 is
begin
O1 <= I1 and I2; --This is a two input and gate with zero delay.
end and2_0;
architecture and2_7 of bind2 is
begin
O1 <= I1 and I2 after 7 ns; -- This is a two input and gate with 7-ns delay.
end and2_7;
architecture or2_0 of bind2 is
begin
O1 <= I1 or I2; -- This is a two input or gate with zero delay.
end or2_0;
architecture or2_7 of bind2 is
begin
O1 <= I1 or I2 after 7 ns; -- This is a two input or gate with 7-ns delay.
end or2_7;
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
entity bind3 is
port (I1, I2, I3 : in std_logic; O1 : out std_logic);
end bind3;
architecture and3_0 of bind3 is
begin
O1 <= I1 and I2 and I3; -- This is a three input and gate with zero delay.
end and3_0;
architecture and3_7 of bind3 is
begin
O1 <= I1 and I2 and I3 after 7 ns; --This is a three input and gate with 7-ns delay.
end and3_7;
architecture or3_0 of bind3 is
begin
O1 <= I1 or I2 or I3; --This is a three input or gate with zero delay.
end or3_0;
architecture or3_7 of bind3 is
begin
O1 <= I1 or I2 or I3 after 7 ns; --This is a three input or gate with 7-ns delay.
end or3_7;
MUX
component or2
port (I1, I2 : in std_logic; O1 : out std_logic);
end component;
component Inv
port (I1 : in std_logic; O1 : out std_logic);
end component;
entity decoder2x4 is
port (I : in std_logic_vector(1 downto 0); Enable : in
std_logic; D : out std_logic_vector (3 downto 0));
end decoder2x4;
begin
HA1 : HA port map (y, cin, s0, c0);
HA2 : HA port map (x, s0, sum, c1);
r1 : or2 port map (c0, c1, carry);
end full_add;
SR LATCH
end SR_latch;
architecture SR_strc of SR_latch is
--Some simulators would not allow mapping between
--buffer and out. In this
--case, change all out to buffer.
component nor2
port (I1, I2 : in std_logic; O1 : out std_logic);
end component;
for all : nor2 use entity work.bind2 (nor2_0);
begin
n1 : nor2 port map (S, Q, Qbar);
n2 : nor2 port map (R, Qbar, Q);
end SR_strc;
ripple carry adder