Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
clk
Kuruvilla Varghese
34
Kuruvilla Varghese 1
35
Flip Flop - Simulator 36
• But synthesis tools ignore d q
sensitivity list, hence the above
clk
code would mean a (transparent)
latch, as the events on ‘clk’ is not
considered. Whenever ‘clk’ is
high ‘q’ gets ‘d’ and on the
negative edge the last value of d
Kuruvilla Varghese
36
FF – Synthesis, Simulation 37
Kuruvilla Varghese 2
37
FF – Synthesis, Simulation 38
Kuruvilla Varghese
38
D Latch 39
d
process (clk, d)
clk begin
if (clk = ‘1’) then
q
q <= d;
end if;
Synthesis Tool end process;
process (clk)
begin
if (clk = ‘1’) then
q <= d;
end if;
end process;
Kuruvilla Varghese 3
39
D Latch 40
Kuruvilla Varghese
40
Wait 41
• wait on sensitivity-list;
• wait until boolean-expression;
• wait for time-expression;
• Examples
wait on clk, d;
wait until count = 10;
wait for 10 ns;
wait on clk for 17 ns;
wait until sum > 100 for 50 ns;
Kuruvilla Varghese 4
41
Asynchronous Reset 42
Kuruvilla Varghese
42
process (clk)
begin a
d q
if (clk’event and clk = ‘1’) then b
q <= a xor b; clk
end if;
end process;
• This means a single process can
code registers preceded by any
combinational circuit
Kuruvilla Varghese 5
43
Registers with comb circuit 44
process (clk)
begin
comb
if (clk’event and clk = ‘1’) then
a
d q
b
** code for combinational
circuit ** clk
end if;
end process; • Note: Any assignment you do
here will have flip-flop/register
Kuruvilla Varghese
44
Kuruvilla Varghese 6
45
FF Synchronous Reset 46
• Asynchronous Reset
d q process (clk, reset)
clk begin
if (reset = ‘1’) then
SR q <= ‘0’;
elsif (clk’event and clk = ‘1’) then
q <= d;
end if;
end process;
Kuruvilla Varghese
46
FF Synchronous Reset 47
d q process (clk)
clk begin
if (clk’event and clk = ‘1’) then
SR
if (reset = ‘1’) then
q <= ‘0’;
• if … then allows nesting and else
synchronous circuit can be coded q <= d;
end if;
• Nesting isn’t possible with
end if;
concurrent statement, hence
doesn’t make sense to code
synchronous circuit.
Kuruvilla Varghese 7
47
Sync Reset, Synthesis 48
d 0 D Q q
1
‘0’
reset
clk CK
Kuruvilla Varghese
48
d q r
process (clk) ck ck
begin clk
Kuruvilla Varghese 8
49
Shift Register 50
ck ck ck ck
clk
Kuruvilla Varghese
50
Shift Register 51
process (clk)
begin process (clk)
if (clk’event and clk = ‘1’) then begin
q(0) <= d(0); if (clk’event and clk = ‘1’) then
for i in 0 to 6 loop
q(i+1) <= q(i); q <= q(6 downto 0) & d(0);
end loop; end if;
end if; end process;
end process;
Kuruvilla Varghese 9
51
Counter 52
Kuruvilla Varghese
52
Counter 53
library ieee;
use ieee.std_logic_1164.all;
+1 d q count use ieee.std_logic_unsigned.all;
q
clk clk
AR entity count8 is port
(clk, reset, load: in std_logic;
reset
din: in std_logic_vector(7 downto 0);
count: out std_logic_vector(7 downto 0));
end count8;
Kuruvilla Varghese 10
53
Counter 54
count <= q;
process (clk, reset)
+1 0 count
begin 1
d q
din q
if (reset = ‘1’) then load
clk clk
q <= (others => '0‘); AR
elsif (clk'event and clk = ‘1’) then
reset
if (load = ‘1’) then q <= din;
else q <= q + 1;
end if; • Synthesis Tools might optimize
end if; further to get efficient target specific
end process; circuits
end arch_count8;
Kuruvilla Varghese
54
Coding Scenario 55
Topmost Level
Structural code
Components
Structural code
Concurrent statements
Kuruvilla Varghese 11
55
Test bench: Timing Simulation 56
D Q
ts: Setup time: Minimum time input
must be valid before the active clock
CLK
edge
Kuruvilla Varghese
56
• Setting up input
tclk
Input
tclk
ts
CLK tco
Output
Kuruvilla Varghese 12
57
Test bench: Timing Simulation 58
• Clock Generation
– Period, Initial offset, Duty cycle Note: Period, setup time, and tco should be
• Asynchronous Reset noted from the Static Timing Analysis for
– Remove tRR time before clock edge test bench and is with respect to
corresponding input/output pin/pad.
– Example uses ts instead of tRR
• Applying Inputs
– Apply ts time before active clock
edge
– Detect the clock edge explicitly or
implicitly (e.g. add clock period –
setup)
Kuruvilla Varghese
58
Kuruvilla Varghese 13
59
Testbench – Sequential Circuits 60
library ieee; signal clk, reset, load: std_logic := ‘0’;
use ieee.std_logic_1164.all; signal din: std_logic_vector(7 downto 0) :=
(others => ‘0’);
entity count8tb is signal count: std_logic_vector(7 downto 0);
end count8tb; constant period: time := 20 ns;
constant setup: time := 2 ns;
architecture behavioral of count8tb is begin
component count8 uut: count8 port map (clk, reset, load, din,
count);
port (clk, reset, load: in std_logic;
din: in std_logic_vector(7 downto 0) ;
count: out std_logic_vector(7 downto 0));
end component;
Kuruvilla Varghese
60
Kuruvilla Varghese
62
Kuruvilla Varghese
64
Kuruvilla Varghese
66
Kuruvilla Varghese 17
67
Arithmetic 68
signal a,b,s: unsigned(7 downto 0) ; signal a, b, s: unsigned(7 downto 0);
signal s9: unsigned(8 downto 0) ; signal s9: unsigned(8 downto 0) ;
signal s7: unsigned(6 downto 0) ; signal cin: std_logic ;
-- Carry in
-- Simple Addition, no carry out s9 <= (a & '1') + (b & cin);
s <= a + b ; s <= s9(8 downto 1) ;
-- Carry Out in result
s9 <= ('0' & a) + ('0' & b) ;
-- For smaller result, slice input
arrays
s7 <= a(6 downto 0) + b(6 downto 0)
;
Kuruvilla Varghese
68
Kuruvilla Varghese 18
69