VHDL Tutorial: Nand Gates
VHDL Tutorial: Nand Gates
VHDL Tutorial: Nand Gates
NAND GATES:
library ieee;
use ieee.std_logic_1164.all;
use ieee.numeric_std.all; signed and unsigned
entity xorCircuit is
port (x1, x2: in std_logic;
f : out std_logic); To declare the input and output
end xorCircuit;
begin
S <= ‘1’; assign 1 to signal S
M <= "10110011"; assign 10110011 to signal M --- MSB = M(7) = ‘1’; LSB = M(0) = ‘1’
f <= (x1 nand (x1 nand x2)) nand (x2 nand (x1 nand x2));
In a proper way:
g <= x1 nand x2;
a <= x1 nand g;
b <= x2 nand g;
f <= a nand b;
end behavioral;
Assume the signals in the XOR circuit VHDL model have the following initial
values: x1=1, x2=1, g=0, a=1, b=1, and f=0.
FORM:
….
<valueN> when <choiceN >,
2 To 4 Decoder:
library ieee;
use ieee.std_logic_1164.all;
entity dec2to4 is
port (w : in std_logic_vector(1 downto 0);
En : in std_logic;
y : out std_logic_vector(3 downto 0));
end dec2to4;
architecture behavioral of dec2to4 is
signal En_w : std_logic_vector (2 downto 0);
begin
FORM:
…..
4 To 2 encoder:
library ieee;
use ieee.std_logic_1164.all;
entity priority is
port (w : in std_logic_vector (3 downto 0);
y : out std_logic_vector (1 downto 0);
z : out std_logic);
end priority;
architecture behavioral of priority is
begin
y <= "11" when w(3) = '1' else
"10" when w(2) = '1' else
"01" when w(1) = '1' else
"00";
z <= '0' when w = "0000" else '1';
end behavioral;
PROCESS:
Like c++ ; statements will be evaluated sequentially in the order in which they are written, and
it is concurrent (vhdl statement outside the process run in the same time with the process):
entity dummy is
end dummy;
architecture var of dummy is
signal trigger, sum : integer := 0; -- @t0
begin begin arch
p1: process (trigger) name
variable var1 : integer := 1; -- @t0 declaring
variable var2 : integer := 2; -- @t0 variables
variable var3 : integer := 3; -- @t0 of the process
entity dummy is
end dummy;
architecture sig of dummy is
signal trigger, sum : integer := 0; -- @t0
signal sig1: integer := 1; -- @t0
signal sig2: integer := 2; -- @t0
signal sig3: integer := 3; -- @t0
begin
p1: process (trigger)
begin
sig1 <= sig2 + sig3; -- =2+3=5 @t0+dt
sig2 <= sig1; -- =1 @t0+dt
sig3 <= sig2; -- =2 @t0+dt
sum <= sig1+sig2+sig3; -- =1+2+3=6 @t0+dt
end process;
end sig;
IF STATEMENT:
if <expression> then
sequential statements
sequential statements
else
sequential statements
end if;
library ieee;
use ieee.std_logic_1164.all;
entity priority is
port (w : in std_logic_vector (3 downto 0);
y : out std_logic_vector (1 downto 0);
z : out std_logic);
end priority;
begin
end if;
end process;
library ieee;
use ieee.std_logic_1164.all;
entity seg7 is
port (bcd: in std_logic_vector (3 downto 0);
case bcd is
when "0000" => leds <= "1111110"; when bcd is 0000 so that led is 1111110 y3ne 0
end case;
end process;
end beh;
FOR LOOP:
sequential statements;
library ieee;
use ieee.std_logic_1164.all;
entity xor8 is
port (a, b: in std_logic_vector (7 downto 0);
y: out std_logic_vector (7 downto 0));
end xor8;
begin
begin
end beh;
WHILE LOOP:
sequential statements;
process (A)
begin
Z <= "0000";
I := 0;
while (I <= 3) loop
if (A = I) then
Z(I) <= '1';
end if;
I := I + 1;
end loop;
end process;
NUMERIC LIBRARY:
WAIT STATMENT:
process (A, B, C, D)
wait on sensitivity_list; begin
wait until boolean_expression; Z <= not ((A and B) or (C and D));
wait for time_expression; end process;
wait;
process
begin
wait on DATA;
wait until data to take its value
SIG_A <= DATA;
wait for 0 ns;
wait 0 ns so SIG_A will be updated
SIG_B <= SIG_A;
SIG_B will be updated after the process is finished
end process;