Hardwarebeschreibungssprachen

Aus II-Wiki
Zur Navigation springen Zur Suche springen
Hardwarebeschreibungssprachen (HBS)
Vertiefungsrichtung II/IHS
Vorlesung
Vorlesender

Dr.-Ing. Steffen Arlt

Abschluß
Art k.A.


Vorteile der Nutzung von Hardwarebeschreibungssprachen, Erlernen der syntaktischen Grundelemente von VHDL, Überblick über gängige Simulations- und Synthesewerkzeuge, Unterschiede zur Hardwarebeschreibungssprache Verilog, Simulation von VHDL-Designs, Synthesegerechte VHDL-Modellierung, Alternative Beschreibungskonzepte (System C)

Prüfung

Klausur
Termin
Datum: 25.02.2011
Zeit: 09:00 - 10:30
Ort: Sr HU 211/212


Am Ende des Semester gibt es eine Klausur die über 90 Minuten geht. Es sind alle selbst erstellten Unterlagen und die vorgefertigten in der Klausur zugelassen.

Klausur HBS WS2010/11

Inhalt:

  • Beschreibungssprachen
    • Warum HDL?
    • Y-Diagramm
    • Unterschiede zwischen VHDL 87 und VHDL 93
    • Unterschied zwischen Signal und Variable
    • case-Anweisung
    • Verzögerungsmodell
    • nicht synthesefähige Anweisungen
    • Flankendetektor
    • 32 Bit Vektor zu null setzten
    • Process vervollständigen (war ein FlipFlop)
    • korrigieren eines Codes
    • Beschreibung eines Automatengraphen in VHDL

Zu den meisten Punkten sollten auch immer Beispiele angegeben werden.

Vorlesungsmitschriften

1. Vorlesung

Motivation

  • Lücke zwischen Integrationsdichte und Design
  • Steigende Komplexität
    • 1970 Intel CPU 4004
      • 4 Bit, 10µm, 600mm 2 , 0, 74MHz, 2, 25k Transistoren
    • 1997 Intel CPU Pentium 2
      • 32 Bit, 0, 35µm, 203mm 2 , 300MHz, 7.500k Transistoren
    • 2005 Intel CPU Pentium 4 6xx
      • 64 Bit, 0, 09µm, 135mm 2 , 3587, 8MHz, 169.000k Transistoren
  • Abstraktion, Generik
  • Time to Market
  • Intellectual Properties (IP) & Reuse
  • Regularität
  • Information Hiding
  • Modularität

Was ist eine HDL?

Modellierungssprachen für die Simulation und Implementierung elektronischer Schaltungen

  • Dokumentationsmittel speziell auf höherem Abstraktionsniveau
  • Übliche HDLs: VHDL, ABEL, Verilog, Altera-HDL, UDL/I
  • Unterschiede zu Hochsprachen wie C, C++, Pascal:
    • Beschreibung von Parallelität¨at
    • strukturelle Beschreibung (Entwurf des Steuer- und Datenflusses)
    • Existenz entsprechender Datentypen f¨ur die Modellierung von Signalvektoren und Signalpegeln
Anwendungen

Spezifikation

  • Verifikation, Modellierung ⇒ Simulation
  • Synthese
  • Dokumentation

Historie VHDL

