Vhdltut
Vhdltut
Jiri Gaisler
Automatic synthesis
Language overview
VHDL is based on Ada semantics
P2
1ns
S1
P1
S3 1
P4
1ns
S2
P3
Scheduling and execution
Each process has a list of signals called sensitivity list
Entity declaration
Entity ram is Ports are signals
generic (a : integer);
port ( Generics are local constants
addr : in integer;
Type and constant
data : inout integer; declarations allowed in entity
err : out integer; but less frequently used.
csn : boolean implicit in
);
type ....
constant ...
end;
VHDL Entity structure
Entity entity_name is entity declaration
generic_declarations;
port_declarations;
);
constant_declarations;
signal_declarations;
subprogram_declarations;
component_declarations;
begin
concurrent_statements; arch. statement part
process_statements;
component_instatiations;
generate_statements;
end;
Type declarations
Integer: +/ 231
Scalar types
Real: 1E38 to +1E38
Enumerated, physical
Standard operators defined
Records, arrays
Enum:
Composite types
type time is range 0 to 1E18 type barr is array (1 to 5) of bit;
units type v is array (integer range <>) of real;
fs; subtype farr is x ( 0 to 127);
ps = 1000 fs;
ns = 1000 ps; signal y : v(10 downto 0);
us = 1000 ns; attributes: v'length, v'range, v'left, v'right
ms = 1000 us;
s = 1000 ms; type mrec is record
end units; a : integer;
end record;
wait for 10 us;
a <= b after (10 ms + 1 ns); variable x : mrec;
x.a := 3;
Constant declarations
constant name : type := value;
signal s1 : integer;
signal s2 : bit_vector(1 to 2) := “00”;
VHDL signals
Holds a value of (almost) any data type
a <= b; event after 1 delta delay
In addition to its current value, several attributes are
function declared
Component declarations
Component declaration is allowed in architecture declaration
part and in packages
Process structure
Similar structure to a sub program (procedure)
Label : process [(sensitivity_list])]
type_declarations; process declaration part
constant_declarations;
subprogram_declarations;
variable_declarations;
begin
sequential_statements; process statement part
end;
Process statement
a <= b + c after 10 ns; p1 : process (b, c)
begin
a <= b when inc = 0 a <= b+c after 10 ns;
else b+1 when inc =1 end process;
else b+2;
p2 : process (b, inc)
begin
if inc = 0 then
a <= b;
elsif inc =1 then
a <= b+1;
else
a<= b+2;
end if;
end process;
Sensitivity list vs. Wait statement
Sensitivity list
Wait statement
p1 : process(a, b, c) p1 : process
begin begin
res <= a + b *c; res <= a + b *c;
end process; wait on a, b, c;
end process;
p2 : process(clk)
begin p2 : process
if clk = '1' then begin
res <= a + b*c; res <= a + b*c;
end if; wait on clk until clk = '1';
end process; end process;
Concurrent vs. Process statements
Concurrent statements are limited in complexity, and
suitable to express functionality in dataflow manner
Process statements allow complex statements such as
loops and multi case selections.
!
Allowed in architecture
port map (a => a, b => b, c =>
c);
u1 : adder port map (d, e, f);
end;
Generate statements
#
Allows to include or exclude
Entity adder
generic (fast : boolean);
statements in the architecture
port map (
#
Loops allowed
a, b : in bit_vector(7 dowto 0);
Resolved at elaboration time
#
sum : out bit_vector(7 downto 0);
);
%
function cadd (c1, c2 : complex)
return complex;
$
&
STANDARD
'
package standard is
type boolean is (false, true);
type bit is ('0', '1');
type character is (NUL, SOH, ..... 'A', 'B', 'C' .... DEL);
type integer is range 2**31 to 2**31; implementation defined
(
(
type real is 1E38 to +1E38; implementation defined
(
(
type time is .....
type std_ulogic is (
'U', Uninitialized
*
'X', Forcing Unknown
*
*
'0', Forcing 0
*
'1', Forcing 1
*
'L', Weak 0
+
'H', Weak 1
+
);
type std_ulogic_vector is array (natural range <>) of std_ulogic;
and, nand, or, nor, xor, xnor, not (on scalars and vectors)
,
is_x
std_logic_arith
,
conv_signed, conv_std_logic_vector
Examples
.
flip flop
.
Clock generator
/
signal clk : std_logic := '0'; dff1 : process (clk)
begin
clk <= not clk after 5 ns; if clk'event and (clk = '1') then
q <= d;
end if;
.
Transparent latch
end process;
latch : process (clk, d)
begin dff2 : process (clk)
if clk = '1' then begin
q <= d; if rising_edge(clk) then
end if; q <= d;
end process; end if;
end process;
Library ieee; SIMPLE ASYNC RAM
0
use ieee.std_logic_1164.all;
use ieee.std_logic_arith.all;
entity async_ram is
generic ( abits : integer := 10; dbits : integer := 8 );
port (
address : in std_logic_vector((abits 1) downto 0);
0
data : inout std_logic_vector((dbits 1) downto 0);
0
csn, wen, oen : in std_logic);
end;
1
begin
r : process(address, data, csn, wen, oen)
variable memarr : mem;
variable dout : std_logic_vector((dbits 1) downto 0);
1
begin
if csn = '0' then
dout := memarr(conv_integer(unsigned(address)));
if wen'event and (wen = '1') then
memarr(conv_integer(unsigned(address))) := data;
end if;
if oen = '0' then data <= dout; else data <= (others => 'Z'); end if;
end if;
end process;
end;
Library ieee; 32 bit RAM BANK
2
use ieee.std_logic_1164.all;
use ieee.std_logic_arith.all;
entity mem_bank is
port (
address : in std_logic_vector(23 downto 2);
data : inout std_logic_vector(31 downto 0);
csn, wen, oen : in std_logic);
end;
component async_ram
generic ( abits : integer := 10; dbits : integer := 8 );
port (
address : in std_logic_vector((abits 1) downto 0);
3
begin
mb: for i in 0 to 3 generate
u0 : async_ram generic map (22, 8);
port map (address, data(i*8+7 downto i*8), csn, wen, oen);
end generate
end;
4
Common problems
4
Clock skew Oscillation
clkn <= not clk; clk <= not clk;
clk2 <= clk;
4
4
Signals are assigned with delay Inifinite loop (missing wait)
a <= b; process
c <= a; begin
statements;
c is NOT equal to b !! ..
end process;
Elaboration and start up
5
4
Time is set to 0
6
Execution (simulation)
Configurations
8
Synthesis subset
8
Sites
www.eda.org, www.vhdl.org, rassp.scra.org
8
9
VHDL course modules (3) at rassp.scra.org
8
References
VHDL Language Reference Manual, IEEE standard 1076
VHDL Cook book, Peter Ashenden, Uni. Adelaide
9