Pobieranie prezentacji. Proszę czekać

Pobieranie prezentacji. Proszę czekać

VHDL Ernest Jamro, Paweł Russek C3 p. 504

Podobne prezentacje


Prezentacja na temat: "VHDL Ernest Jamro, Paweł Russek C3 p. 504"— Zapis prezentacji:

1 VHDL Ernest Jamro, Paweł Russek C3 p. 504 jamro@agh.edu.pl russek@agh.edu.pl www.fpga.agh.edu.pl jamro@agh.edu.pl russek@agh.edu.pl

2

3 Potrzeba narzędzia: 1970 - INTEL 4004 4 projektantów 1 tys. tranzystorów 1982 - INTEL 80286 20 projektantów 100 tys. tranzystorów 1992 - INTEL PENTIUM 100 projektantów 3 mln tranzystorów 2008 1000 projektantów 150 mln tranzystorów 200??? ???? projektantów ???? mln tranzystorów Współczesne wymagania: hardware-software codesign !!! Języki Opisu Sprzętu – po co? E. Jamro, J.Kasperek, P.J.Rajda © 2009 Katedra Elektroniki AGH Kraków

4 Języki Opisu Sprzętu – po co? E. Jamro, J.Kasperek, P.J.Rajda © 2009 Katedra Elektroniki AGH Kraków

5 VHDL – co to jest? Definicja VHDL - V HSIC H ardware D escription L anguage V ery H igh S peed I ntegrated C ircuit It is "a formal notation intended for use in all phases of the creation of electronic systems.... it supports the development, verification, synthesis, and testing of hardware designs, the communication of hardware design data..." [IEEE Standard VHDL Language Reference Manual] E. Jamro, J.Kasperek, P.J.Rajda © 2009 Katedra Elektroniki AGH Kraków

6 VHDL – jak, gdzie, kiedy? Zakres stosowania Modelowanie A=”01” ? A(1..0) Z Z <= ’1’ when A = ”01” else ’0’; E. Jamro, J.Kasperek, P.J.Rajda © 2009 Katedra Elektroniki AGH Kraków

7 VHDL – jak, gdzie, kiedy? Zakres stosowania Symulacja A(1) A(0) Z E. Jamro, J.Kasperek, P.J.Rajda © 2009 Katedra Elektroniki AGH Kraków

8 VHDL – jak, gdzie, kiedy? Zakres stosowania Synteza (automatyczna) translacja opisu w języku HDL na strukturę w postaci listy połączeń elementarnych bloków funkcyjnych docelowej platformy sprzętowej (bramek, przerzutników, pamięci i innych) A(0) A(1) Z E. Jamro, J.Kasperek, P.J.Rajda © 2009 Katedra Elektroniki AGH Kraków

9 entity name architecture style of name VHDL – jak, gdzie, kiedy? Jednostki projektowe entity COMPARE is port (A,B: in bit; C: out bit); end COMPARE; architecture BEHAVIORAL of COMPARE is begin C <=‘1’ when A=B else ‘0’; end behavioral; E. Jamro, J.Kasperek, P.J.Rajda © 2009 Katedra Elektroniki AGH Kraków

10 VHDL – przykłady Dekoder entity DECODER is port(D: in bit_vector (3 downto 0); ZERO: out bit; ONE: out bit; EIGHT: out bit; NINE: out bit); end DECODER; architecture FIRST of DECODER is begin NINE <= '1' when D="1001" else '0'; EIGHT <= '1' when D="1000" else '0'; ONE <= '1' when D="0001" else '0'; ZERO <= '1' when D="0001" else '0'; end FIRST; E. Jamro, J.Kasperek, P.J.Rajda © 2009 Katedra Elektroniki AGH Kraków

11 VHDL – przykłady Komparator entity COMPARE is port(A,B: in bit_vector (0 to 7); EQL: out bit_vector (0 to 7)); end COMPARE; architecture SECOND of COMPARE is begin EQL <= not (A xor B); end SECOND; Gdzie na tym schemacie jest błąd? E. Jamro, J.Kasperek, P.J.Rajda © 2009 Katedra Elektroniki AGH Kraków

