Lecture 5 - Combinatorial and Sequential Logic
Lecture 5 - Combinatorial and Sequential Logic
Combinatorial Logic,
Statements, Generics
TIE-50206 Logic Synthesis
Arto Perttula
Tampere University of Technology
Fall 2017
Seq.
n
logic foo_r
a_in
b_in
Comb. D Q n
n logic
c_in
1
Acknowledgements
• Prof. Pong P. Chu provided ”official” slides for
the book which is gratefully acknowledged
– See also: http://academic.csuohio.edu/chu_p/
• Most slides were originally made by Ari Kulmala
– and other previous lecturers (Teemu Pitkänen, Konsta
Punkka, Mikko Alho, Erno Salminen…)
if … then if … then
if full=’1’ then… if full = ’1’ then…
else … else …
else else
if full=’0’ then… if full = ’1’ then…
else … -- Consistency
else …
Statements: CASE
procedures and
functions only
• Alternative to if-clause
• All possible choices must be considered or the last choice must contain others clause
CASE expression IS
WHEN choice1 =>
statements
WHEN choice2 =>
statements
WHEN others =>
statements
END CASE;
• Example problem with DesignCompiler synthesis tool (from Synopsys):
– ”Error: All possible string values of selector type not covered by choices.”
signal sel : std_logic;
...
CASE sel IS
WHEN ‘0’ => result <= a;
WHEN ‘1’ => result <= b;
END CASE;
• Example:
CASE state IS
WHEN “000” =>
output <= 0;
WHEN “001”=>
output <= 1;
WHEN “010”=>
output <= 2;
WHEN “011”=>
output <= 3;
WHEN OTHERS =>
output <= 4;
END CASE;
• Use when others => with case
– Otherwise, some tools want you to specify also what happens with other std_logic values,
e.g., ”X11”, ”1Z1”, ”WHH”, ”UUU”
Statements: WAIT
procedures and
functions only
LOOP
clock <= not clock;
wait for ClockPeriod/2;
Also in concurrent part IF error = ‘1’ THEN
EXIT; example of clock generation in simulation test benches
END IF;
END LOOP;
RETURN;
n n
Comb. Comb.
logic logic
clk
7.11.2017 31
Trivial Example: DFF
• Example: model a single rising-edge triggered D flip-flop
If reset is active
Reminder: No code
before if
or after end if
If reset was not active
AND we have a rising
Arto Perttula edge in signal ‘clk’ 32
Example 2: Multiply-Accumulate
Step 1: Define the Entity
• Entity is the same for all architecture variants
– However, clk and rst_n are ignored in combinatorial
Data width is parameterized, we’ll
entity mac is return to this…
generic (
data_width_g : integer := 4);
Default range is 4-1 downto 0 = 4 bits
port (
clk : in std_logic;
rst_n : in std_logic;
a_in : in std_logic_vector(data_width_g-1 downto 0);
b_in : in std_logic_vector(data_width_g-1 downto 0);
c_in : in std_logic_vector(data_width_g-1 downto 0);
mac_out : out std_logic_vector(data_width_g*2-1 downto 0)
);
end mac;
Double width due to multiplication Default: 4*2-1 = 7, 7 downto 0 = 8 bits
(in numeric_std, two 4-bit number addition
results in 4-bit result, not 5-bit.) 7.11.2017 33
MAC: 3 Possible Architectures
1) Combinatorial circuit:
A_in
B_in * Mac_out
C_in +
2) Synchronous circuit:
A_in
B_in * Mac_out
C_in + D Q
D Q
+ D Q
C_in
result_v := unsigned(a_in)*unsigned(b_in)+unsigned(c_in);
mac_out <= std_logic_vector(result_v);
D Q
+ D Q
C_in
begin -- rtl
begin -- rtl
C_in
D Q
+ mac_pipe : process (clk, rst_n)
begin -- process mac_comb
if rst_n = '0' then
-- Note that intermediate pipeline registers do
-- not have to be nullified under reset
c_r <= (others => '0');
Mac_out moved out of the mul_r <= (others => '0');
clock region causes that no
register generated for it but just elsif clk'event and clk = '1’
a wire coming from an adder. c_r <= unsigned(c_in);
It must NOT be reset. mul_r <= unsigned(a_in)*unsigned(b_in);
end if;
end process mac_pipe;
Quiz: why would this made more sense than v3?
A: Smaller area. Delay of ADD doesn’t probably increase the critical path mac_out <= std_logic_vector(mul_r + c_r);
end rtl; 38
System Reset
• Brings the system into known state
– At-start-up
– After crash
• Known state = deterministic values for flip-flops in the system
– Concerns sequential logic (sequential processes)
• Memory (SRAM, DRAM) contents usually remain in reset
– But you cannot count on that!
– Contents are lost when power is shutdown
– Will be initialized/reset explicitly location by location (often with SW)
• Flip-flop’s value may be set
1. Asynchronously via special input pin – Asynchronous reset
2. Synchronously via D input – Synchronous reset
3. Synchronously via D input – Normal operation
Q changes
after clk
Undefined signal value on reset. edge again
-- component instantiation
DUT: mac
Component declaration
Architecture body
generic ( data_width_c)
data_width_g : integer :=4); port map (
port ( clk => clk,
clk : in std_logic; rst_n => rst_n,
rst_n : in std_logic; a_in => a_to_mac,
a_in : in std_logic_vector(data_width_g-1 downto 0); b_in => b_to_mac,
b_in : in std_logic_vector(data_width_g-1 downto 0); c_in => c_to_mac,
c_in : in std_logic_vector(data_width_g-1 downto 0); mac_out => mac_result);
mac_out : out std_logic_vector(data_width_g*2-1 downto 0));
end component; ...
Data_width_
i_rx_chan : n2h2_rx_chan Mem_addr_r(0)
_cmp_hi_
hibi_addr
generic map ( Channel 0 …
…
Id = 0
data_width_g => data_width_g, Irq_chan_r(0)
id_g => i,
g
...
Data_width_
addr_cmp_hi_g => hibi_addr_cmp_hi_g) … Mem_addr_r(1)
_cmp_hi_
…
hibi_addr
port map ( Channel 1
clk => clk, Irq_chan_r(1)
Id = 1
rst_n => rst_n,
g
avalon_addr_in => mem_addr_r(i),
...
…
irq_out => irq_chan_r(i)
);
Data_width_
Mem_addr_r
_cmp_hi_
n_chans_g-1
hibi_addr
end generate channels; …
Channel (n_chans_g-1)
…
Hardware parameterized with generics, same ”base” for all
n_chans_g-1 Irq_chan_r
Id =
In example, each channel has
g
(n_chans_g-1)
Different identifier id_g
Same signal widths data_width_g and addr_cmp_hi_g
I/Os can be mapped to different signals
Outputs must be mapped to different signals!
In example, each channel has
Different mem_addr_r and irq_chan_r (std_logic_vector position in 2D-array)
Same clk and rst_n
Arto Perttula 7.11.2017 55
For-generate
• Note that the generic parameters can be result of a function, from a table etc.
– Very powerful
-- purpose: To determine proper relative frequencies
– Statically computed values, no dynamic parameters -- depending on the syncmode
Conflict between
Conflict between Conflict between Values ’Z’, ’H’ or values given in
’0’ driven by DUV ’1’ driven by DUV ’L’ driven by TB process and in
and ’1’ driven by and ’0’ driven by do not cause concurrent
TB TB. conflicts. assignment 62
Timing Example: Signal vs. Variable
architecture rtl of ac is
signal x_r : integer; Process is triggered at clock edge.
signal y_r : integer; Variable is updated instantly at the clock edge.
signal z : integer; Signal is updated just after the clock edge Simulator view:
begin -- rtl
end rtl;
D Q x_r + D Q
7.11.2017 64
Signal vs. Variable Value Update (3)
architecture rtl of ac is architecture rtl of ac is
signal x_r : integer; signal x_r : integer;
signal y_r : integer; signal y_r : integer;
signal z : integer; signal z : integer;
begin -- rtl begin -- rtl
end if;
end process value; Note: simulator’s view does not fully match real
world, although the register x_r and outputs y_r
z <= y_r;
and z are the same!
end rtl; 7.11.2017 66
VHDL Pitfalls
1. Identifiers
– VHDL isn’t case sensitive (e.g., Input and input are the same)
– (But some tool’s are…)
2. Misspelled If statement
– ELSIF written as ELSE IF
3. Wrong string delimiters
– ’0001’ instead of ”0001”, or ”0” instead of ’0’
– 0 instead of ’0’ or vice versa
4. Misused reserverd words
– Reserved words used as object names: IN , OUT, BUFFER, AND, NAND, OR
5. Incomplete case statement
– VHDL requires all conditions to be presented
– Conditions must be locally static (determined at compile-time)
!
!