You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_arith.all;
use ieee.std_logic_unsigned.all;
entitybasic_gatesisport (
a : instd_logic;
b : instd_logic;
z_not : outstd_logic;
z_and : outstd_logic;
z_or : outstd_logic;
z_nand : outstd_logic;
z_nor : outstd_logic;
z_xor : outstd_logic
);
endentitybasic_gates;
architecturertlofbasic_gatesisbegin
z_not <=not a;
z_and <= a and b;
z_or <= a or b;
z_nand <= a nand b;
z_nor <= a nor b;
z_xor <= a xor b;
endarchitecturertl;
Latches
Simple Latch with Pos Gate
library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_arith.all;
use ieee.std_logic_unsigned.all;
entitybasic_latchisport (
d : instd_logic;
en : instd_logic; -- positive gate
q : outstd_logic
);
endentitybasic_latch;
architecturertlofbasic_latchisbegind_latch_proc : process (en) isbeginif (en ='1') then
q <= d;
endif;
endprocessd_latch_proc;
endarchitecturertl;
Latch with Async Set / Reset
library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_arith.all;
use ieee.std_logic_unsigned.all;
entitylatch_async_set_resetisport (
en : instd_logic; -- positive gate
set : instd_logic;
reset : instd_logic;
val : instd_logic_vector(3downto0);
d : instd_logic_vector(3downto0);
q : outstd_logic_vector(3downto0)
);
endentitylatch_async_set_reset;
architecturertloflatch_async_set_resetisbeginlatch_async_set_reset_proc : process (en) isbeginif (reset='1') then
q <=x"0";
elsif (set='1') then
q <= val;
elsif (en ='1') then
q <= d;
endif;
endprocesslatch_async_set_reset_proc;
endarchitecturertl;
Flip-Flops
Basic D FF
library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_arith.all;
use ieee.std_logic_unsigned.all;
entityd_ff_basicisport (
clk : instd_logic;
d : instd_logic;
q : outstd_logic
);
endentityd_ff_basic;
architecturertlofd_ff_basicisbeginbasic_d_ff : process (clk) isbeginifrising_edge(clk) then
q <= d;
endif;
endprocessbasic_d_ff;
endarchitecturertl;
D FF with Clock Enable
library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_arith.all;
use ieee.std_logic_unsigned.all;
entityd_ff_ceisport (
clk : instd_logic;
ce : instd_logic;
d : instd_logic;
q : outstd_logic
);
endentityd_ff_ce;
architecturertlofd_ff_ceisbegind_ff_ce_proc : process (clk) isbeginifrising_edge(clk) thenif (ce ='1') then
q <= d;
endif;
endif;
endprocessd_ff_ce_proc;
endarchitecturertl;
D FF with CE and Sync Reset
library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_arith.all;
use ieee.std_logic_unsigned.all;
entityd_ff_ce_resetisport (
clk : instd_logic;
ce : instd_logic;
reset : instd_logic;
d : instd_logic;
q : outstd_logic
);
endentityd_ff_ce_reset;
architecturertlofd_ff_ce_resetisbegind_ff_ce_reset_proc : process (clk) isbeginifrising_edge(clk) thenif (reset ='1') then
q <='0';
elsif (ce ='1') then
q <= d;
endif;
endif;
endprocessd_ff_ce_reset_proc;
endarchitecturertl;
D FF with CE and Sync Set / Reset
library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_arith.all;
use ieee.std_logic_unsigned.all;
entityd_ff_ce_reset_setisport (
clk : instd_logic;
ce : instd_logic;
reset : instd_logic;
set : instd_logic;
d : instd_logic_vector(3downto0);
val : instd_logic_vector(3downto0);
q : outstd_logic_vector(3downto0)
);
endentityd_ff_ce_reset_set;
architecturertlofd_ff_ce_reset_setisbegind_ff_ce_reset_set_proc : process (clk) isbeginifrising_edge(clk) thenif (reset ='1') then
q <=x"0";
elsif (set ='1') then
q <= val;
elsif (ce ='1') then
q <= d;
endif;
endif;
endprocessd_ff_ce_reset_set_proc;
endarchitecturertl;
D FF with CE & Async Set Reset
library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_arith.all;
use ieee.std_logic_unsigned.all;
entityd_ff_ce_async_reset_setisport (
clk : instd_logic;
ce : instd_logic;
reset : instd_logic;
set : instd_logic;
d : instd_logic_vector(3downto0);
val : instd_logic_vector(3downto0);
q : outstd_logic_vector(3downto0)
);
endentityd_ff_ce_async_reset_set;
architecturertlofd_ff_ce_async_reset_setisbeginbasic_d_ff : process (clk, reset, set) isbeginif (reset ='1') then
q <=x"0";
elsif (set ='1') then
q <= val;
elsifrising_edge(clk) thenif (ce ='1') then
q <= d;
endif;
endif;
endprocessbasic_d_ff;
endarchitecturertl;
MUX
4 to 1
library ieee;
use ieee.std_logic_1164.all;
entityfour_to_one_muxisport (
a : instd_logic;
b : instd_logic;
c : instd_logic;
d : instd_logic;
s : instd_logic_vector(1downto0);
o : outstd_logic
);
endentityfour_to_one_mux;
architecturertloffour_to_one_muxisbeginfour_to_one_mux_proc : process (a, b, c, d, s) isbegincase s iswhen"00"=> o <= a;
when"01"=> o <= b;
when"10"=> o <= c;
when"11"=> o <= d;
whenothers=> o <= a;
endcase;
endprocessfour_to_one_mux_proc;
endarchitecture;
2 to 1
library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_arith.all;
use ieee.std_logic_unsigned.all;
entitytwo_to_one_muxisport (
a : instd_logic;
b : instd_logic;
s : instd_logic;
o : outstd_logic
);
endentitytwo_to_one_mux;
architecturertloftwo_to_one_muxisbegintwo_to_one_mux_proc : process (a, b, s) isbeginif (s ='1') then
o <= a;
else
o <= b;
endif;
endprocesstwo_to_one_mux_proc;
endarchitecture;
2 to 1 (VHDL-2008)
-- REQUIRES VHDL-2008 to be enabledlibrary ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_arith.all;
use ieee.std_logic_unsigned.all;
entitytwo_to_one_mux_withisport (
a : instd_logic;
b : instd_logic;
s : instd_logic;
o : outstd_logic
);
endentitytwo_to_one_mux_with;
architecturertloftwo_to_one_mux_withisbegintwo_to_one_mux_with_proc : process (a, b, s) isbeginwith s select o <=
a when'1',
b whenothers;
endprocesstwo_to_one_mux_with_proc;
endarchitecturertl;
Decoders
3 to 8 Decoder
library ieee;
use ieee.std_logic_1164.all;
entitythree_to_eight_dcdisport (
s : instd_logic_vector(2downto0);
res : outstd_logic_vector(7downto0)
);
endentitythree_to_eight_dcd;
architecturertlofthree_to_eight_dcdisbeginthree_to_eight_dcd_proc : process (s) isbegincase s iswhen"001"=> res <=b"0000_0001";
when"010"=> res <=b"0000_0010";
when"011"=> res <=b"0000_0100";
when"100"=> res <=b"0000_1000";
when"101"=> res <=b"0001_0000";
when"110"=> res <=b"0010_0000";
when"111"=> res <=b"0100_0000";
whenothers=> res <=b"0000_0000";
endcase;
endprocessthree_to_eight_dcd_proc;
endarchitecture;
Arithmetic Operations
Adder (without Carry)
library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_arith.all;
use ieee.std_logic_unsigned.all;
entityaddisport (
a : instd_logic_vector(3downto0);
b : instd_logic_vector(3downto0);
sum : outstd_logic_vector(3downto0)
);
endentityadd;
architecturertlofaddisbegin
sum <= a + b;
endarchitecturertl;
Subtractor
library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_arith.all;
use ieee.std_logic_unsigned.all;
entitysubisport (
a : instd_logic_vector(3downto0);
b : instd_logic_vector(3downto0);
diff : outstd_logic_vector(3downto0)
);
endentitysub;
architecturertlofsubisbegin
diff <= a - b;
endarchitecturertl;
Shifters
Shift left by 1-bit
library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_arith.all;
use ieee.std_logic_unsigned.all;
entityslisport (
clk : instd_logic;
di : instd_logic_vector(3downto0);
do : outstd_logic_vector(3downto0)
);
endentitysl;
architecturertlofslisbeginprocess (clk) isbeginifrising_edge(clk) then
do <= di(2downto0) &'0';
endif;
endprocess;
endarchitecturertl;
Shift right by 1-bit
library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_arith.all;
use ieee.std_logic_unsigned.all;
entityslisport (
clk : instd_logic;
di : instd_logic_vector(3downto0);
do : outstd_logic_vector(3downto0)
);
endentitysl;
architecturertlofslisbeginprocess (clk) isbeginifrising_edge(clk) then
do <='0'& di(3downto1);
endif;
endprocess;
endarchitecturertl;