12 VHDL – przykłady Multiplekser entity MPLEXER is port(D: in bit_vector (7 downto 0); A: in bit_vector (2 downto 0); X: out bit); end MPLEXER; architecture THIRD of MPLEXER is signal Ai: integer range 7 downto 0; begin Ai <= conv_integer(A); X <= D(Ai); end THIRD; E. Jamro, J.Kasperek, P.J.Rajda © 2009 Katedra Elektroniki AGH Kraków

13 Przykład: package STANDARD -- This is Package STANDARD as defined in the VHDL 1992 Language Reference Manual. package standard is type boolean is (false,true); type bit is ('0', '1'); type character is ( nul, soh, stx, etx, eot, enq, ack, bel, bs, ht, lf, vt, ff, cr, so, si, dle, dc1, dc2, dc3, dc4, nak, syn, etb,................ 'đ', 'ń', 'ň', 'ó', 'ô', 'ő', 'ö', '÷', 'ř', 'ů', 'ú', 'ű', 'ü', 'ý', 'ţ', '˙' ); type severity_level is (note, warning, error, failure); type integer is range -2147483647 to 2147483647; type real is range -1.0E308 to 1.0E308; type time is range -2147483647 to 2147483647 units fs; ps = 1000 fs; ns = 1000 ps; us = 1000 ns; ms = 1000 us; sec = 1000 ms; min = 60 sec; hr = 60 min; end units; subtype delay_length is time range 0 fs to time'high; impure function now return delay_length; subtype natural is integer range 0 to integer'high; subtype positive is integer range 1 to integer'high; type string is array (positive range <>) of character; type bit_vector is array (natural range <>) of bit; type file_open_kind is ( read_mode, write_mode, append_mode); type file_open_status is ( open_ok, status_error, name_error, mode_error); attribute foreign : string; end standard;

14 Pojęcia leksykalne - literały Literały pojedyncze (skalary) character - pojedynczy znak objęty apostrofami, np: ‘A’ lub ‘a’ bit - reprezentuje wartość binarną ‘1’ lub ‘0’ std_logic - reprezentuje wartość sygnałów wg. IEEE 1164: U niezainicjalizowany X nieznany (forcing an unknown) 0 silne zero (forcing 0) 1 silne jeden (forcing 1) Z wysoka impedancja W słaby nieznany (weak unknown) L słabe zero (weak 0) H słabe jeden (weak 1) - nieistotny (don’t care) Poza pakietem STANDARD Należy dodać przed entity: library IEEE; use IEEE.STD_LOGIC_1164.all; E. Jamro, J.Kasperek, P.J.Rajda © 2009 Katedra Elektroniki AGH Kraków

15 Biblioteka std_logic.vhd ----------------------------------------------------------------- -- resolution function ----------------------------------------------------------------- CONSTANT resolution_table : stdlogic_table := ( -- --------------------------------------------------------- -- | U X 0 1 Z W L H - | | -- --------------------------------------------------------- ( 'U', 'U', 'U', 'U', 'U', 'U', 'U', 'U', 'U' ), -- | U | ( 'U', 'X', 'X', 'X', 'X', 'X', 'X', 'X', 'X' ), -- | X | ( 'U', 'X', '0', 'X', '0', '0', '0', '0', 'X' ), -- | 0 | ( 'U', 'X', 'X', '1', '1', '1', '1', '1', 'X' ), -- | 1 | ( 'U', 'X', '0', '1', 'Z', 'W', 'L', 'H', 'X' ), -- | Z | ( 'U', 'X', '0', '1', 'W', 'W', 'W', 'W', 'X' ), -- | W | ( 'U', 'X', '0', '1', 'L', 'W', 'L', 'W', 'X' ), -- | L | ( 'U', 'X', '0', '1', 'H', 'W', 'W', 'H', 'X' ), -- | H | ( 'U', 'X', 'X', 'X', 'X', 'X', 'X', 'X', 'X' ) -- | - | ); E. Jamro, J.Kasperek, P.J.Rajda © 2009 Katedra Elektroniki AGH Kraków

16 Pojęcia leksykalne – wyrażenia Operatory wyrażeń: logiczne andornandnorxornot relacji =/= >= połączenia & arytmetyczne +-*/ ** modremabs VHDL’92 sllsrlslasrarolrorxnor Typy argumentów: takie same: and or nand nor xor not = /= >= + - * / integer: mod rem integer exp: ** numeryczny: abs E. Jamro, J.Kasperek, P.J.Rajda © 2009 Katedra Elektroniki AGH Kraków

