Entwurf digitaler Schaltungen Groÿe Übung3 Simulation mit ghdltech · Übersetzen in ein...
Transcript of Entwurf digitaler Schaltungen Groÿe Übung3 Simulation mit ghdltech · Übersetzen in ein...
Entwurf digitaler SchaltungenGroÿe Übung 3
Simulation mit ghdlProf. G. Kemnitz, Dr. C. Giesemann
Institut für Informatik, Technische Universität Clausthal7. Mai 2015
Prof. G. Kemnitz, Dr. C. Giesemann · Institut für Informatik, Technische Universität Clausthal7. Mai 20151/26
1. Simulation mit ghdl
Simulation mit ghdl
Prof. G. Kemnitz, Dr. C. Giesemann · Institut für Informatik, Technische Universität Clausthal7. Mai 20152/26
1. Simulation mit ghdl 1. Debug-Ausgaben
Debug-Ausgaben
Prof. G. Kemnitz, Dr. C. Giesemann · Institut für Informatik, Technische Universität Clausthal7. Mai 20153/26
1. Simulation mit ghdl 1. Debug-Ausgaben
Textausgabe mit ghdl
VHDL-Programme lassen sich wie C-Programme mitformatierten Ausgaben testen. Erfordert Package mitAusgabefunktionen. In Tuc.Ausgabe sind de�niert:
procedure write(s: STRING); // Ausgabe Zeichenkettefunction str(x: <typ>; [<formatangabe>]);
str() ist für alle behandelten Datentypen überladen.
Programmrahmen unter Nutzung von �Tuc.Ausgabe�:library Tuc;
use Tuc.Ausgabe.all;
entity ausgabetest is end entity;
architecture a of ausgabetest isbegin... -- hier steht der zu simulierende Prozess
end architecture;
Prof. G. Kemnitz, Dr. C. Giesemann · Institut für Informatik, Technische Universität Clausthal7. Mai 20154/26
1. Simulation mit ghdl 1. Debug-Ausgaben
processvariable a: integer := 25;variable b: bit;beginwait for 10 ps;write("t=" & str(now) & " a=" & str(a) & " b=" & str(b));wait for 10 ns; a := 56; b := '1';write("t=" & str(now) & " a=" & str(a) & " b=" & str(b));wait;
end process;
Anmerkungen:�now� aktuelle Simulationszeit vom Typ �time��&� Konkatenationsoperator zum Verketten vonTextbausteinen
Ausgabe:t=10.00 ps a=25 b=0t=10.01 ns a=56 b=1
Prof. G. Kemnitz, Dr. C. Giesemann · Institut für Informatik, Technische Universität Clausthal7. Mai 20155/26
1. Simulation mit ghdl 1. Debug-Ausgaben
Ausprobieren
zip-Archiv mit den Dateien zu Übung von der Web-Seite laden.Entpacken. Erzeugen der Bibliothek �Tuc� mit dem Package�Ausgabe� im Verzeichnis �Tuc� auf der Kommandozeile:
ghdl -a --work=Tuc Ausgabe.vhdl
Analysieren des VHDL-Programms im Verzeichnis mit�ausgabetest.vhdl�:
ghdl -a -PTuc1 ausgabetest.vhdl2
Übersetzen in ein ausfühbares Programm (Make):
ghdl -m -PTuc ausgabetest3
Ausführen (Run)
ghdl -r -PTuc ausgabetest
1Pfad zur Bibliothek �tuc-obj93.cf�.2Datei mit der VHDL-Quelle.3Entity-Name
Prof. G. Kemnitz, Dr. C. Giesemann · Institut für Informatik, Technische Universität Clausthal7. Mai 20156/26
1. Simulation mit ghdl 2. Beobachterprozess
Beobachterprozess
Prof. G. Kemnitz, Dr. C. Giesemann · Institut für Informatik, Technische Universität Clausthal7. Mai 20157/26
1. Simulation mit ghdl 2. Beobachterprozess
Beobachterprozess
Für eine Schaltung mit Eingabe x und Ausgabe y sollen für jedenÄnderungszeitpunkt die Werte aufgelistet werden:
Beobachter: process(x, y)beginif now = 0 ps thenwrite(LF & " Zeit | x | y |");
elsewrite(rechts(str(now), 9) & " | " & str(x) & " | " & str(y) & " |");
end if;end process;
Prozesse mit Weckliste, Aufruf bei �now=0 ps� und jederÄnderung von x oder y.bei �now=0 ps� wird Tabellenkopf geschriebenrechts() verlängert den Ausgabetext um führendeLeerzeichen. LF � Line feed.
Prof. G. Kemnitz, Dr. C. Giesemann · Institut für Informatik, Technische Universität Clausthal7. Mai 20158/26
1. Simulation mit ghdl 2. Beobachterprozess
Simulation mit Beobachterprozess
... library-, use- und entity-Anweisungenarchitecture a of beobpro issignal x: std_logic_vector(3 downto 0);signal y: std_logic_vector(1 downto 0);
begin
Eingabeprozess: processbeginwait for 10 ns; x <= "0101";wait for 5 ns; x <= "1101";wait;
end process;
-- Testobjekt als 2 nebenlaeufige Signalzuweisungeny(0) <= 'X' after 1.2 ns, x(0) and x(1) after 2.4 ns;
y(1) <= 'X' after 1.1 ns, x(2) and x(3) after 3.1 ns;
Beobachter: ...end architecture;
Prof. G. Kemnitz, Dr. C. Giesemann · Institut für Informatik, Technische Universität Clausthal7. Mai 20159/26
1. Simulation mit ghdl 2. Beobachterprozess
Ausprobieren
Die Bibliothek �Tuc� sei bereits erzeugt. Im Verzeichnis mit derVHDL-Datei:
ghdl -a -PTuc BeobProzess.vhdl # Analysierenghdl -m -PTuc beobpro # Makeghdl -r -PTuc beobpro # Ausführen
Ausgabe:Zeit | x | y | 5.20 ns | 0101 | XX |
1.10 ns | UUUU | XU | 6.40 ns | 0101 | X0 |1.20 ns | UUUU | XX | 7.10 ns | 0101 | 00 |2.40 ns | UUUU | XU | 7.50 ns | 1101 | 00 |3.10 ns | UUUU | UU | 8.60 ns | 1101 | X0 |4.00 ns | 0101 | UU | 10.60 ns | 1101 | 10 |5.10 ns | 0101 | XU |
Prof. G. Kemnitz, Dr. C. Giesemann · Institut für Informatik, Technische Universität Clausthal7. Mai 201510/26
1. Simulation mit ghdl 2. Beobachterprozess
Der Eingabeprozess...wait for 4 ns; x <= "0101";wait for 3.5 ns;x <= "1101"; ...
wartet zweimal und weist zweimal neue Werte zu. Dienebenläu�gen Signalzuweisungen
y(0) <= 'X' after 1.2 ns, x(0) and x(1) after 2.4 ns;y(1) <= 'X' after 1.1 ns, x(2) and x(3) after 3.1 ns;
weisen nach jeder Änderung von ihren Eingaben nach derHaltezeit �unbestimmt� und nach der Verzögerungszeit denneuen Wert zu. Nochmal die Ausgabe:
Zeit | x | y | 5.20 ns | 0101 | XX |1.10 ns | UUUU | XU | 6.40 ns | 0101 | X0 |1.20 ns | UUUU | XX | 7.10 ns | 0101 | 00 |2.40 ns | UUUU | XU | 7.50 ns | 1101 | 00 |3.10 ns | UUUU | UU | 8.60 ns | 1101 | X0 |4.00 ns | 0101 | UU | 10.60 ns | 1101 | 10 |5.10 ns | 0101 | XU |
Prof. G. Kemnitz, Dr. C. Giesemann · Institut für Informatik, Technische Universität Clausthal7. Mai 201511/26
1. Simulation mit ghdl 2. Beobachterprozess
Graphische Simulationsausgabe
Ausgabe der Simulationsergebnisse in eine Wave-Datei:
ghdl -r -PTuc beobpro --wave=beobpro.ghw # Ausführengtkwave beobpro.ghw beobpro.sav # Viewer starten
Prof. G. Kemnitz, Dr. C. Giesemann · Institut für Informatik, Technische Universität Clausthal7. Mai 201512/26
1. Simulation mit ghdl 2. Beobachterprozess
Falls das Save-File im Beispiel �beobpro.sav� noch nichtexistiert4:
im SST-Fenster Hierarchie aufklappen, Signale auswählen5
Die Busse in der Signals-Spalte auswählen und mit �Edit >Expand� Busse aufklappen.Mit �Time > Zoom > ...� darzustellendes Zeitfensterauswählen.Mit �Edit > Data Format > Binary� Datenformatauswählen,...
Wenn die Darstellung stimmt, Darstellungseinstellungen mit�File > Write Save File� speichern.
4Zum ausprobieren gtkwave schlieÿen und mit nicht existierenderSave-Datei aufrufen, z.B. �gtkwave beobpro.ghw test.sav�.
5Oben auswählen, im Fenster Signals nochmal auswählen und unter�Append� drücken.
Prof. G. Kemnitz, Dr. C. Giesemann · Institut für Informatik, Technische Universität Clausthal7. Mai 201513/26
1. Simulation mit ghdl 3. Fehlersuche
Fehlersuche
Prof. G. Kemnitz, Dr. C. Giesemann · Institut für Informatik, Technische Universität Clausthal7. Mai 201514/26
1. Simulation mit ghdl 3. Fehlersuche
Beschreibung mit Entwurfsfehler
0 2 4 6 8 1012 tsim
10
10
10c110
a
b
c2
(c1 ohne, c2 mit Fehler)
signal a, b, c: STD_LOGIC;
...
process
begin
c <= a and b after 2 ns;
wait on a, b;
end process;
Bestimmen Sieden Ausgabesignalverlauf des korrekten Simulationsmodellsdie Ausgabe wenn in der Warteanweisung das Signal b fehlt.
Was passiert, wenn die gesamte Warteanweisung fehlt? Warumist der Fehler schwer zu lokalisieren?
Prof. G. Kemnitz, Dr. C. Giesemann · Institut für Informatik, Technische Universität Clausthal7. Mai 201515/26
1. Simulation mit ghdl 3. Fehlersuche
Kontrolle mit dem Simulator
library ieee; -- es wird nur std_logic
use ieee.std_logic_1164.all; -- gebraucht
entity vglsim is end entity; -- Entity ohne Signale
architecture a of vglsim is
signal a, b, c1, c2: STD_LOGIC;
begin
-- Eingabe als nebenläufige Signalzuweisungen
a <= '0', '1' after 3 ns, '0' after 7.5 ns,
'1' after 10.5 ns;
b <= '1', '0' after 5.5 ns, '1' after 9 ns,
'0' after 15.5 ns, '0' after 20 ns6;
6Die eigentlich über�üssige Änderung nach 20 ns verlängert dieWave-Darstellung bis 20 ns.
Prof. G. Kemnitz, Dr. C. Giesemann · Institut für Informatik, Technische Universität Clausthal7. Mai 201516/26
1. Simulation mit ghdl 3. Fehlersuche
-- richtige Beschreibung:
process
begin
c1 <= a and b after 2 ns;
wait on a, b;
end process;
-- fehlerhafte Beschreibung:
process
begin
c2 <= a and b after 2 ns;
wait on a; -- hier fehlt �wait on b�
end process;
end architecture;
Prof. G. Kemnitz, Dr. C. Giesemann · Institut für Informatik, Technische Universität Clausthal7. Mai 201517/26
1. Simulation mit ghdl 3. Fehlersuche
Ausführung und Ergebnis
del work-obj93.cf # Arbeitsbibliothek löschen
ghdl -a vglsim.vhdl # analysieren
ghdl -m vglsim # Make
ghdl -r vglsim --wave=vglsim.ghw # ausführen
gtkwave vglsim.ghw vglsim.sav # anzeigen
Prof. G. Kemnitz, Dr. C. Giesemann · Institut für Informatik, Technische Universität Clausthal7. Mai 201518/26
1. Simulation mit ghdl 4. Getaktete Schaltung
Getaktete Schaltung
Prof. G. Kemnitz, Dr. C. Giesemann · Institut für Informatik, Technische Universität Clausthal7. Mai 201519/26
1. Simulation mit ghdl 4. Getaktete Schaltung
Rückgekoppeltes Schieberegister (LFSR7)
1 Beschreiben Sie das nachfolgende rückgekoppelte Schiebere-gister in VHDL mit Schnittstelle und nur einem Prozess.
2 Bestimmen Sie die Ausgabesignalverläufe für y0 bis y2.3 Schreiben Sie einen Testrahmen mit dem rückgekoppeltenSchieberegister als Testobjekt und einem Prozess, der dieEingabesignale rechts erzeugt.
I I I=1
10
10
10
10
10
51 2 3 4 6 7 8 9 10
IT
T
Iy0y1y2 y0
y1
y2
Takt:
7LFSR � linear feedback shift register.
Prof. G. Kemnitz, Dr. C. Giesemann · Institut für Informatik, Technische Universität Clausthal7. Mai 201520/26
1. Simulation mit ghdl 4. Getaktete Schaltung
LFSR-Beschreibungsrahmen
library ieee;
use ieee.std_logic_1164.all;
entity lfsr isport (T, I: in std_logic;y: out std_logic_vector(2 downto 0)
);
end entity;
architecture a of lfsr issignal s: std_logic_vector(2 downto 0);begin... -- Prozess zur Beschreibung der Übergangsfunktiony <= s;
end architecture;
Prof. G. Kemnitz, Dr. C. Giesemann · Institut für Informatik, Technische Universität Clausthal7. Mai 201521/26
1. Simulation mit ghdl 4. Getaktete Schaltung
Prozess zur Beschreibung der Übergangsfunktion
I I I=1
IT
y0y1y2
process(T)beginif I='1' then -- wenn I aktivs <= "000"; -- initialisieren
elsif rising_edge(T) then -- sonst bei stei--- gender Taltflanke
s(2 downto 1) <= s(1 downto 0); -- Schiebefunktions(0) <= not(s(1) xor s(2)); -- Rückkopplung
end if;end process;
Prof. G. Kemnitz, Dr. C. Giesemann · Institut für Informatik, Technische Universität Clausthal7. Mai 201522/26
1. Simulation mit ghdl 4. Getaktete Schaltung
Testrahmen
library Tuc;use Tuc.Ausgabe.all;library ieee;
use ieee.std_logic_1164.all;
entity lfsr_test is end entity;
architecture a of lfsr_test issignal T, I: std_logic;signal y: std_logic_vector(2 downto 0);
begin
-- Instanz des TestobjektsTObj: entity work.lfsr(a)
port map(I=>I, T=>T, y=>y);
-- Eingabeprozess
...
end architecture;Prof. G. Kemnitz, Dr. C. Giesemann · Institut für Informatik, Technische Universität Clausthal7. Mai 201523/26
1. Simulation mit ghdl 4. Getaktete Schaltung
Eingabeprozess
10
10
51 2 3 4 6 7 8 9 10
T
ITakt:
0 20 40 60t in nsprocess
beginI <= '0', '1' after 11 ns, '0' after 18 ns;write("Takt| Ausgabe");for idx in 1 to 10 loop
T <= '1' after 3 ns, '0' after 8 ns;wait for 10 ns;write(rechts(str(idx),3) & " | " & str(y));
end loop;wait;
end process;
Prof. G. Kemnitz, Dr. C. Giesemann · Institut für Informatik, Technische Universität Clausthal7. Mai 201524/26
1. Simulation mit ghdl 4. Getaktete Schaltung
Simulationghdl -a lfsr.vhdl # Testobjekt analysierenghdl -a -PTuc lfsr_test.vhdl # Testrahmen analysierenghdl -m -PTuc lfsr_test # Makeghdl -r -PTuc lfsr_test --wave=lfsr_test.ghw # ausführengtkwave lfsr_test.ghw lfsr_test.sav # anzeigen
Ausgabe:Takt| Ausgabe
1 | UUU2 | 0003 | 0014 | 0115 | 1106 | 1017 | 0108 | 1009 | 000
10 | 001Prof. G. Kemnitz, Dr. C. Giesemann · Institut für Informatik, Technische Universität Clausthal7. Mai 201525/26
1. Simulation mit ghdl 4. Getaktete Schaltung
Aufgaben
Erweitern Sie den Testrahmen um die Erzeugung desdargestellten Signalverlaufs für das Eingabesignal x und dasLFSR um den Eingang x.
I I I=1
=1
10
10
51 2 3 4 6 7 8 9 10
0 20 40 60t in ns
10
T
ITaktnr.:
x
y0y1y2
IT
x
Prof. G. Kemnitz, Dr. C. Giesemann · Institut für Informatik, Technische Universität Clausthal7. Mai 201526/26