VHDL RTL Synthesis Basics
VHDL RTL Synthesis Basics
Combinational
logic
1. Readable code
2. Ability to use same code for synthesis and simulation
This code contains a feedback. v is read by the process and then assigned
by it. v needs to retain its value for the next process run. Compiler might
generate an error, produce the previous circuit, or infer a latch.
ENTITY demux IS
PORT( a: IN unsigned (1 DOWNTO 0);
d: IN std logic;
z: OUT unsigned (3 DOWNTO 0));
END ENTITY demux;
IF s THEN
y <= a;
ELSE
y <= b;
END IF;
b s
s y
b 0 y
a a 1
ARCHITECTURE model OF ct IS
BEGIN
p2: PROCESS (a, b, c, x, y, z) IS
BEGIN
f <= ’0’;
x
IF x = ’0’ THEN
y
f <= a;
ELSIF y = ’0’ THEN
z
a 0
f <= b; f
b 0
ELSIF z = ’1’ THEN
0 0 1
f <= c;
END IF;
1
END PROCESS p2; c 1
END ARCHITECTURE model;
• A latch is needed for n since its old value is used every process run.
Copyright © 2002-2020 VHDL: RTL Synthesis Basics 26 of 59
Synthesis of IF Statements (Cont.)
Example: 18 (Class) Show how the increment-by-one circuit below is
synthesized.
LIBRARY ieee; d q
z[0]
USE ieee.std logic 1164.ALL;
USE ieee.numeric std.ALL; clk qn
ENTITY increment IS
PORT( inc: IN bit;
z: OUT unsigned (0 TO 1)); d q
z[1]
END ENTITY increment;
ARCHITECTURE behav OF increment IS clk qn
BEGIN inc
pi: PROCESS (inc) IS
VARIABLE temp: unsigned (0 TO 1) := (OTHERS => ’0’);
BEGIN
IF inc = ’1’ THEN
temp := temp + 1;
END IF;
z <= temp;
END PROCESS pi;
END ARCHITECTURE behav;
inputs outputs
En a2 a1 a0 y5 y4 y3 y2 y1 y0
0 x x x 0 0 0 0 0 0
1 0 0 0 0 0 0 0 0 1
1 0 0 1 0 0 0 0 1 0
1 0 1 0 0 0 0 1 0 0
1 0 1 1 0 0 1 0 0 0
1 1 0 0 0 1 0 0 0 0
1 1 0 1 1 0 0 0 0 0
LIBRARY ieee;
USE ieee.numeric bit.ALL;
ENTITY decoder IS
PORT( a: IN integer RANGE 0 TO 7;
en: IN bit;
y: OUT unsigned (5 DOWNTO 0));
END ENTITY decoder;
a[1]
.
.
. a[2]
y[0]
CASE a IS
y[1]
WHEN 0 => y <= o"01";
WHEN 1 => y <= o"02"; y[2]
END CASE;
END IF;
END PROCESS pd;
END ARCHITECTURE design;
USE WORK.collect.ALL;
ENTITY state update IS
PORT( current state: IN state;
z: OUT integer RANGE 0 TO 3);
END ENTITY state update;
ARCHITECTURE update OF state update IS
BEGIN
cs: PROCESS (current state) IS
BEGIN
CASE current state IS
WHEN s0 | s3 => z <= 0;
WHEN s1 => z <= 3;
WHEN OTHERS => NULL;
END CASE;
END PROCESS cs;
END ARCHITECTURE update;
current_state[0] z[0]
d q
clk qn
d q z[1]
current_state[1] clk qn
LIBRARY ieee;
USE ieee.std logic 1164.ALL;
USE ieee.numeric std.ALL;
USE WORK.types.ALL;
ENTITY ff IS x s
PORT( x, clk: IN std logic;
d q
s: OUT std logic);
END ENTITY ff;
clk qn
ARCHITECTURE ff OF ff IS
BEGIN
f: PROCESS (clk) IS
BEGIN
IF rising edge (clk) THEN
s <= NOT x;
END IF;
END PROCESS f;
END ARCHITECTURE ff;
• The WAIT statement delays the execution of the whole process until
its expression becomes true.
• This means that all other variable/signal assignment statements in the
process will infer flip-flops.
ENTITY reg IS
PORT( clk, en: IN std logic;
data: IN std logic vector (0 TO 3);
reg q: OUT std logic vector (0 To 3));
END ENTITY reg;
clk qn
data[2] q reg_a[2]
d
en qn
data[1] d q reg_a[1]
qn
data[0] d q reg_a[0]
qn
• The IF statement must contain exactly one ELSIF part with no ELSE
part.
• The first condition of the IF statement must test the level of the
asynchronous set or reset and nothing else.
• The second condition of the IF statement (the ELSIF part) must test
for the clock edge and nothing else.
• The second branch of the IF statement may contain any number and
combination of synthesizable sequential statements.
• The reset, set, and clock signals must not be used anywhere in the
process except in the sensitivity list and IF conditions as described
above.
u/inc
0 1
[c] [c]
u d
d/dec
Notes:
• When an input is not specified on an FSM, it is a don’t care.
• When an output is not specified on an FSM, it is a zero value.
Copyright © 2002-2020 VHDL: RTL Synthesis Basics 50 of 59
Synthesis of Finite-State Machines (FSM) (Cont.)
Example 30: (Cont.)
LIBRARY ieee;
USE ieee.std logic 1164.ALL;
ENTITY source IS
PORT( reset, u, d: IN bit;
clk: IN std logic;
inc, dec, c: OUT bit);
END ENTITY source;
ARCHITECTURE fsm OF source IS
SIGNAL current state, next state: integer RANGE 0 TO 1;
BEGIN
ps: PROCESS (clk, reset) IS BEGIN
IF reset = ’1’ THEN
current state <= 0;
ELSIF rising edge (clk) THEN
current state <= next state;
END IF;
END PROCESS ps;
.
.
.
inc
dec
sel
in0
u 0
out c
in1 d q
d 1
qn
clk reset
reset
• To create tristate logic we must use std logic type since it has
’Z’ as one of its possible values.
d_in[3:0]
d_in(3) d_out(3)
d_in(2) d_out(2)
d_in(1)
d_in(3)
d_out(1)
d_in(2)
d_in(1) d_out(0)
d_in(0)
en d_out[3:0]
ENTITY prebus IS
PORT( my in: IN std logic vector (7 DOWNTO 0);
sel: IN std logic;
my out: OUT std logic vector (7 DOWNTO 0));
END ENTITY prebus;
ENTITY trireg IS
PORT( trien, clock, le, din: IN std logic;
ffout, latchout: OUT std logic);
END ENTITY trireg;
ARCHITECTURE mixed OF trireg IS
BEGIN
ff: PROCESS (trien, clock) IS
BEGIN
IF trien = ’0’ THEN
ffout <= ’Z’;
ELSIF rising edge (clock) THEN
ffout <= din;
END IF;
END PROCESS ff;
.
.
.
d q
ffout
clock
qn