17 VHDL – przykłady Sumator library IEEE; use IEEE.STD_LOGIC_1164.all; use IEEE.STD_LOGIC_UNSIGNED.all; entity SUM is port(A,B: in std_logic_vector (2 downto 0); Cin: in std_logic; S: out std_logic_vector (2 downto 0); Cout: out std_logic); end SUM; architecture FOURTH of SUM is signal V: std_logic_vector (3 downto 0); begin V <= A + B + Cin; S <= V(2 downto 2); Cout <= V(3); end FOURTH; E. Jamro, J.Kasperek, P.J.Rajda © 2009 Katedra Elektroniki AGH Kraków

18 Process Składnia: [etykieta : ] process [ ( lista sygnałów aktywujących ) ] [ is ] [podprogram] [typ] [stała] [zmienna] [inne deklaracje] begin instrukcje sekwencyjne end process [etykieta] ; Instrukcja przypisania wartości dla zmiennych zmienna := wyrażenie ; Instrukcja przypisania wartości dla sygnałów sygnał <= wyrażenie [ after delay] ; E. Jamro, J.Kasperek, P.J.Rajda © 2009 Katedra Elektroniki AGH Kraków

19 Process / brak process Powielanie logiki entity loop_stmt is port (a: bit_vector (3 downto 0); m: out bit_vector (3 downto 0)); end loop_stmt; architecture example1 of loop_stmt is signal b: bit_vector(3 downto 0); begin b(0)<= a(0); label: for i in 1 to 3 generate b(i)<= b(i-1) and a(3-i); end generate; m<= b; end example1; architecture example2 of loop_stmt is begin process (a) variable b: bit; begin b := '1'; for i in 0 to 3 loop b := a(3-i) and b; m(i) <= b; end loop; end process; end example2;

20 Alternatywne rozwiązanie Multiplekser Mux_out<= A when sel = "00" else B when sel = "01" else C when sel = "10" else '-'; LUB with sel select Mux_out <= A when "00", B when "01", C when "10", '-' when others; E. Jamro, J.Kasperek, P.J.Rajda © 2009 Katedra Elektroniki AGH Kraków

21 Transkoder kodu hex na siedmiosegmentowy with HEX select LED<= "1111001" when "0001", --1 "0100100" when "0010", --2 "0110000" when "0011", --3 "0011001" when "0100", --4 "0010010" when "0101", --5 "0000010" when "0110", --6 "1111000" when "0111", --7 "0000000" when "1000", --8 "0010000" when "1001", --9 "0001000" when "1010", --A "0000011" when "1011", --b "1000110" when "1100", --C "0100001" when "1101", --d "0000110" when "1110", --E "0001110" when "1111", --F "1000000" when others; --0

22 Przerzutnik typu D process (CLK) begin if (CLK'event and CLK='1') then if reset=‘1’ then -- reset synchroniczny DOUT <= '0'; else DOUT <= DIN; end if; end process ; process (CLK, RESET) begin if RESET='1' then – reset asynchroniczny DOUT <= '0'; elsif (CLK'event and CLK='1') then DOUT <= DIN; end if; end process ;

