Uebung5_loesung

Transcription

Uebung5_loesung
DT2P, FS-2008, dqtm, gelk
Übung 5: VHDL Zähler
Aufgabe 1 RTL Diagramm Sekunden und Minuten Zähler.
(a) Entwerfen Sie ein RTL Diagramm für die Sekunden- und Minuten-Zähler des DCF77 Projekts.
(b) Bestimmen Sie die erwartete Anzahl von FFs und den längsten kombinatorischen Pfad.
Aufgabe 2 Count-Load-Enable.
(a) Analysieren Sie den unteren Code und zeichnen Sie das entsprechende RTL Diagramm.
(b) Schreiben Sie den Code um, mit getrennten Prozessen für kombinatorische und getaktete
Logik.
(c) Wie ändert sich der Code für einen synchronen Reset? Wie würde der kombinatorische
Prozess mit einem Default-Statement aussehen?
(d) Fügen Sie einen Überlaufwert hinzu. Sobald der Zähler diesen Überlaufwert erreicht, soll er
wieder bei 0 anfangen.
library ieee;
use ieee.std_logic_1164.all;
use ieee.numeric_std.all;
entity counter is port (
clk:
in std_logic;
reset: in std_logic;
load: in std_logic;
enable: in std_logic;
data: in std_logic_vector(3 downto 0);
count: out std_logic_vector(3 downto 0)
);
end counter;
architecture simple of counter is
signal countL: unsigned(3 downto 0);
begin
increment: process (clk, reset) begin
if (reset = '1') then
countL <= "0000";
elsif(clk'event and clk = '1') then
if (load = '1') then
countL <= to_unsigned(data);
elsif (enable = '1') then
countL <= countL + 1;
end if;
end if;
end process;
count <= std_logic_vector(countL);
end simple;
Quelle: http://vahana.com/examples.htm/ : cntlden.vhd
Zürcher Fachhochschule
Seite 1/10
dt2ueb5_zaehler_lsg.doc
DT2P, FS-2008, dqtm, gelk
Aufgabe 3 Down-Counter.
(a) Zeichnen Sie das RTL Diagramm eines Zählers mit synchronem Reset, der von 9 runter auf 0
dekrementiert, und dann wieder bei 9 anfängt. Die Ausgangssignale dieser Einheit sind count und
roll, beide von Datatyp std_logic.
(b) Das Signal roll ist aktiv hoch während einem Zyklus (ein Puls) wenn count=0. Zeichnen Sie ein
Zeitverlaufsdiagramm, welches das Verhalten von roll und count bezüglich dem Clock
Eingangssignal zeigt.
(c) Schreiben Sie den RTL Code für diesen Zähler, benutzen Sie getrennte Prozesse für
kombinatorische und getaktete Logik.
(d) Ist das Signal roll in Ihrem Code ein Ausgang eines FFs? Falls nicht, schreiben Sie eine
Variation von Ihrem Code mit roll als Ausgang eines FFs.
(e) Welchen Vorteil bringt es, Ausgangssignale als FF-Ausgänge zu implementieren?
Aufgabe 4 Code Analysieren
(a) Analysieren Sie den VHDL Code und zeichnen Sie das entsprechende RTL Diagramm.
(b) Bestimmen Sie die Anzahl von FFs, die man über die Synthese dieses Designs bekommt.
-- Description:
-- Up and Down Counter with configurable
-- width and overflow value (via generics)
-- History:
-- 15.Jan.2009 : 1st version M.Q.Tavares _ ZHAW
LIBRARY ieee;
USE ieee.std_logic_1164.all;
USE ieee.numeric_std.all;
ENTITY count_updown IS
GENERIC(n
: natural :=6;
ov_value : unsigned :=TO_UNSIGNED(59,6));
PORT ( clock : in std_logic;
reset_n : in std_logic;
cntup : in std_logic;
count : out std_logic_vector(n-1 downto 0));
END count_updown;
-- (continues on next page)
Zürcher Fachhochschule
Seite 2/10
dt2ueb5_zaehler_lsg.doc
DT2P, FS-2008, dqtm, gelk
-- (continued)
ARCHITECTURE rtl OF count_updown IS
--------------------------- SIGNAL & CONSTANT DECLARATIONS
-------------------------SIGNAL next_count : unsigned(n-1 downto 0);
SIGNAL i_count : unsigned(n-1 downto 0);
BEGIN
--------------------------- Register Process
-------------------------reg_count : process(reset_n,clock)
begin
if (reset_n='0') then
i_count <= (OTHERS =>'0');
elsif (clock'event and clock='1') then
i_count <= next_count;
end if;
end process reg_count;
--------------------------- Comb Process
-------------------------comb_count : process(i_count,cntup)
begin
-- Default Statement
next_count <= i_count;
-- count down & roll up at zero
if cntup='0' then
if (i_count = TO_UNSIGNED(0,n)) then
next_count <= ov_value;
else
next_count <= i_count - 1;
end if;
-- count up & roll down at overflow
else
if (i_count = ov_value) then
next_count <= TO_UNSIGNED(0,n);
else
next_count <= i_count + 1;
end if;
end if;
end process comb_count;
--------------------------- Concurrent assignements
-------------------------count <= std_logic_vector(i_count);
END rtl;
Zürcher Fachhochschule
Seite 3/10
dt2ueb5_zaehler_lsg.doc
DT2P, FS-2008, dqtm, gelk
Musterlösung
Aufgabe 1
Keine Lösung wird vorgegeben, sie ist Teil ihre Projektaufgabe.
Aufgabe 2
(a)
counter
countL
load
enable
data
4
4
D
D
D
D
C
CC
C
clock
Q
Q
Q
Q
4
count
R
RR
R
reset
(b)
architecture simple of counter is
-- Separated Comb & Reg Processes
-- with asynchronous reset (as original example)
signal next_countL:
signal countL:
library ieee;
use ieee.std_logic_1164.all;
use ieee.numeric_std.all;
unsigned(3 downto 0);
unsigned(3 downto 0);
begin
comb_increment: process (load,enable,data,countL)
begin
if (load = '1') then
next_countL <= unsigned(data);
elsif (enable = '1') then
next_countL <= countL + 1;
else
next_countL <= countL;
end if;
end process;
entity counter is port (
clk:
in std_logic;
reset: in std_logic;
load: in std_logic;
enable: in std_logic;
data: in std_logic_vector(3 downto 0);
count: out std_logic_vector(3 downto 0)
);
end counter;
reg_increment: process (clk,reset) begin
if (reset = '1') then
countL <= "0000";
elsif(clk'event and clk = '1') then
countL <= next_countL;
end if;
end process;
count <= std_logic_vector(countL);
end simple;
Zürcher Fachhochschule
Seite 4/10
dt2ueb5_zaehler_lsg.doc
DT2P, FS-2008, dqtm, gelk
(c ) Mit synchronem Reset: nur der kombinatorische Prozesse ändert sich.
-- Separated Comb & Reg Processes and synchronous reset
……
comb_increment: process (reset,load,enable,data,countL)
begin
if (reset = '1') then
next_countL <= "0000";
elsif (load = '1') then
next_countL <= unsigned(data);
elsif (enable = '1') then
next_countL <= countL + 1;
else
next_countL <= countL;
end if;
end process;
………
Der kombinatorische Prozesse kann man auch so schreiben (mit Default Statement) :
-- Separated Comb & Reg Processes and synchronous reset
….
comb_increment: process (reset,load,enable,data,countL)
begin
-- Default Statement
next_countL <= countL;
if (reset = '1') then
next_countL <= "0000";
elsif (load = '1') then
next_countL <= unsigned(data);
elsif (enable = '1') then
next_countL <= countL + 1;
end if;
end process;
……
Zürcher Fachhochschule
Seite 5/10
dt2ueb5_zaehler_lsg.doc
DT2P, FS-2008, dqtm, gelk
(d) Mit synchronem Reset, Default Statement und Überlauf Wert:
-- Separated Comb & Reg Processes and synchronous reset
-- Plus Default Statement and Overflow Value
library ieee;
use ieee.std_logic_1164.all;
use ieee.numeric_std.all;
entity counter is port (
clk:
in std_logic;
reset: in std_logic;
load: in std_logic;
enable: in std_logic;
data: in std_logic_vector(3 downto 0);
count: out std_logic_vector(3 downto 0)
);
end counter;
architecture simple of counter is
signal next_countL:
signal countL:
constant overflow:
unsigned(3 downto 0);
unsigned(3 downto 0);
unsigned(3 downto 0) := "1001";
begin
comb_increment: process (reset,load,enable,data,countL)
begin
-- Default Statement
next_countL <= countL;
if (reset = '1') then
next_countL <= "0000";
elsif (load = '1') then
next_countL <= unsigned(data);
elsif (enable = '1') then
if (countL < overflow) then
next_countL <= countL + 1;
else
next_countL <= (OTHERS => '0');
end if;
end if;
end process;
reg_increment: process (clk) begin
if(clk'event and clk = '1') then
countL <= next_countL;
end if;
end process;
count <= std_logic_vector(countL);
end simple;
Zürcher Fachhochschule
Seite 6/10
dt2ueb5_zaehler_lsg.doc
DT2P, FS-2008, dqtm, gelk
Aufgabe 3
(a)
roll als komb-output
downcounter
countL
reset
4
D
D
D
D
C
CC
C
clock
Q
Q
Q
Q
count
4
roll
R
RR
roll als seq-output
downcounter
countL
reset
5
D
D
D
D
C
CC
C
clock
Q
Q
Q
Q
5
4
count
roll
R
RR
(b)
Zürcher Fachhochschule
Seite 7/10
dt2ueb5_zaehler_lsg.doc
DT2P, FS-2008, dqtm, gelk
(c) roll als komb-output
------------------------------------------------- Downcounter 9 to 0 and return with sync-reset
-- Internal Signals with Unsigned
-----------------------------------------------library ieee;
use ieee.std_logic_1164.all;
use ieee.numeric_std.all;
entity downcounter is port (
clk:
in std_logic;
reset: in std_logic;
roll:
out std_logic;
count: out std_logic_vector(3 downto 0)
);
end downcounter;
architecture simple of downcounter is
--------------------------- SIGNAL & CONSTANT DECLARATIONS
-------------------------signal next_countL: unsigned(3 downto 0);
signal countL:
unsigned(3 downto 0);
begin
--------------------------- Comb Process
-------------------------comb_decrement: process (reset,countL)
begin
if (reset = '1') then -- after reset start at '5'
next_countL <= "0101";
roll
<= '0';
elsif (countL > "0000") then
next_countL <= countL - 1; -- countdown
roll
<= '0';
else
next_countL <= "1001"; -- set countL back to '9'
roll
<= '1';
end if;
end process;
--------------------------- Reg Process
-------------------------reg_increment: process (clk) begin
if(clk'event and clk = '1') then
countL <= next_countL;
end if;
end process;
--------------------------- Concurrent assignements
-------------------------count <= std_logic_vector(countL);
end simple;
Zürcher Fachhochschule
Seite 8/10
dt2ueb5_zaehler_lsg.doc
DT2P, FS-2008, dqtm, gelk
(d) roll als seq-output
------------------------------------------------- Downcounter 9 to 0 and return with sync-reset
-- Internal Signals with Unsigned
-----------------------------------------------library ieee;
use ieee.std_logic_1164.all;
use ieee.numeric_std.all;
entity downcounter is port (
clk:
in std_logic;
reset:
in std_logic;
roll:
out std_logic;
count:
out std_logic_vector(3 downto 0)
);
end downcounter;
architecture simple of downcounter is
--------------------------- SIGNAL & CONSTANT DECLARATIONS
-------------------------signal next_countL: unsigned(3 downto 0);
signal countL:
unsigned(3 downto 0);
signal next_roll:
std_logic;
begin
--------------------------- Comb Process
-------------------------comb_decrement: process (reset,countL)
begin
-- Default Statements
next_countL <= countL - 1;
next_roll <= '0';
if (reset = '1') then -- after reset start at '5'
next_countL <= "0101";
elsif (countL = "0001") then -- set roll on next cycle
next_roll <= '1';
elsif (countL = "0000") then
next_countL <= "1001"; -- set countL back to '9'
end if;
end process;
--------------------------- Reg Process
-------------------------reg_increment: process (clk) begin
if(clk'event and clk = '1') then
countL <= next_countL;
roll <= next_roll;
end if;
end process;
--------------------------- Concurrent assignements
-------------------------count <= std_logic_vector(countL);
end simple;
(e) Stammt das Signal direkt von einem Flip-Flop (Fall a), so ändert sich das Ausgangssignal nach
der steigenden Taktflanke so schnell wie möglich. Ist jedoch dem Flip-Flop noch eine
kombinatorische Logik nachgeschaltet (Fall b), so muss diese erst durchlaufen werden, bis sich das
Ausgangssignal ändert. Die maximale Taktfrequenz eines Systems hängt von der kombinatorischen
Logik zwischen zwei Flip-Flops ab. Ist im obigen Fall b, am Ausgang ein weiteres Flip-Flop
Zürcher Fachhochschule
Seite 9/10
dt2ueb5_zaehler_lsg.doc
DT2P, FS-2008, dqtm, gelk
nachgeschaltet, so verzögert die Ausgangslogik das Signal zum Eingang dieses Flip-Flops und
dadurch verringert sich die maximale Taktfrequenz.
Aufgabe 4
(a)
count_updown
icount
cntup
next_count
n
D
D
D
D
C
CC
C
clock
Q
Q
Q
Q
n
count
RRR
R
reset_n
(b) n FFs
Der Wert von n wird in der Instantitierung des Blockes bestimmt.
Zürcher Fachhochschule
Seite 10/10
dt2ueb5_zaehler_lsg.doc

Documents pareils