VHDL szimuláció Labor II. Dr. Hidvégi Timót Tervezés 1
Lefoglalt szavak abs access after alias all and architecture array assert attribute block body buffer bus case component configuration constant disconnect downto else elsif end entity exit file for function generate generic guarded if in inout Is label library linkage loop map mod nand new next nor not null of on open or others out package port procedure process range record register rem report return select severity signal subtype then to transport type units until use variable wait when while with xor group impure inertial literal postponed pure reject rol ror shared sla sll sra srl unaffected xnor VHDL program szerkezete Logikai áramkör Entitás Architektúra Strukturális Viselkedési 2
A VHDL program felépítése A B CIN? S COUT entitás entity fa1 is port ( A, B, CIN : in bit; S, COUT : out bit); end fa1; architektúra architecture struct of fa1 is S <= A xor B xor CIN; COUT <= (A and B) or (A and CIN) or (B and CIN); end struct; Entitás entity NÉV is generic (konstansok); port( bemenet neve : bemenet típusa; kimenet neve : kimenet típusa); end NÉV; entity pelda1 is end pelda1; generic (integer : kesleltetes := 10 ns); port(a, B, Cin : in bit; S, Cout : out bit); entity szamlalo is generic (szelesseg : integer := 16); port(d : in bit_vector (szelesseg-1 downto 0); CLK, EN : in bit; S : out bit_vector (szelesseg-1 downto 0)); end szamlalo; 3
Architektúra ARCHITECTURE architektúra-neve OF entitás-neve IS komponensek megadása jelek deklarációja folyamatok definíciója függvények definíciója BEGIN processek leírások END architektúra-neve; Komponens component azonosító generic lista; port lista; end component; component count1 generic (m : integer := 7); port ( DCOUNT : in std_logic_vector(m downto 0); CLK : in std_logic; CLR : in std_logic; QCOUNT : out std_logic_vector(m downto 0)); end component; 4
Adattípusok I. SIGNAL A1 : bit; SIGNAL A2 : bit_vector(7 downto 0); A1 <= 1 ; A2 <= 00110011 ; bit_vector(7 downto 0); bit_vector(8 downto 1); bit_vector(0 downto 7); 0 1 Z - L H U X W LIBRARY IEEE; USE IEEE.STD_LOGIC_1164.ALL bit_vector(1 downto 8); std_logic; std_logic_vector(7 downto 0); Adattípusok II. Ezekkel tudunk aritmetikai műveleteket végezni. signal X1, X2, Y : real; Y <= X1 + X2; Boolean értéke true vagy false lehet. SIGNAL A1 : BOOLEAN; A type segítségével tudunk különböző értékeket megadni egy változónak. TYPE BYTE IS ARRAY(7 downto 0) of bit; -- Létrehozzuk a byte típust TYPE MEMORY_TYPE IS ARRAY(1 to 16) of byte; -- Definiáljuk a memóriát, mint -- tömböt SIGNAL MEMORY : MEMORY_TYPE; -- A memory változóhoz hozzárendeljük -- a 16 szavas, 8 bites memóriát MEMORY(4) <= 00110011 -- A 4. memória címre 00110011-et írunk 5
Példa I. F = AB + CD Entitás Architektúra A B C D? F A B C D & & 1 F Strukturális leírás entity fpelda is port (A, B, C, D : in bit; F : out bit); end fpelda; architecture struct of fpelda is F <= (A and B) or (C and not(d)); end struct; entitás architektúra 6
Viselkedési leírás entity fpeldav is port (A, B, C, D : in bit; F : out bit); end fpeldav; architecture viselk of fpeldav is process(a,b,c,d) if (A= 1 and B= 1 )or (C= 1 and D= 0 ) then F <= 1 ; else F <= 0 ; end if; end process; end viselk; Multiplexer entity multip2 is port(a0, A1, v: in bit; Y: out bit); end multip2; arhitecture structural of multip2 is Y <= (A0 and not(v)) or (A1 and v); end structural; A0 A1 v & & 1 Y arhitecture viselkedes of multip2 is Y <= A0 when v = '0' else A1; end viselkedes; A0 A1 Y v 7
Process címke: process (szenzitív lista) deklarációs lista; utasítások; end process címke; process(clk, CLR) if CLK'event and CLK = '1' then if CLR = '1' then for i in 0 to m-1 loop SQ(i) <= '0'; end loop; Q <= SQ; else SQ <= SQ + 1; Q <= SQ; end if; else null; end if; end process; Feltételes szerkezetek (IF) IF feltétel1 THEN utasítások1 ELSE utasítások2 END IF; IF feltétel1 THEN utasítások ELSIF feltétel2 THEN utasítások ELSIF feltétel3 THEN... ELSE feltételn END IF; 8
Feltételes szerkezet if RST = 1 and CLK event and CLK = 1 then if RST = 1 then if CLK event and CLK = 1 then if CLK event and CLK = 1 then if RST = 1 then Feltételes szerkezetek (CASE) CASE expression IS WHEN c1 => sequential-statements; WHEN c2 => sequential-statements;... WHEN OTHERS => sequential-statements; end CASE; 9
Feltételes szerkezetek (WHEN) entity condstmt is port(a, B, C, D : in bit_vector(7 downto 0); S : in bit_vector(1 downto 0); Y : out bit_vector(7 downto 0)); end condstmt; architecture RTL of condstmt is Begin Y <= A when S ="00" else B when S="01" else C when S="10" else D; end RTL; library IEEE; use IEEE.STD_LOGIC_1164.ALL; use IEEE.STD_LOGIC_ARITH.ALL; use IEEE.STD_LOGIC_UNSIGNED.ALL; entity szorzo1 is port(a, B : in std_logic_vector(3 downto 0); P : out std_logic_vector(7 downto 0)); end szorzo1; architecture viselk of szorzo1 is P <= A * B; end viselk; Adattípusok 10
Ciklusok loop Feltétel nélküli hurok. A next vagy az exit utasítás használatáig vagyunk a ciklusban. cimke: loop utasítások end loop cimke while A ciklusmag addig hajtódik végre, amíg a feltétel igaz. címke: for Adott iterációban hajtódik végre a ciklusmag. címke: while feltétel loop utasítások end loop címke; for ciklusváltozó in tartomány utasítások end loop címke; for ciklus if CLR = '1' then for i in 0 to m-1 loop SQ(i) <= '0'; end loop; Q <= SQ; else..... 11
Várakozás (WAIT) wait on Addig várakozunk, amíg az adott jel értéke meg nem változik wait on CLK; wait on RST, CLK, SET; wait until Logikai feltétel wait until RST = 1 ; wait for Adott ideig várakozunk wait for 20 ns; Szimuláció DS CLKS QS RSTS A szimulálandó áramkör A szimulálandó áramkör és a testbench A szimulálandó Áramkör VHDL kódja 12
A szimulált kód QS A DFF szimulációja 13
Szorzó (8x8) A(7.. 0) B(7.. 0) P(15.. 0) Tesztkörnyezet 14
Szimuláció 4/1 multiplexer szimulációja X(31.. 0) Y(7.. 0) SEL0 SEL1 15
A tesztkörnyezet? 4/1 multiplexer szimulációja 16