VHSIC Very High Speed Integrated Circuits - Programm des DoD ` VHDL- Hardware Description Language

  • 1981 erste Anforderungen
  • 1983-1985 VHDL-Entwicklung von Intermetrics, IBM, TI
  • 1987 IEEE Standard 1076-1987 VHDL-87
  • 1991 IEEE Standard 1164 (neunwertige Logik)
  • 1993 IEEE Standard 1076-1993 VHDL-93
  • 1995 IEEE Standards 1076.3 1076.4

Historie Verilog

  • 1985 Verilog- Spache und Simulator von Gateway Automation entwickelt
  • 1985-1989 wachsende Zunahme der Verwendung von Verilog bei ASIC-Herstellern
  • 1989 Verilog wird von Cadence ¨ubernommen
  • 1990 Formulierung von Open Verilog International (OVI)
  • 1995 IEEE Standard 1364

Kurzvergleich

  • VHDL bietet mehr lexikalische Elemente (erweiterte Typdefinitionen, Variablen)
  • Vorteile von Verilog liegen bei der Simulation von Netzlisten mit Timingmodellen, ist an C angeleht, keine strenge Typprüfung
  • Die Favorisierung einer Sprache ist bei den heute verfügbaren Simulations- und Synthesewerkzeugen nicht mehr notwendig
  • Europa: ca. 90% Nutzung von VHDL
  • USA: ca.50% Nutzung von VHDL
  • Verilog oft effizienter als VHDL

2. Vorlesung

3. Vorlesung

4. Vorlesung

5. Vorlesung

Operatoren

logische Operatoren: and, or, nand, nor, xor, xnor, not

<source lang="vhdl"> x <= a xnor b; x_vec <= a_vec and b_vec; -- bei Vektoren Bitweise </source>

relative Operatoren: =, /=, <, <=, >, >=

arithmetische Operatoren: sign + - , +, -, &, *, /, mod, rem, **, abs()

Bsp.: <source lang="vhdl">

 5 mod 3 = 2

- 5 mod 3 = 1

 5 mod (-3) = -1 

- 5 mod (-3) = -2

 5 rem 3 = 2

- 5 rem 3 = -2

 5 rem -3 = 2

- 5 rem -3 = -2 </source> Shift Operatoren: SLL, SRL, SLA, SRA, ROL, ROR

Nebenläufige Anweisungen

<source lang="VHDL"> architecture <concurrent decluration part> begin --concurrent VHDL begin concurrent part process (...) sequential decluration part begin sequential VHDL end process end --concurrent VHDL end </source>

  • process
  • bedingte Signalzuweisung (condition signal assignment)

<source lang="VHDL"> <sig_id> <= <waveform>/sig_value when <condition> else <condition> </source>

Bsp.: <source lang="VHDL"> q <= a when addr = "oo" else -- Vergleichbar if-then, elsif- else Konstruktion

    b when addr = "11" else
    c;					-- alternative: unaffected;

</source>

  • selektive Signalzuweisung (selected signal assignment)

<source lang="VHDL"> with addr select -- entspricht einem Multiplexer (HBS 4-12) q = a when "00", b when "11", c when others; </source>

case-Konstrukt

<source lang="VHDL"> architecture Mux1 of MUX is -- Skizze (HBS 4-12) begin y <= (I(0) and not E and not S)

             or (I(1) and not E and S);

end Mux1;

architecture Mux2 of Muc is begin y <= (I(0) and not E) when s = '0' else (I(1) and not E); end Mux2;

architecture rtl1 or test is signal a,b,c,d,e : std_logic; begin d <= a and (b or c); e <= a or b; end rtl1;

architecture rtl2 of test is begin process (a,b,c) variable var: std_logic; begin var := b or c; d <= a and var; end process; process (a,b) begin e <= a or b; end process; end rtl2; </source>

<source lang="VHDL"> process (a) wait until a = 1; wait on a; wait for 10ns;

wait for 2* period; wait until a = 1 for 10ns; </source>

Bsp.: Verzögerungsmodell <source lang="VHDL"> process (a) -- Skizze (HBS 4-13) begin c1 <= not a; end process;

process begin c2 <= not a; wait on a; end process;

process begin wait on a; c3 <= not a; end process;

process begin wait until a = '1'; c4 <= not a; end process;

process begin c5 <= not a; wait until a = '1' for 10ns; end process; </source>

Sequentielle Statements

<source lang="VHDL"> if addr = "00" then q <= a; elsif addr = "11" then q <= c; end if;

case addr is when "00" => q <= a; when "11" => q <= b; when others => q <= c; end case;

type alu_mod is (addr, sub, idle); -- Null-Anweisung variable sel: alu_mod; case sel is when add = c := a + b; when sub = c := a - b; when idle => null; end case; </source>

6. Vorlesung

Schleifen

  • "loop"
  • Abbruch exit, next
bedingungslose Schleife

<source lang="vhdl"> <label> : loop . . . end loop [<label>]; </source>

Bsp.: <source lang="vhdl"> elementar_loop : loop if i = 31 then exit; else i := i+1; q(i) <= '0'; end if; end loop elementar_loop; </source>

for-Schleifen

<source lang="vhdl"> <label> : for <index> in <range> loop . . . end loop [<label>]; </source> Bsp.: <source lang="vhdl"> for i in 0 to 31 loop addr(i) <= '0'; end loop; </source>

while-Schleifen

<source lang="vhdl"> <label> : while <condition> loop . . . end loop; </source> Bsp.: <source lang="vhdl"> while i<5 loop q(i) <= data_in(i) i := i + 1; end loop; </source>

optionales & zusätzliches

<source lang="vhdl"> [<label>] exit [<label>] [when]: next </source>

Unterprogramme (Subprograms)

  • function, procedure
  • Operatoren, Datentypen, Konstanten, Konvertierung
  • lokal (in einer architecture), global (package)
  • rein sequenzielles VHDL
  • laut IEEE_1076.6 sind Signaldeklarationen nicht synthesefähig
  • Rekursion - nicht synthesefähig!
Funktionen
  • mehrere Übergabeparameter
  • ein Rückgabewert

<source lang="vhdl"> function <func_id> (<parameter_list>) return <type_id> is <variable. constant, type declaration>; begin <ssequential statements> return <id>; end [<func_id>];

Bsp.: <source lang="vhdl"> funtion vec2int (v:std_logic_vector) return integer is variable tmp: integer := 0; begin for i in v'range loop tmp : = tmp*2; if v(i) = '1' then tmp := tmp + 1; end if; end loop; return tmp; end vec2int;

(int_var := vec2int(vec_var)) </source>

function overloading

<source lang="vhdl"> type tri_logic is ('0', '1', 'K'); function and (in_1: tri_logic; in_2: tri_logic) return tri_logic is begin if in_1 = '1' and in_2 = '1'then return '1'; elsif in_1 = '0' or in_2 = '0' then return '0'; else return 'K'; end if; end and; </source>

Zustände von Funktionen: pure, impure

Prozeduren
  • liefern keine Rückgabewerte: nicht in Ausdrücken
  • mehrere Ü-Parameter möglich (in, out, inout)
  • [in = ro]
  • [out = wo]
  • [inout = r/w]

<source lang="vhdl"> procedure <proc_id> (<param_list>] is <declaration> begin <sequ. VHDL> end [<proc_id>]; </source>

Bsp.: <source lang="vhdl"> procedure std_logicvec2int (v: in std_logic_vector; f: out boolean; result: out int) is variable tmp : integer := 0; begin result := 0; f := true; for i in v'range loop result := result*2; if v(i) = '1' then result := result + 1; f := false; end if; end loop; end std_logic2int; </source>

Assertion
  • Überprüfung von Bedingungen und Angaben von errors, warnings
  • Meldung wenn Bedingung "false"
  • default Meldung: "Assertion violution"

<source lang="vhdl"> assert <not condition> [report]["<text>"][severity]]serverity_level] { <note|warning|failure> </source>

  • default für severity_level ist error

Bsp.: <source lang="vhdl"> assert (a = '1' and b = '1') report "a and b not equal '1' at same time" severity warning; </source>

7. Vorlesung

Interne Behandlung von Signalen und Variablen

<source lang="vhdl"> sig <= <waveform>, ... waveform = <expr.>[after time] | unaffected </source>

Transaktionslisten
  • (current_time + time, value)
  • delta - Delay: 1/unendlich, Summe = (1/unendlich)

wählt Aktion2 <source lang="vhdl"> signal x : std_logic := 0; process (...) begin x <= '1'; if (x = '1') then -- Aktion1 else -- Aktion2 end if; end process </source>

wählt Aktion1 <source lang="vhdl"> process (...) variable x : std_logic := 0; begin x := '1'; if (x = '1') then -- Aktion1 else -- Aktion2 end if; end process; </source>

Simulationsablauf
Initialisierung
  • Wertzuweisungen
  • Simulationtime = 0
  • alle Prozesse anstarten

Aktualisierung

  • Bestimmung von next_time und next_event aus der Transaktions + Weckliste
  • current_time auf next_time
  • => Ausführen der Transaktionen, Wertzuweisungen + Aktivierung von Prozessen
  • Löschen der aktiven Transaktionen

Ausführen der Prozesse

  • aller aktivierten Prozesse
  • Weränderung erst nach Prozess-Stop
  • (Schleife aus Aktualisierung & Ausführen von Prozesse)

Simulationsende

  • alle Transktionslisten leer
  • keine Events mehr ausführen
  • Signale stabil
  • Zeitlimit

Bsp.: <source lang="vhdl"> constant check_periode : time := 250ns; begin process begin clk <= 0; wait for clock_period/2; clk <= 1; wait for clock_periode/2; end process; </source>

Alternativ <source lang="vhdl"> clk <= not clk after 125ns; </source>

Verzögerungsmodelle bei Signalzuweisungen

<source lang="vhdl"> <sig> <= [<inertial(default)|transport>]<waveform>,... </source>

Bsp.: <source lang="vhdl"> begin a <= '0', '1' after 10ns, 'o' after 30ns, '1' after 50ns, '0' after 58ns; b <= '0', '1' after 15ns; c <= inertial a and b after 12ns; d <= transport a and b after 12ns; e <= reject 8ns inertial not a after 10ns;

process(clk) variable num, sum integer range 0 to 15 := 0; begin if (clk = '1' and clkevent) then veq_q0 <= sum; num := num + 1; sum := num + 1; veq_q1 <= sum; end if; end process;

signal num, sum : integer range 0 to 15 := 0; process(clk) begin if (clk = '1' and clkevent) then veq_q0 <= sum; num <= num + 1; sum <= num + 1; veq_q1 <= sum; end if; end process; </source>

8. Vorlesung

Entwurfsbeispiele

Latch (HBS_5-3)

Definition: Ein Latch (engl. für Schnappschloss, Auffangregister), oder auch als zustandsgesteuertes Flipflop bezeichnet, ist eine bestimmte Ausführung eines elektronischen 1-Bit-Datenspeichers und bildet(e) die Grundlage für weite Bereiche der Digital-Hardware, insbesondere innerhalb CPU- und Peripherie-Chips.

Im Gegensatz zu taktflankengesteuerten Flipflops ist ein Latch während der gesamten aktiven Taktphase transparent, d. h. Eingangsänderungen können den Ausgang sofort beeinflussen.

<source lang="vhdl"> entity LATCH is port (d, en : in bit; q : out bit); end LATCH; architecture test1 of LATCH is beagin process (en, d) begin if en = '1' then q <= d; -- else -- q <= q; end if; end process; end test1;

architecture test2 of LATCH is begin process (clk, d) begin case clk is when '1' => q <= d; when '0' => null; end process; end test2;

architecture test3 of LATCH is signal temp : bit; begin process (en, d) begin if en = '1' then q <= temp; else temp <= d; end if; end process; end test3;

architecture test4 of LATCH is begin process (en, d) variable temp : bit; begin temp := 0; if en = '1' then temp <= d; end if; q <= temp; end process; end test4;

architecture test5 of LATCH is begin process (en, d) variable temp : bit; begin temp := 0; if en = '1' then temp <= d; else temp := not temp; end if; q <= temp; end process; end test5; </source>

FLipFlops

Definition: Ein Flipflop (engl. flip-flop), meist auch bistabile Kippstufe oder bistabiles Kippglied genannt, ist eine elektronische Schaltung, die zwei stabile Zustände einnehmen und diese speichern kann.

Das Flipflop ist eine einfache elektronische Schaltung, welche eine Datenmenge von einem Bit über eine lange Zeit speichern kann. Es ist fundamentaler Bestandteil vieler elektronischer Schaltungen (sequentieller Schaltkreise) – von der Quarzuhr bis zum Mikroprozessor. Daneben ist es in vieltausend- bis milliardenfacher Ausführung in Computerspeicherchips (statischen Speicherbausteinen) enthalten.

Asynchrones Reset D-Flip Flop

<source lang="vhdl"> Library ieee; use ieee.std_logic_1164.all; entitiy FF is port (clk : in std_logic; reset : in std_logic; d : in std_logic; q : out std_logic); end FF; architecture rtl of FF begin process (clk, reset) begin if reset = '0' then q <= 0; elsif (clk = '1' and clk'event) then q <= d; end if; end process; end rtl; </source>

Alternative für Simulation <source lang="vhdl"> wait until clk'event and clk = '1' if rising_edge(clk) (falling) </source>

Synchrones Reset Preset D-FlipFlop

<source lang="vhdl"> architecture rtl2 of FF is begin process(clk) begin if (clk = '0' and clk'event) then if (reset = '0' then q <= '0': elsif preset = '0' then q <= '1'; elsif enable = '1' then q <= d; else null; end if; end if; end process; end rtl2; </source>

Zähler
Johnson-Zähler

<source lang="vhdl"> Library ieee; use idee.std_logic_1164.all; entity johnson is port (clk : in std_logic; sum : out std_logic_vector (3 downto 0); end johnson; architecture rtl of johnson is begin process(clk) variable count : std_logic_vector (3 downto 0); begin if (clk = '1' and clk'event) then for i in 3 downto 1 loop count(i) := count(i-1); end loop; count(0) := not count(3); end if; sum <= count; end process; end rtl; </source>

9. Vorlesung

Schieberegister

<source lang="vhdl"> library ieee; use ieee.std_logic_1164.all; entity shiftreg is port (ld_shift, clk : in std_logic; ld_val : in std_logic_vector (4 downto 0); ser_out : out std_logic); end shift_reg;

architecture rtl of shift_reg is signal temp : std_logic_vector (4 downto 0); begin process (clk) begin if (clk = '1' and clk'event) then if ld_shift = '1' then tmp <= ld_val; else tmp (4 downto 0) <= temp (3 downto 0) & '0'; end if; end if; end process; end rtl; </source>

  • Beispiel zwei fehlt...

Finite State Machines (FSM)

Automaten
Automatenentwurf

Zustandskodierung binär hot one

  1. FlipFlops {ld n} n

k komplexer i.a. einfach

  • "1001" -> FSM -> 1

Skizze

<source lang="vhdl"> library ieee; use ieee.std_logic_1164.all; entity detect_fsm is port(x, rst ,clk : in std_logic; y : out std_logic); end detect_fsm;

architecture rtl of detect_fsm is type state_type is (z0, z1, z2, z4); signal next_state, current_state : state_type; begin next_state_process: process (current_state, x) begin case current_state is when z0 => if x = '1' then next_state <= z1; end if; z1 => if x = '0' then next_state <= z2; end if; z2 => if x = '0' then next_state <= z3; else next_state <= z1; end if; when others => if x = '1' then next_state <= z1; else next_state <= z0; end if; end case; end process next_state process; output_process : process (current_state, x) begin if (current_state = z3 and x = '1') then y <= 1; else y <= 0; end if; end process output_process; clk_process: process(clk, rst) begin if (rst = '1') then current_state <= z0; elsif (clk = '1' and clk'event) then current_state <= next_state; end if; end process clk_process, end rtl; </source>

<source lang="vhdl"> architecture rtl2 of detect_fsm is type state_type is (z0, z1, z2, z4); signal state : state_type; begin process (rst, clk) begin if (rst = '1' then state <= z0; y<= 0; elsif (clk = '1' and clk'event) then case state is when z0 => if x = '1' then state <= z1; end if; when z1 => if x = '0' then state <= z2; end if; when z2 => if x = '0' then state <= z3; else state <= z1; end if; when others => if x = '1' then state <= z1; y <= 1; else state <= z0; end if; end case; end process; end rtl2; <source>

mit one hot Codierung <source lang="vhdl"> architecture rtl3 of detect_fsm is signal z0, z1, z2, z4 : std_logic; begin process (rst, clk) begin if (rst = '1' then z0 <= '1'; z1 <= '0'; z2 <= '0'; z3 <= '0'; y <= '0'; elsif (clk = '1' and clk'event) then z0 <= (z0 or z3) and not x; z1 <= x; z2 <= zi and not x; z3 <= z2 and not x; y <= z3 and x; end if; end if; end process; end rtl3; </source>

7-Segment-Anzeige

BCD a b c d e f g 0 0000 0 0 0 0 0 0 1 . . . 9 1001 0 0 0 0 1 0 0

6. Testbenches

  • drei Skizzen

10. Vorlesung

Testumgebung für einen MUX

<source lang="vhdl"> library ieee; use ieee.std_logic_1164.all; entity mux is port (in 0, in 1, sel : in std_logic; z : out std_logic); end mux;

architecture rtl of mux is begin with sel select z <= in 0 when '0'; in1 when others; end rtl;

entity tb is end tb

architecture tb_version1 of tb is component mux port (in 0, in 1, sel : in std_logic; 2 : out std_logic); end component,

signal in 0, in 1, sel z : std_logic; type sample is record in0 : std_logic; in1 : std_logic; sel : std_logic; end record;

type samples_array is array (natural rang <>) of sample; constant test_data : sample_array := (('0','0','0',),('0','0','1'),('0','1','0'),('0','1','1'),('1','0','0'),('1','0','1'),('1','1','0'),('1','1','1')); begin dut: mux port map(in0 => in0, in1 => in1, sel => sel, z => z); process begin for i in test_data'range loop in0 <= test_data(i).in0; in1 <= test_data(i).in1; sel <= test_data(i).sel; wait for 10 ns; end loop; wait end process;

process begin wait for 5ns; assert z = '0' report "wrong result" severity note; wait for 10ns; assert z = '0' report "wrong result" severity note; wait for 10ns; assert z = '0' report "wrong result" severity note; wait for 10ns; assert z = '1' report "wrong result" severity note; wait for 10ns; assert z = '1' report "wrong result" severity note; wait for 10ns; assert z = '0' report "wrong result" severity note; wait for 10ns; assert z = '1' report "wrong result" severity note; wait for 10ns; assert z = '1' report "wrong result" severity note; wait for 10ns; wait; end process; end tb_version1; </source>

VERILOG

Ripple Carry Counter

<source lang='verilog'> module ripple_carry_counter (q, clk, reset); output [3:0] q; input clk, reset; T_FF tff0 (q [0], clk, reset); T_FF tff1 (q [1], q [0], reset); T_FF tff2 (q [2], q [1], reset); T_FF tff3 (q [3], q [2], reset); end module

module T_FF(q, clk, reset); output q; input clk, reset; wire d; D_FF dff0 (q, d, clk, reset); not n1 (d, q); end module

module D_FF (q, d, clk, reset); output q; input d, clk, reset; reg q;

always @(posedge reset or negedge dk) if (reset) q = 1'b0; else q = d; end module </source>

Materialien

Das vollständige Skript der aus dem Downloadbereich:

Beschreibung zum FPGA-Board für das Praktikum:

Die Praktikumsanleitung zum Versuch Stoppuhr:

Die Praktikumsanleitung zum Versuch Signalgenerator:

Literaturhinweise

  • Hunter, R.D., Johnson, T.T.: Indruction to VHDL. Springer US 1995
  • Sjoholm, St., Lindh, L.: VHDL for Designers. Prentice Hall 1996
  • Reichardt, J.: VHDL-Synthese. Oldenbourg 2003
  • ältere Vorlesungsmitschrift