Proiectarea Flux de Date: Instrucţiunea de Atribuire Concurentă Directă de Semnal
Proiectarea Flux de Date: Instrucţiunea de Atribuire Concurentă Directă de Semnal
Instrucţiunea if
library IEEE;
use IEEE.std_logic_1164.all;
use IEEE.numeric_std.all;
entity prime is
port ( N: in STD_LOGIC_VECTOR (3 downto 0);
F: out STD_LOGIC) ;
end prime;
architecture prime6_arch of prime is
begin
process (N)
variable NI : INTEGER;
begin
NI := to_integer(unsigned (N));
if NI=1 or NI=2 or NI=3 or NI=5 or NI=7 or NI=11 or
NI=13 then F<='1' ;
else F <= '0' ;
end if ;
end process ;
end prime6_arch;
Instrucţiunea case
library IEEE;
use IEEE.std_logic_1164.all;
use IEEE.numeric_std.all;
entity prime is
port ( N: in STD_LOGIC_VECTOR (3 downto 0);
F: out STD_LOGIC) ;
end prime; architecture prime7_arch of prime is
begin
process (N)
begin
case to_integer(unsigned (N)) is
when 1 => F <= '1';
when 2 => F <= '1';
when 3 | 5 | 7 | 11 | 13 => F <= '1' ;
when others => F <= '0' ;
end case ;
end process ;
end prime7_arch;
b) While-loop
process
begin
while error_flag /= ‘1’ and done /= '1’ loop
Clock <= not Clock;
wait for CLK_PERIOD/2;
end loop;
end process;
c) Loop
loop -- ciclu infinit, se utilizează cu instr. next sau exit
instrucţiune-secvenţială;
. . .
instrucţiune-secvenţială;
end loop;
Instrucţiunea wait
process
begin
RESET_LOOP: loop
wait until CLOCK’event and CLOCK = ’1’;
next RESET_LOOP when (RESET = ’1’);
X <= A;
wait until CLOCK’event and CLOCK = ’1’;
next RESET_LOOP when (RESET = ’1’);
Y <= B;
end loop RESET_LOOP;
end process;
Descrierea circuitelor combinaţionale în VHDL
Multiplexor
MUX 2->1
Program VHDL bazat pe flux de date:
library IEEE;
use IEEE.std_logic_1164.all;
entity mux2_1 is
port (s: in std_logic;
D1,D0 : in std_logic;
Q : out std_logic);
end mux2_1;
architecture mux2_1_arch of mux2_1 is begin
Q <= D1 when (s = '1') else D0;
end mux2_1_arch;
Decodificator
Program VHDL comportamental pentru un decodificator 3→8 cu intrări
active pe 0.
DC 3->8
library IEEE;
use IEEE.std_logic_1164.all;
entity dec3to8 is
port ( S: in std_logic_vector (2 downto 0); --intrari de selectare
EN: in std_logic; -- enable
Y: out std_logic_vector (7 downto 0)); -- iesirile sunt active pe zero
end dec3to8;
architecture dec3to8_arch of dec3to8 is
begin
process (S,EN)
begin
y <= "11111111";
if (en = '1') then
case S is
when "000" => Y(0) <= '0';
when "001" => Y(1) <= '0';
when "010" => Y(2) <= '0';
when "011" => Y(3) <= '0';
when "100" => Y(4) <= '0';
when "101" => Y(5) <= '0';
when "110" => Y(6) <= '0';
when "111" => Y(7) <= '0';
when others => null;
end case;
end if;
end process;
end dec3to8_arch;
library IEEE;
use IEEE.std_logic_1164.all;
USE ieee.numeric_std.ALL; entity dec3to8 is
port ( S: in std_logic_vector (2 downto 0); --intrari de selectare
EN: in std_logic; -- enable
Y: out std_logic_vector (7 downto 0)); -- iesirile sunt active pe zero
end dec3to8;
architecture dec3to8_comp of dec3to8 is
begin
process (S,EN)
begin
Y <= "11111111";
if (EN = '1') then
Y(to_integer(unsigned(S))) <= '0';
end if;
end process;
end dec3to8_comp ;
Codificatoare
Program VHDL bazat pe flux de date
CD 8->3
library IEEE;
use IEEE.std_logic_1164.all;
entity CD is port (
X : in std_logic_vector (7 downto 0);
Y : out std_logic_vector (2 downto 0));
end CD;
architecture CD_arch of CD is
begin
Y <=
"000" when X(0)='1' else "001" when X(1)='1' else
"010" when X(2)='1' else
"011" when X(3)='1' else
"100" when X(4)='1' else
"101" when X(5)='1' else
"110" when X(6)='1' else
"111" when X(7)='1' else
"000";
end CD_arch;
construcţia VHDL if-then-else – de prioritate, comportamentala
library IEEE;
use IEEE.std_logic_1164.all;
entity CD_PR is port (
X : in std_logic_vector (7 downto 0);
Y : out std_logic_vector (2 downto 0));
end CD_PR;
architecture CD_PR_arch of CD_PR is
begin
process(X)
begin
Y <= "000";
if X(7)='1' then Y <= "111";
elsif X(6)='1' then Y <= "110";
elsif X(5)='1' then Y <= "101";
elsif X(4)='1' then Y <= "100";
elsif X(3)='1' then Y <= "011";
elsif X(2)='1' then Y <= "010";
elsif X(1)='1' then Y <= "001";
elsif X(0)='1' then Y <= "000";
end if;
end process;
end CD_PR_arch;
Porti logice
AND2 (Comportamental)
library ieee;
use ieee.std_logic_1164.all;
entity Gate_And2 is
port (x, y: in std_logic;
F: out std_logic);
end Gate_And2;
architecture Gate_And2_beh of Gate_And2 is
begin
process (x, y)
begin
F <= x and y;
end process;
end Gate_And2_beh;
XOR2 (Comportamental)
library ieee;
use ieee.std_logic_1164.all;
entity Gate_XOR2 is
port (x, y: in std_logic;
F: out std_logic);
end Gate_XOR2;
architecture Gate_XOR2_beh of Gate_XOR2 is
begin
process (x, y)
begin
F <= x XOR y;
end process;
end Gate_XOR2_beh;
OR3 (Comportamental)
library ieee;
use ieee.std_logic_1164.all;
entity Gate_OR3 is
port (x, y, z: in std_logic;
F: out std_logic);
end Gate_OR3;
architecture Gate_OR3_beh of Gate_OR3 is
begin
process (x, y, z)
begin
F <= x OR y OR z;
end process;
end Gate_OR3_beh;