23 Przerzutnik typu D z multiplekserem i Clock Enable (CE) process (CLK) begin if (CLK'event and CLK='1') then if ce= ‘1’ then if sel=‘0’ then DOUT <= DIN0; else DOUT <= DIN1; end if ; -- sel end if ; -- ce end if ; -- clk end process; E. Jamro, J.Kasperek, P.J.Rajda © 2009 Katedra Elektroniki AGH Kraków

24 sensivity list Pytanie: Jaka jest różnica w zachowaniu się dwóch poniższych procesów ? Odpowiedź: Lewy:Symulacja jednokrotna. Użycie poprzednich wartości S i T dla obliczenia wartości V. Prawy:Symulacja dwukrotna. Uaktualni wartości S i T dla obliczenia wartości V w dwóch cyklach delta. process (A, B)– częsty błąd begin S <= A; T <= B; V <= S or T; end process; process (A, B, S, T) begin S <= A; T <= B; V <= S or T; end process; E. Jamro, J.Kasperek, P.J.Rajda © 2009 Katedra Elektroniki AGH Kraków

25 Licznik (automat) architecture licznik of COUNT is signal Q: std_logic_vector(3 downto 0); begin process (C) begin if C='1' and C'event then if CE='1' then if Q = 9 then Q <= "0000”; else Q <= Q + 1; end if; end process; count<= Q; end licznik; E. Jamro, J.Kasperek, P.J.Rajda © 2009 Katedra Elektroniki AGH Kraków

26 Automat Moore’a --Insert the following in the architecture before the begin keyword --Use descriptive names for the states, like st1_reset, st2_search type state_type is (st1_, st2_,...); signal state, next_state : state_type; --Declare internal signals for all outputs of the state-machine signal _i : std_logic; -- example output signal --other outputs --Insert the following in the architecture after the begin keyword SYNC_PROC: process ( ) begin if ( 'event and = '1') then if ( = '1') then state ; <= '0'; else state <= next_state; _i; -- assign other outputs to internal signals end if; end process;

27 Automat Mealy’ego MEALY State-Machine - Outputs based on state and inputs OUTPUT_DECODE: process (state,,,...) begin --insert statements to decode internal output signals --below is simple example if (state = st3_ and = '1') then _i <= '1'; else _i <= '0'; end if; end process; NEXT_STATE_DECODE: process (state,,,...) begin --declare default state for next_state to avoid latches next_state <= state; --default is to stay in current state --insert statements to decode next_state --below is a simple example case (state) is when st1_ => if = '1' then next_state ; end if; when st2_ => if = '1' then next_state ; end if; when st3_ => next_state ; when others => next_state ; end case; end process;

28 Styl projektowania Modelowa struktura projektu: Jeden sygnał zegarowy Wszystkie przerzutniki wyzwalane tym samym zboczem Problemy przy dwóch aktywnych zboczach: Zależność od współczynnika wypełnienia (tolerancja na zmiany duty cycle w dokumentacji projektu!) Problemy z metodą testowania typu ścieżka brzegowa (JTAG 1149) CLK E. Jamro, J.Kasperek, P.J.Rajda © 2009 Katedra Elektroniki AGH Kraków

29 Styl projektowania Asynchroniczne kluczowanie zegara - same problemy! (niewykorzystanie zasobów dystrybucji sygnałów zegarowych, problemy z testowaniem, gorsze parametry czasowe itp.) Rozwiązanie – stosowanie wejść CE – kodowanie przez warunek: if ce=‘1’ po sekwencji if clk’event and clk=‘1’. CLK E. Jamro, J.Kasperek, P.J.Rajda © 2009 Katedra Elektroniki AGH Kraków

30 Styl projektowania CLK Nie należy stosować wewnętrznie (asynchronicznie!) generowanych sygnałów zegarowych. Należy natomiast projektować układy synchroniczne lub używać kilku sygnałów zegarowych (patrz: DLL). CLK CE E. Jamro, J.Kasperek, P.J.Rajda © 2009 Katedra Elektroniki AGH Kraków

31 Deklaracja sygnałów w entity W deklaracji sygnału jako portu dla entity należy wyszczególnić: nazwę sygnału, jego kierunek, typ i opcjonalnie jego wartość początkową. Składnia: port ( names : direction type [ := expression] [ ; more_ports] ); Przykład: port (DATA_IN: in bit:= ‘0’; DATA_OUT: out bit); port (B, A: in std_logic_vector);

32 Deklaracja sygnałów w VHDL Pytanie: Jaki jest najprawdopodobniej kierunek sygnału DATA_OUT ? Odpowiedź: buffer Ze względu na to że buffer propaguje do nadrzędnych modułów nie zaleca się go używać. Lepiej jest użyć wewnętrznego dodatkowego sygnału. MUXMUX logika DATA_IN SELECT DATA_OUT

33 Generic library IEEE; use IEEE.STD_LOGIC_1164.all; entity MY_ADDER generic (width: integer; operacja: integer); port ( a, b: in std_logic_vector(width-1 downto 0); s: out std_logic_vector(width-1 downto 0)); end MY_ADDER; architecture arch of MY_ADDER is gplus: if operacja = 0 generate s<= a + b; end generate; gminus: if operacja=1 generate s<= a-b; end generate; end arch;

34 Dodawanie bibliotek library ieee; use ieee.std_logic_1164.all; -- użycie std_logic use ieee.std_logic_unsigned.all; -- każda wartość std_logic_vector jest traktowana jako integer bez znaku use ieee.std_logic_signed.all; -- każda wartość std_logic_vector jest traktowana jako integer ze znaku Nie można równocześnie użyć obu bibliotek: std_logic_unsigned oraz std_logic_signed. W tym wypadku należy użyć biblioteki: use ieee.std_logic_arith.all; oraz zamiast słowa kluczowego std_logic_vector należy użyć słów unsigned lub signed (wada: konieczność używania konwersji std_logic_vector  unsigned (lub signed))

35 Umiejscawianie komponentów entity FULL_ADDER is port ( a, b, cin: in std_logic; s, cout: out std_logic); end FULL_ADDER; architecture arch of FULL_ADDER is begin s<= a xor b xor c; cout<= a when a=b else cin; end arch; entity MY_ADDER is generic (width: integer); port ( a, b: in std_logic_vector(width-1 downto 0); s: out std_logic_vector(width-1downto 0); end MY_ADDER; architecture arch of MY_ADDER is component FULL_ADDER -- deklaracja komponentu port ( a, b, cin: in std_logic; s, cout: out std_logic); end component; signal carry: std_logic_vector(0 to dwidth); begin carry(0)<= ‘0’; gi: for i in 0 to width-1 generate fa: full_adder Port map (a=> a(i), b=>b(i), cin=> carry(i), s=> s(i), cout=> carry(i+1)); end generate; end arch;

36 TESTBENCH – połączenie Process/Component Rodzaje procesów testujących Ad Hoc Zbiór wektorów testowych do podstawowych testów funkcjonalnych. Algorytmiczny Prosty algorytm generujący wymuszenia, np. pętla zwiększająca zmienną przez cały jej zakres do testowania dekodera lub ALU. Plik wektorów Rozwiązanie strukturalne: proces czytający plik z wektorami do testowania. ProcessComponent Signals UUTTestBench E. Jamro, J.Kasperek, P.J.Rajda © 2009 Katedra Elektroniki AGH Kraków

37 Przykład symulacji entity my_adder_tb is end my_adder_tb; Architecture sim of my_adder_tb is component my_adder........ end component; constant width: integer:= 4; signal a, b, s: std_logic_vector(width-1 downto 0):= (others=>’0’); -- to działa tylko dla symulacji signal error: bit; -- sygnalizuje błąd podczas obliczeń begin UUT: my_adder -- testowany moduł port map(a=> a, b=>b, s=>s); wymus: process begin -- generacja wszystkich możliwych wektorów wejściowych a, b wait for 10ns; a<= a + 1; if a="1111” then b<= b+1; end if; end process; error<= ‘1’ when a+b/=s else ‘0’; end sim;

38 Metody wymuszania stanów sygnałów process begin wait for 5ns; clk<= not clk; end process; CE<= ‘1’; first<= '0', '1' after 201ns, '0' after 211ns; process begin a<= ‘0’; b<= ‘0’; wait for 10ns; a<= ‘1’; wait for 50ns; a<=‘0’; b<= ‘1’; wait; -- czekaj w nieskończoność end process;

39 VHDL – literatura „A Guide to VHDL”, S. Mazor, P. Langstraat „VHDL Analysis and Modelling of Digital Systems”, Z. Navabi „VHDL Hardware Description and Design”, R. Lipsett, C. Schaefer, C. Ussery „The VHDL Cookbook”, P. J. Ashenden „VHDL programming: with advanced topics”, L. Baker „VHDL starter's guide”, S. Yalamanchili „VHDL for designers”, S. Sjoholm, L. Lindh „VHDL made easy!”, D. Pellerin, D. Taylor „VHDL answers to frequently asked questions”, B. Cohen „VHDL and AHDL digital systems implementation”, F. A. Scarpino „VHDL: język opisu i projektowania układów cyfrowych”, W. Wrona „Active-VHDL Series BOOK#2 – EVITA Interactive Tutorial”, J. Mirkowski, M. Kapustka, Z. Skowroński, A. Biniszkiewicz „VHDL: a logic synthesis approach”, D. Naylor, S. Jones E. Jamro, J.Kasperek, P.J.Rajda © 2009 Katedra Elektroniki AGH Kraków

40 VHDL – literatura Marek ZwolińskiWłodzimierz Wrona Kevin Skahill Józef Kalisz E. Jamro, J.Kasperek, P.J.Rajda © 2009 Katedra Elektroniki AGH Kraków

41 VHDL – zasoby w Internecie http://fpga.elektro.agh.edu.pl VHDL: http://www.vhdl.org/http://www.vhdl.org/ Grupa dyskusyjna: comp.lang.vhdl (FAQ - 4części) Accellera: http://www.accellera.org/http://www.accellera.org/ EDA Industry Working Groups homepage: http://www.eda.org/http://www.eda.org/ FPGA Journal http://www.fpgajournal.com/ - (ładne lekcje ChalkTalk )http://www.fpgajournal.com/ Design Automation Cafe: http://www.dacafe.com/http://www.dacafe.com/ Doulos High Level Design Web site: http://www.doulos.com/http://www.doulos.com/ VHDL-online, University of Erlangen-Nürnberg: http://www.vhdl-online.de/http://www.vhdl-online.de/ VHDL info pages of the Microelectronics Department (University of Ulm, Germany): http://mikro.e-technik.uni-ulm.de/vhdl/vhdl_infos.htmlhttp://mikro.e-technik.uni-ulm.de/vhdl/vhdl_infos.html E. Jamro, J.Kasperek, P.J.Rajda © 2009 Katedra Elektroniki AGH Kraków

42 VHDL – tutoriale Evita Interactive VHDL Tutorial from Aldec, Inc.: http://www.aldec.com Doulos High Level Design Web site; A Hardware Engineers Guide to VHDL: http://www.doulos.com/hegv/index.htm http://www.doulos.com/hegv/index.htm An Introductory VHDL Tutorial, Green Mountain Computing Systems: http://www.gmvhdl.com/VHDL.html http://www.gmvhdl.com/VHDL.html VHDL Tutorial by Ulrich Heinkel, Thomas Bürner and Martin Padeffke (in English and German): http://www.vhdl-online.de/~vhdl/TUTORIAL/http://www.vhdl-online.de/~vhdl/TUTORIAL/ VHDL-FSM-Tutorial by Martin Padeffke: http://www.vhdl-online.de/FSM/http://www.vhdl-online.de/FSM/ VHDL Verification Course by Stefan Doll: http://www.stefanVHDL.com/http://www.stefanVHDL.com/ E. Jamro, J.Kasperek, P.J.Rajda © 2009 Katedra Elektroniki AGH Kraków

43 VHDL – free IP cores OpenIP home page: http://www.opencores.orghttp://www.opencores.org System On Chip http://www.soccentral.com/http://www.soccentral.com/ Free behavioral models from Alatek: http://www.alatek.com/http://www.alatek.com/ The Hamburg VHDL archive: http://tams-www.informatik.uni-hamburg.de/research/vlsi/vhdl/ http://tams-www.informatik.uni-hamburg.de/research/vlsi/vhdl/ Rapid Prototyping of Application Specific Signal Processors (RASSP) www site: http://www.eda.org/rassp/http://www.eda.org/rassp/ Doulos High Level Design Web site; Monthly-updated Original Models (developed by Doulos): http://www.doulos.com/fi/http://www.doulos.com/fi/ A VHDL synthesizable model for the MICROCHIP PIC 16C5X microcontroller by Tom Coonan: http://www.mindspring.com/~tcoonan/http://www.mindspring.com/~tcoonan/ VHDL Library of Arithmetic Units developed by R. Zimmermann: http://www.iis.ee.ethz.ch/~zimmi/arith_lib.html http://www.iis.ee.ethz.ch/~zimmi/arith_lib.html E. Jamro, J.Kasperek, P.J.Rajda © 2009 Katedra Elektroniki AGH Kraków


Pobierz ppt "VHDL Ernest Jamro, Paweł Russek C3 p. 504"

Podobne prezentacje


Reklamy Google