Professional Documents
Culture Documents
1. ENTITY ======================
library IEEE;
use IEEE.STD_LOGIC_1164.all;
entity AOI is
port (A, B, C, D: in STD_LOGIC;
F: out STD_LOGIC);
end AOI;
architecture V1 of AOI is
begin
F <= not((A and B) or (C and D));
end V1;
2. SIGNAL ---------------------------------------
architecture V2 of AOI is
signal AB, CD, O: STD_LOGIC;
begin
AB <= A and B after 2 NS;
CD <= C and D after 2 NS;
O <= AB or CD after 2 NS;
F <= not O after 1 NS;
end V2;
3. COMPONENT =================
library IEEE;
use IEEE.STD_LOGIC_1164.all;
entity MUX2 is
port (SEL, A, B: in STD_LOGIC;
F: out STD_LOGIC);
end MUX2;
component AOI
port (A, B, C, D: in STD_LOGIC;
F: out STD_LOGIC);
end component;
begin
G1: INV port map(SEL, SELB);
G2: AOI port map(SEL, A, SELB, B, F);
end STRUCTURE;
4. --------------------------------------------------
G1: entity WORK.INV(ARCH)
port map (SEL, SELB);
G2: entity WORK.AOI(V2)
port map (SEL, A, SELB, B, F);
vhdl_ex 1
5. TEST BENCHES ===============
library IEEE;
use IEEE.STD_LOGIC_1164.all;
(or use WORK.all;)
entity TEST_MUX4 is
end; -- empty entity !
begin
SEL <= "00",
"01" after 30 NS,
"10" after 60 NS, "11" after 90 NS,
"XX" after 120 NS, "00" after 130 NS;
A <= 'X',
'0' after 10 NS,
'1' after 20 NS;
B <= 'X',
'0' after 40 NS,
'1' after 50 NS;
C <= 'X',
'0' after 70 NS,
'1' after 80 NS;
D <= 'X',
'0' after 100 NS,
'1' after 110 NS;
...
M: MUX4 port map(SEL, A, B, C, D, F);
end BENCH;
vhdl_ex 2
3. PROCESS & SYNCHRONISATION VHDL3
1. PROCESS ====================
architecture V3 of AOI is
begin
process (A, B, C, D) -- sensitivity list !
begin
AB <= A and B after 2 NS;
CD <= C and D after 2 NS;
end process;
process (O)
begin
F <= not O after 1 NS;
end process;
end V3;
3. WAIT ------------------------------------------
Stimulus: process
begin
Reset <= '0';
wait for 50 NS;
Reset <= '1';
wait;
end process;
vhdl_ex 3
5. EVENTS -------------------------------------
process (A, B, S, T) -- delta delay !
begin
S <= A nand B after 2 NS;
T <= not S;
F <= T after 1 NS;
end process;
6. --------------------------------------------------
Feedback: process (S, R, Q, QB) -- RS
begin
Q <= S nand QB;
QB <= R nand Q;
end process;
vhdl_ex 4
4. SEQUENCIAL STATES VHDL4
1. VARIABLE -----------------------------------
process (A, B, C)
variable V: Std_logic; -- local !
begin
V := A nand B;
V := V nor C;
F <= not V;
end process;
begin
process (A, B, C)
variable V: Std_logic; -- local !
begin
V := A nand B;
V := V nor C;
F <= not V;
end process;
process (F)
begin
...
end process;
...
4. ---------------------------------------------------
if C2 = '1' and C3 = '1' then
V := not V;
end if;
5. ----------------------------------------------------
process (C1, C2, C3, A, B)
variable V: Std_logic;
begin
if C1 = '0' then
V := A;
else
V := B;
end if;
F <= V;
end process;
vhdl_ex 5
6. NESTED IF ----------------------------------
process (C0, C1, C2, A, B, C, D)
begin
if C0 = '1' then
F <= A;
else
if C1 = '1' then
F <= B;
else
if C2 = '1' then
F <= C;
else
F <= D;
end if;
end if;
end if;
end process;
7. ELSIF -----------------------------------------
process (C0, C1, C2, A, B, C, D)
begin
if C0 = '1' then
F <= A;
elsif C1 = '1' then
F <= B;
elsif C2 = '1' then
F <= C;
else
F <= D;
end if;
end process;
begin
if Enable = '1' then
Q <= Data;
end if;
end process;
9. CASE ------------------------------------------
case SEL is
when "00" => -- nu elemente comune !
F <= A;
when "01" =>
F <= B;
when "10" =>
F <= C;
when "11" =>
F <= D;
when others =>
F <= 'X';
end case;
vhdl_ex 6
10. OR COND ---------------------------------
case ADDRESS is
when 16 | 20 | 24 | 28 =>
A <= '1';
B <= '1';
when others =>
end case;
13. -------------------------------------------------
case SEL is -- CASE paralel test !
when "10" =>
F <= A;
when "11" =>
F <= A;
when "01" =>
F <= B;
when others =>
F <= C;
end case;
14. ------------------------------------------------
if SEL = "00" then -- No FPGA !
F <= A;
elsif SEL = "01" then
F <= B;
elsif SEL = "10" then
F <= C;
else
F <= D;
end if;
vhdl_ex 7
15. -------------------------------------------------
case SEL is
when "00" =>
F <= A;
when "01" =>
F <= B;
when "10" =>
F <= C;
when others =>
F <= D;
end case;
17. ------------------------------------------------
process (A, B)
variable I: Std_logic;
...
begin
I := not I;
end process;
begin
V := '0';
for I in 0 to 3 loop
F(I) <= A(I) and B(3-I);
V := V xor A(I);
end loop;
G <= V;
end process;
vhdl_ex 8
19. LOOP ---------------------------------------
loop
...
exit;
...
exit when CONDITION;
...
end loop;
21. ----------------------------------------------
Main: for I in 0 to 15 loop
...
next Main when Reset = '0'; -- jmp to begin !
...
end loop Main;
begin
for I in 1 to 1000 loop -- eqv: while NOW < 15 US
Clock <= '0';
wait for 5 NS;
Clock <= '1';
wait for 10 NS;
end loop;
wait;
end process ClockGenerator_1;
23. ----------------------------------------------
ClockGenerator_3: process
begin
loop
Clock <= '0';
wait for 5 NS;
Clock <= '1';
wait for 10 NS;
exit when NOW >= 15 US;
end loop;
wait;
end process ClockGenerator_3;
vhdl_ex 9
24. -----------------------------------------------
process (A, B, C, D) -- priority coder ?
variable V: Std_logic_vector(3 downto 0);
begin
V(3) := A;
V(2) := B;
V(1) := C;
V(0) := D;
F <= 0;
for I in 0 to 3 loop
if V(I) = '1' then
F <= I;
exit;
end if;
end loop;
end process;
25. ------------------------------------------------
architecture V2 of AOI is
signal AB, CD, O: STD_LOGIC;
begin
AB <= A and B after 2 NS; -- event asign !
CD <= C and D after 2 NS;
O <= AB or CD after 2 NS;
F <= not O after 1 NS;
end V2;
26. -----------------------------------------------
process (A, B)
begin
AB <= A and B after 2 NS;
end process;
vhdl_ex 10
5. TYPES VHDL5
begin
C1: Reg port map (..., S, ...);
C2: Ctl port map (..., S, ...);
end;
4. --------------------------------------------------
case IP is
when "00" =>
OP <= "0--1"; -- ‘-‘ (don’t care); optimization for outputs !
when "01" =>
OP <= "1-0-";
when "10" =>
OP <= "--10";
when others =>
OP <= "101-";
end case;
5. ---------------------------------------------------
case IP is
when "0--" => -- ‘-‘ no for inputs; exclusive inputs in case !
OP <= "00";
when "10-" =>
OP <= "01";
when "1-1" =>
OP <= "10";
when others =>
OP <= "11";
end case;
vhdl_ex 11
7. RESOLVED ---------------------------------
function RESOLVED
(S: STD_ULOGIC_VECTOR)
return STD_ULOGIC;
9. ---------------------------------------------------
type Opcode is (Add, Neg, Load,
Store, Jmp, Halt);
signal S: Opcode := Halt; -- := initialisation - explicit
------------------------------------------------------
variable
V: Std_logic_vector(0 to 1) := "00";
12. -------------------------------------------------
signal A, B, C: STD_LOGIC;
signal F: STD_LOGIC_VECTOR(3 downto 0);
F(3 downto 0) <= (A & B) & C; -- F(3) = A; F(2) = B; F(1) = C; F(0) no chg
13. SHIFT & ROTATE -------------------- -- shift logic:sll, srl; arithm: sla, sra; rotate: rol, ror
signal
vhdl_ex 12
14. OVERLOADING --------------------------
library IEEE, COMPASS_LIB;
use IEEE.STD_LOGIC_1164.all;
use COMPASS_LIB.COMPASS.all; -- op ‘+’ – def. implicit for sum integer
not for sum vector !
entity ADDER is
port(A, B: in
STD_LOGIC_VECTOR(7 downto 0);
SUM: out
STD_LOGIC_VECTOR(7 downto 0));
end;
architecture A1 of ADDER is
begin
SUM <= A + B; -- ok sum vector !
end;
15. -------------------------------------------------
library IEEE;
use IEEE.STD_LOGIC_1164.all;
use IEEE.NUMERIC_STD.all; -- sum +
entity ADDER is
port(A, B: in UNSIGNED(7 downto 0);
SUM: out UNSIGNED(7 downto 0));
end;
architecture A1 of ADDER is
begin
SUM <= A + B; -- ok sum vector !
end;
17. -----------------------------------------------
use IEEE.NUMERIC_STD.all;
...
signal A: Unsigned(7 downto 0);
signal S: Unsigned(2 downto 0);
signal G: Std_logic;
...
Mux: G <= A(To_integer(S)); -- A(I), I – integer; explicit conversion funct
vhdl_ex 13
6. CLOCKS & REGISTERS VHDL6
1. --------------------------------------------------
library IEEE;
use IEEE.STD_LOGIC_1164.all;
entity LATCH is
port (ENB, D: in STD_LOGIC;
Q: out STD_LOGIC);
end;
begin
process (ENB, D)
begin
if ENB = '1' then
Q <= D;
end if;
end process;
end;
2. ---------------------------------------------------
process (Clock)
begin
if Clock'EVENT and Clock = '1' then
Q <= D;
…
end if;
end process;
3. ---------------------------------------------------
process (Clock)
begin
if RISING_EDGE(Clock) then
Q <= D;
end if;
end process;
4. ---------------------------------------------------
...
signal Count :
STD_LOGIC_VECTOR(7 downto 0);
begin
process (Clock, Reset)
begin
if Reset = '0' then
Count <= "00000000";
elsif RISING_EDGE(Clock) then
if Load = '1' then
Count <= Data;
else
Count <= Count + '1';
end if;
end if;
end process;
vhdl_ex 14
5. ---------------------------------------------------
architecture A1 of Block1 is
...
component GlobalResetBuffer
port (Pin: out Std_logic);
end component;
begin
G: GlobalResetBuffer
port map (Reset);
6. ---------------------------------------------------
process (Clock)
begin
if RISING_EDGE(Clock) then
if Reset = '1' then
Q <= '0';
elsif Enable = '1' then
Q <= Data;
end if;
end if;
end process;
7. ---------------------------------------------------
process (Clock)
begin
if RISING_EDGE(Clock) then
if Enable = '1' then
if Reset = '1' then
Q <= '0';
else
Q <= Data;
end if;
end if;
end if;
end process;
8. ---------------------------------------------------
Another_Flipflop: process
begin
wait until Clock = '1';
if Reset = '1' then
Q <= '0';
else
Q <= D;
end if;
end process;
vhdl_ex 15
9. ---------------------------------------------------
Another_Flipflop: process
begin
wait until RISING_EDGE(Clock);
10. ---------------------------------------------------
T1: process (All_Inputs)
begin
end process;
11. ---------------------------------------------------
T2: process (All_Inputs)
begin
if Enable = '1' then
end if;
end process;
12. ---------------------------------------------------
T3: process (Clock)
begin
if RISING_EDGE(Clock) then
end if;
end process;
13. ---------------------------------------------------
T4: process
begin
wait until RISING_EDGE(Clock);
end process;
14. ---------------------------------------------------
T5: process (Clock, Reset)
begin
if Reset = '0' then
... Asynchronous actions
end if;
end process;
vhdl_ex 16
15. ---------------------------------------------------
signal Acc, Delta:
... STD_LOGIC_VECTOR(11 downto 0);
process
variable Up: STD_LOGIC;
variable nextA:
STD_LOGIC_VECTOR(11 downto 0);
begin
wait until RISING_EDGE(Clock);
if Up = '1' then
nextA := Acc + Delta;
if nextA >= Max then
Up := '0';
end if;
else
nextA := Acc - Delta;
if nextA < 0 then
Up := '1';
end if;
end if;
16. ---------------------------------------------------
signal Reg: STD_LOGIC;
...
AND_REG: process
variable V: STD_LOGIC;
begin
wait until RISING_EDGE(Clock);
V := '1';
for I in 0 to 7 loop
V := V and Input(I);
end loop;
Reg <= V;
end process;
17. ---------------------------------------------------
Counter: process
variable Count:
STD_LOGIC_VECTOR(7 downto 0);
begin
wait until RISING_EDGE(Clock);
vhdl_ex 17
18. ---------------------------------------------------
process
begin
wait until RISING_EDGE(Clock);
Q <= Data;
QB <= not Data;
end process;
19. ---------------------------------------------------
process
begin
wait until RISING_EDGE(Clock);
Q <= Data;
end process;
QB <= not Q;
20. ---------------------------------------------------
port (...UpOut: out STD_LOGIC);
...
process
begin
wait until RISING_EDGE(Clock);
21. ---------------------------------------------------
port (...UpOut: out STD_LOGIC);
...
process
variable Up: STD_LOGIC;
begin
wait until RISING_EDGE(Clock);
if Up = '1' then
...
Up := '0';
else
...
Up := '1';
end if;
vhdl_ex 18
22. ---------------------------------------------------
port (... UpOut: out STD_LOGIC);
...
signal Up: STD_LOGIC;
...
begin
process
begin
wait until RISING_EDGE(Clock);
if Up = '1' then
...
Up <= '0';
else
...
Up <= '1';
end if;
end process;
23. ---------------------------------------------------
port (...UpOut: buffer STD_LOGIC);
...
process
begin
wait until RISING_EDGE(Clock);
vhdl_ex 19
7. FINITE STATE MACHINES VHDL7
1. --------------------------------------------------
library IEEE;
use IEEE.Std_logic_1164.all;
entity FSM is
port (Clock, Reset: in Std_logic;
F, G: out Std_logic);
end;
begin
process
...
begin
wait until RISING_EDGE(Clock);
…
end process;
end;
2. ---------------------------------------------------
architecture Explicit of FSM is
begin
process
type StateType is (Idle, Start, Stop, Clear);
variable State: StateType;
begin
wait until RISING_EDGE(Clock);
vhdl_ex 20
3. ---------------------------------------------------
architecture SeparateDecoding of FSM is
type StateType is (Idle, Start, Stop, Clear);
signal State: StateType;
begin
Change_state: process
begin
wait until RISING_EDGE(Clock);
4. --------------------------------------------------
architecture RegistersPlusLogic of FSM is
type StateType is (Idle, Start, Stop, Clear);
signal State, NextState: StateType;
begin
Registers: process
begin
wait until RISING_EDGE(Clock);
vhdl_ex 21
5. --------------------------------------------------
architecture NoDecoding of AnotherFSM is
constant Idle: STD_LOGIC_VECTOR := "11";
constant Start: STD_LOGIC_VECTOR := "01";
constant Stop: STD_LOGIC_VECTOR := "10";
constant Clear: STD_LOGIC_VECTOR := "00";
signal State: STD_LOGIC_VECTOR(1 downto 0);
begin
process
begin
wait until RISING_EDGE(Clock);
P <= State(1);
Q <= State(0);
end;
6. --------------------------------------------------
type StateType is
(Idle, Start, Stop, Clear);
signal State: StateType;
7. ---------------------------------------------------
type StateType is
(One, Two, Three, Four, Five);
signal State: StateType;
8. ---------------------------------------------------
type StateType is
(One, Two, Three, Four, Five,
Dummy1, Dummy2, Dummy3);
9. ---------------------------------------------------
signal Count:
STD_LOGIC_VECTOR(3 downto 0);
...
if Count = "1001" then
Count <= "0000";
else
Count <= Count + '1';
end if;
vhdl_ex 22