VHDL
VHDL
陳獻文
國家晶片系統設計中心
03-5773693 ext.159
[email protected]
VHDL Syntax
Sequential Statements
Concurrent Statements
Modeling logic circuits
Combinational Logic
Sequential Logic
Finite State Machine
Testbench
Gate-Level Simulation
S.W.CHEN VHDL 2004.2 1-1
VHDL
Very High Speed Integrated Circuit Hardware
Description Language
1980
The USA Department of Defense (DOD)
project under the Very High Speed Integrated
Circuit (VHSIC)
1993
IEEE 1076 '93.
1996
Both commercial simulation and synthesis
tools became available adhering to IEEE 1076
'93 standard.
A VHDL package for use with synthesis tools,
IEEE 1076.3 (NUMERIC_STD)
IEEE 1076.4 (VITAL)
system
VHDL
algorithm
verilog
RTL
Logic
vital
Gate
VHDL RTL
ModelSim
Artisan VHDL Level
Gate Level model
Design
Compiler
SE
Schematic
-- pragma translate_off
Z <= string(“don’t translate”);
-- pragma translate_on
Z <= A and B;
Entity
I/O port spec. of the block Entity
Architecture
function of the block
can have more than one
Arch1 Arch2
Configuration (version 1) (version 2)
choose a architecture to run simulation.
Package
Package body
S.W.CHEN VHDL 2004.2 3-8
Entity NAND2 is
port ( A : in std_logic;
B : in std_logic;
Z : out std_logic);
end nand2;
A
Z
NAND2
B
IN
Connect with OUT or INOUT.
OUT
Connect with IN or INOUT.
INOUT
Connect with IN or OUT.
BUFFER
Connect with BUFFER only.
INOUT
Bit
BIT_VECTOR (0 TO 7)
STD_LOGIC
STD_LOGIC_VECTOR (15 DOWNTO 0)
A
And I Inverter Z
(and2x1) (invx1)
B U1
U0
NAND2
end DATAFLOW;
A
RTL
Z
B
ARCHITECTURE b Of a IS
BEGIN
END b;
CONFIGURATION c OF a IS
FOR b
END FOR;
END c;
Package Declarations
Package Bodies
Constant Declarations
Subprograms
Type Declarations
Component Declarations
PACKAGE a IS
...
END [a];
PACKAGE BODY a IS
...
END [a];
Working Library
writable library (WORK)
Resource Library
Vendor supply (Synopsys)
Standard library (IEEE)
Cell library VHDL model (Artisan,Compass)
- - Library WORK;
use WORK.EXAMPLE.ALL;
entity...
architecture...
ModelSim
Map work library to other real folder.
Altera MaxPlusII and Xilinx
The work library is the folder that put main
vhdl program.
library IEEE;
use ieee.std_logic_1164.all;
….
signal a: std_logic;
signal a: std_logic_vector(0 to 3);
library IEEE;
use ieee.std_logic_arith.all;
….
signal a: signed(7 downto 0);
signal a: unsigned(7 downto 0);
S.W.CHEN VHDL 2004.2 3-25
modelsim.ini
[Library]
others=$Model_TECH/../modelsim.ini
work=work
artisan_lib25=/cad2/lab/VHDL/modelsim/lib25
Compiler Map
(vcom) Library
(vmap)
ModelSim
Simulation
(vsim)
vsim&
Commad space
Workspace
Create Library
vlib work
Library mapping
vmap work work
VHDL Compilation
vcom nand2.vhd
Simulation
vsim test
add wave a b z
Behavioral /
gate-level
VHDL design Simulator
Simulator
Commands stimuli Unit
(force,run, Under
output Test
set trace)
(UUT)
Behavioral /
Behavioral gate-level
VHDL program VHDL design Simulator
Simulator
Commands stimuli Unit
(run) Under
Testbench output Test
(UUT)
Signal
Describe a real wire in the circuit.
Variable
Holds any single value from the values of the
specified type.
Often used to hold temporary values within a
process or subprogram.
Constant
Holds one specific value of the specified type.
Boolean Time
Natural Positive
Enumeration
Physical-predefined
Time
<base>#<value>#e<value>
( 2 )10
10
Numeric Type-Predefined
integer
real
for Numeric
TYPE Integer IS RANGE -2147483647 TO +2147483647;
SUBTYPE Natural IS Integer RANGE 0 TO Integer'HIGH ;
Subtype-predefined
Natural
Positive
Record Type
Use work.example.all;
end arch;
Model 1
type dim1 is array (7 downto 0) of bit_vector(7 downto 0);
signal a : dim1;
Assignment:
a(0)(7 downto 0) <= “00000000”;
Model 2
type dim2 is array ( 7 downto 0,7 downto 0) of bit;
signal b : dim2;
Assignment:
b(0,7 downto 0) <= “00000000”; -- Error
b(0,0) <= ‘0’;
b(0,1) <= ‘0’;
S.W.CHEN VHDL 2004.2 3-58
Only simulation
Package example Is
Type data_rec; -- Incomplete type
Type data_ptr is Access data_rec;
TYPE data_rec IS
RECORD
data : std_logic_vector(7 downto 0);
nxt : data_ptr;
END RECORD;
end;
PROCESS (CLK)
VARIABLE head: data_ptr := NULL;
VARIABLE temp: data_ptr := NULL;
BEGIN
IF CLK'EVENT AND CLK = '1' THEN
IF (RW_DIR = '0') THEN --Write Mode
temp := NEW data_rec;
temp.data := D_IN;
temp.nxt := head;
head := temp;
ELSIF (RW_DIR = '1') THEN
D_OUT <= head.data;
temp := head;
head := temp.nxt;
DEALLOCATE(temp); -- delete temp
END IF;
END IF;
END PROCESS;
S.W.CHEN VHDL 2004.2 3-60
USE std.textio.all;
USE ieee.std_logic_textio.all;
FILE input_file : TEXT IS IN "/dsk/vhdl/in.data“;
FILE output_file : TEXT IS OUT "/dsk/vhdl/out.data“;
VARIABLE l1,l2 : LINE;
VARIABLE test : std_logic_vector(7 downto 0);
WHILE NOT ( ENDFILE(input_file) )
LOOP
TEXT (File) READLINE(input_file, l1);
READ(l1, test);
LINE WRITE(l2, test);
WRITELINE(output_file, l2);
BIT data END LOOP;
T’HIGH
week’high=SAT, count’high=63, byte’high=7
T’LOW
week’low=SUN, count’low=0, byte’low=0
A’RANGE
nibble’range= 3 downto 0
A’REVERSE_RANGE
address’reverse_range = 5 to 17
S’EVENT
S’STABLE
S’ACTIVE
can’t be synthesized
S’TRANSACTION
can’t be synthesized
-- positive-edge-trigger
B
S <= A and B;
S
Declare an “Attribute”.
Specify this attribute to the identifiers.
Literal Operands
Identifier
Aggregate
Function call operands
Qualified Expression Operands
Type Conversion Operands
Record & Record Element Operands
Enumeration Literals
TRUE
FALSE
‘a’
‘1’
‘0’
Architecture arch of en is
Signal k: bit_vector(15 downto 0);
Signal g: std_logic_vector(15 downto 0);
begin
k<=X“9FDE”;
g<=X“9FDE”; -- error
g<=to_stdlogicvector(X”9FDE”);
end arch;
Arry<=(a,b,c,d);
(=>,=>,=>) <= AR ;
or
AR <= (=>,=>,=>);
wrong method:
signal a: std_logic;
signal b: std_logic_vector(3 downto 0);
signal c: std_logic_vector(4 downto 0);
….
C<=(a,b); --Error
FUNC(5); -- ambiguous
FUNC(R_1'(5)); -- unambiguous
type_name(expression)
integer types
similar array types
same length
convertible or identical element types
Enumerated types are not convertible
BIT_ARRAY_10(S_BIT_VEC); -- OK
wrong conversion:
concatenation &
signal a, b: bit;
signal c: bit_vector (7 downto 0);
Case bit_vector’(a, b) is
when “00” => Q<=C;
when “01” => Q<=A;
when others => Q<=‘0’;
end case;
Subtype TTT is bit_vector(1 to 2);
...
Case TTT’(a&b) is
when “00” => Q<=C;
when “01” => Q<=A;
when others => Q<=‘0’;
end case;
J K J REM K J MOD K
4 5 4 4
-4 5 -4 1
4 -5 4 -1
-4 -5 -4 -4
S.W.CHEN VHDL 2004.2 3-106
for synopsys synthesis
Supports the “abs” and “**” operators for all
integer types.
When you're using “**”, the left operand must
be the computable value 2.
signal A, B: INTEGER range -8 to 7;
signal C: INTEGER range 0 to 15;
signal D: INTEGER range 0 to 3;
...
A <= abs(B);
C <= 2 ** D;
std_logic_1164
Library IEEE;
USE IEEE.std_logic_1164.ALL;
Library ieee;
Use ieee.std_logic_arith.all;
Library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_arith.all;
--use ieee.std_logic_unsigned.all;
IEEE.std_logic.1164_ALL; Declaration
IEEE.numeric_std.ALL;
Declaration
IEEE.std_logic_arith.ALL; Function and
Function
IEEE.std_logic_unsigned.ALL;
IEEE.std_logic_signed.ALL;
IEEE.math_real.ALL;
IEEE.math_complex.ALL;
LIBRARY IEEE;
USE IEEE.STD_LOGIC_ARITH.ALL;
variable count: unsigned (1 downto 0);
variable u,s,: unsigned(7 downto 0);
variable z: unsigned(7 downto 0);
u:= “01101011”;
s:= “11101011”; 1 1
... “11”
count := conv_unsigned(arg=>3, size=>2);
z := shl(u,count); -- “01011000”
z := shl(s,count); -- “01011000”
z := shr(u,count); -- “00001101”
z := shr(s,count); -- “00011101”
z := sll(a,count); -- “10000”
z := slr(a,count); -- “00111”
z := rol(a,count); -- “10011”
z := ror(a,count); -- “00111”
y1 := sla(a,count); -- Error
y1 := a sla count; -- “10111”
y2 := a sra count; -- “11101”
a
c
My_and
A b
And I Inverter Z
(my_and) (my_inv)
B U1
U0
NAND2
a z
My_inv
entity my_inv is
port(a:in std_logic;
z: out std_logic);
end my_inv;
a z architecture arch of my_and is
My_inv begin
z<= not a;
end arch;
configuration cfg_inv of my_inv is
for arch
end for;
end cfg_inv;
Configuration conf of yy is
for xx
for u1: ND2 use entity work.my_nand(arch);
end for;
for others: nd2 use entity work.my_nand(arch);
end for;
end for;
end conf;
ARCHITECTURE xx OF yy IS
component ND2
port(A,B: in std_logic;
C: out std_logic);
end component;
for ALL: ND2 use entity work.my_nand(arch);
begin
...
end xx;
Entity
ENTITY MY_AND2 IS
in architecture
component declaration
component instantiations
in configuration
parents
children
Component Declaration
COMPONENT my_and
GENERIC(tp:time:=3 ns);
PORT (q: OUT std_logic;
a,b:IN std_logic);
END COMPONENT;
timing propagation
Component Instantiation
and2 architecture
and2
architecture
and2 architecture
Configuration of and2
CONFIGURATION 74F08_cfg OF my_and IS
FOR arch
GENERIC MAP(tp=> 2.5 ns);
END FOR;
END c_74F08_cfg;
Q <= shl(D,count);
Architecture arch of en is
{Declaration Statement}
begin
{Concurrent Statement}
{Sequential Statement}
end arch;
Sequential Statement
can use “variable”. c<=a and b;
z<=a and c;
three types: b
process a
c
function z
procedure
Concurrent Statement
Each statement can be taken as a small
circuit.
Each statement will operate simultaneously.
Assignment
architecture arch of en is
signal a: std_logic:=‘0’;
begin
process
variable b: std_logic:=‘1’;
begin
a <= ‘1’; -- signal
b := ‘0’ -- variable;
end;
end arch;
entity en is
port (a : in bit_vector(2 downto 0);
b : in bit;
z : out bit_vector(3 downto 0));
end en;
architecture arch of en is
begin
process( a,b )
begin
z(1 downto 0)<= (b , a(0) );
z(3 downto 2)<=a(2 downto 1);
end process;
end arch;
process(clk,a,b,c)
begin
if(clk’event and clk = ‘1’) then
c <= a and b;
d <= c;
end if;
end process;
process (clk,a,b)
variable c : std_logic;
begin
if(clk’event and clk = ‘1’) then
c := a and b;
d <= c;
end if;
end process;
C(t) := A and B
D <= C(t)
Variable updated
many
events
Signal updated
Note: A process
is not a clock.
process( a,b,c,p1,p2 )
begin
if (P1=‘1’) then
Z<=A;
elsif (P2=‘0’) then
Z<=B;
else
Z<=C;
end if;
end process;
cond
process(a,b,c,d,value)
begin
case VALUE is
when PICK_A => Z <= A ;
when PICK_B => Z <= B;
when PICK_C => Z <= C;
when PICK_D => Z <= D;
end case;
end process;
use work.test.all;
PICK_A=00
entity en is PICK_B=01
port (value: in ENUM;
PICK_C=10
a,b,c,d: in bit;
z: out bit); PICK_D=11
end en;
loop
can’t be synthesized
Note:Loop and clock
while…loop have no relational.
can’t be synthesized A loop is not a clock.
for...loop
used for synthesis
don’t use wait statement
fixed range
PROCESS
VARIABLE a:integer :=1;
BEGIN
[loop1:] WHILE (a<=10)
LOOP
WAIT FOR 25 ns;
clk1<= NOT clk1;
a:=a+1;
END LOOP [loop1];
END PROCESS;
process
VARIABLE a:integer :=1; -- permanent existence
begin
loop1: While(a<=10)
LOOP
WAIT FOR 25 ns;
clk<= NOT clk ;
a:=a+1;
END LOOP loop1;
loop2: FOR a IN 1 TO 10
LOOP
WAIT for 26 ns ;
clk1 <= NOT clk1;
END LOOP loop2;
end process;
process(B,copy_enable)
begin
A<="00000000";
for I in 1 to 8 loop
next when COPY_ENABLE(I)='0';
A(I)<=B(I);
end loop;
end process;
If(copy_enable(I)=‘0’) then
next;
else
a(I)<=b(I);
end if;
only signal
process process
begin begin
if pwring then wait on dtack until dtack='1'
wait for 150 ns; for 150 ms;
reset<='1'; -- halt until dtack is ‘1’,
pwring <= false; -- only wait for 150ms.
end if; if dtack='0' then
end process; buserr<='1';
end if;
end process;
process(a,clk)
begin
if (clk='1' and clk'event) then
Z<=A;
end if;
end process;
process
begin
wait until (clk='1' and clk'event);
Z<=A;
end process;
Process
variable VAR: bit;
begin
wait until clk’event and clk=‘1’;
VAR := not Var; -- register
S <= Var;
end process;
Process(CLK,S2)
variable Var: bit;
begin
if CLK’event and CLK=‘1’ then
Var:=not Var;
S<=Var;
end if;
Var := S3; -- X
S <= S3; -- X
S2 <= Var; -- X
S4 <= S; -- O
end process;
ASSERT condition
REPORT string
SEVERITY serverity_level
serverity_level
note
warning
error
failure
Procedure
procedure pro_name (A: in Bit; Z: out Bit );
Function
function fun_name ( A,B: in Bit ) return Integer;
return
return; -- procedure
return expression; -- Functions
Only Simulation
wired_and
wired_or
package RES_PACK is
function RES_FUNC(DATA: in BIT_VECTOR) return BIT;
subtype RESOLVED_BIT is RES_FUNC BIT;
end;
use work.RES_PACK.all;
entity WAND_VHDL is
port(X,Y : in BIT;
Z : out RESOLVED_BIT);
end WAND_VHDL;
Signal Conditional
Assignment Signal
Process Assignment
Block & Guarded Selected Signal
Block Assignment
Concurrent Generate
Assert Statement
Concurrent
Procedure Call
BEGIN
q <= a NOR b;
END BEHAVIOR;
ALU
MEMORY
SIGNAL KIND
REGISTER
signal to retain its last value.
BUS
signal to take on the default value sepcified by the
bus resoluation function.
ENTITY new_latch IS
PORT(c,d:IN std_logic;
a: OUT std_logic BUS;
b: OUT std_logic);
-- no register here, but port will hold the original value.
DISCONNECT a: std_logic AFTER 10 ns;
END new_latch;
B1: BLOCK(c='1‘)
BEGIN
b<= guarded not d after 100 ns;
a<= guarded not d after 200 ns;
END BLOCK B1;
0 NS
Assertion NOTE at 0 NS in design unit CPROC(CPROC_A) from process /CPROC/_P0:
"S is False -- Procedure P”
Assertion NOTE at 0 NS in design unit CPROC(CPROC_A) from process /CPROC/_P1:
"S is False -- Procedure P2"10.00 NSAssertion NOTE at
10.00 NS
in design unit CPROC(CPROC_A) from process /CPROC/_P1:
"S is False -- Procedure P2"30.00 NSAssertion NOTE at
30.00 NS
in design unit CPROC(CPROC_A) from process /CPROC/_P1:
"S is False -- Procedure P2"
process(A_OUT)
begin
SIG<=A_OUT;
end process;
process(B_OUT)
begin
SIG<=B_OUT;
end process;
signal A, B, C, D, Z: BIT;
signal CONTROL: bit_vector(1 downto 0 );
... process(CONTROL, A, B, C, D)
begin
with CONTROL select case CONTROL is
Z <= A when “00“, when 0=>
B when “01“, Z<=A;
C when “10“, when 1=>
Z<=B;
D when “11“; when 2=>
Z<=C;
when 3=>
Z<=D;
end case;
end process;
component dff
port(sig_in,clock:in std_logic;
q: out std_logic);
end component;
signal a: std_logic_vector(0 to 4);
...
a(0)<=inp;
g1: FOR i IN 0 TO 3 GENERATE
u0 : dff port map(a(i),clock,a(i+1));
END GENERATE; -- concurrent
outp<=a(4);
CONVERTER
entity CONVERTER is
generic(N: INTEGER:=8);
port(CLK,DATA: in BIT;
Convert: buffer BIT_VECTOR(N-1 downto 0));
end CONVERTER;
...
signal S : bit_vector(N-2 downto 0);
...
S data
CONVERT
x = A • B • C '+ A • D'+ B • C • D;
y = A + B'+C • D;
…
signal A,B,C,D : std_logic;
signal X,Y : std_logic;
ARCHITECTURE a OF BL_EQ IS
BEGIN
X <= (A and B and not(C)) or (A and not(D))
or (B and C and D);
Y <= A or not(B) or (C and D);
END a;
p1:process(a1)
variable v: unsigned(1 downto 0);
begin
v:=((a1(0) nor a1(1)), (a1(2) nor a1(3)));
s1<=v(0) nand v(1);
end process p1;
p2:process (a1)
variable v: unsigned(1 downto 0);
begin
v:=(a1(4) nor a1(5))&(a1(6) nor a1(7));
s2<=v(0) nand v(1);
end process p2;
y1<=s1 nor s2;
process(a2,b2,c2,d2,e2)
begin
y2<=a2+(b2-c2)+(d2*e2);
end process;
process
if
case
concurrent
conditional assign
with...select
process(a)
begin
if (a="00000001“) then y<="000";
elsif (a="00000010") then y<="001";
elsif (a="00000100") then y<="010";
elsif (a="00001000") then y<="011";
elsif (a="00010000") then y<="100";
elsif (a="00100000") then y<="101";
elsif (a="01000000") then y<="110";
elsif (a="10000000") then y<="111";
else y<="XXX";
end if;
end process;
process(a)
variable n: integer range 0 to 7 ;
variable test: unsigned (7 downto 0);
begin
test:="00000001";
y<="XXX";
for n in 0 to 7 loop
if(A=test) then
y<=conv_unsigned(n,3);
exit;
end if;
test:=shl(test,"1");
end loop;
end process;
architecture a of latch is
begin
process(ena,d)
begin
if ena = '0' then
q <= d;
end if;
end process;
end a;
architecture a of d_ff is
begin
process(clk,d)
begin
if clk‘event and clk = '1' then
q <= d;
end if;
end process;
end a;
architecture a of dff_sr is
begin
process(reset,clk,d)
begin
if clk'event and clk = '1' then
if reset = '0' then
q <= '0';
else
q <= d;
end if;
end if;
end process;
end a;
architecture a of dff_ar is
begin
process(reset,clk,d)
begin
if reset = '0' then
q <= '0';
elsif clk'event and clk = '1' then
q <= d;
end if;
end process;
end a;
process(clock,reset,up,down)
variable updown : unsigned(1 downto 0);
begin
updown:=up&down;
if (reset='1‘) then
count<="00000";
elsif clock'event and clock='1' then
case updown is
when "00"=> count<=count;
when "10"=> count<=count+1;
when "01"=> count<=count-2;
when others=> count<=count;
end case;
end if;
end process;
Current state
Next state
NS
Output logic
CLK
S1 CS
S2 OL
S3
seq: process(clock,reset)
begin
if (reset='1') then
currentstate<=st0;
elsif clock'event and clock='1' then
currentstate<=nextstate;
end if;
end process seq;
seq: process(clock,reset,currentstate)
begin
if(reset='1') then
currentstate<=st0;
elsif clock'event and clock='1' then
currentstate<=nextstate;
end if;
case currentstate is
when st0=>y<=0;
when st1=>y<=1;
when st2=>y<=2;
when st3=>y<=3;
end case;
end process seq;
ENTITY testbench IS
END testbench;
component f_adder
port (a,b,c: in std_logic;
sum,carry: out std_logic);
end component;
signal a_i,b_i,c_i: std_logic;
signal sum_o,carry_o: std_logic;
...
...
...
...
...
B <= '0',
'1' after (runtime*1),
'0' after (runtime*2),
'1' after (runtime*3);
report “string”;
report T’IMAGE(X);
report “string” & T’IMAGE(X);
process
Variable error_num : integer;
begin
error_num := 10;
report “Error number is :”;
report integer’IMAGE(error_num);
report “Error number is :” & integer’IMAGE(error_num);
wait for 10 ns;
end process;
S.W.CHEN VHDL 2004.2 6-22
process
Variable hex_value : std_logic_vector(15 downto 0);
begin
hex_value := X”abcd”;
report “Hex Value is : ” & to_hex(hex_value) & “;”;
wait for 10 ns;
end process;
report message:
Hex Value is : abcd;
cadence
http://www.cic.edu.tw/chip_design/desi
gn_petition.html
CIC 0.25um Cell-Based Design kit V1.0
Release
CIC 0.35um Cell-Based Design Kit
(TSMC/TSMC) Release
Invoke ModelSim
vsim&
Create a library – artisan_lib25
vlib artisan_lib25
vmap artisan_lib25 artisan_lib25
Invoke ModelSim
vsim&
Create a library – vital
vlib vital
vmap vital vital
Compile Vtable.vhd to vital library
Select Compile -> Compile...
Select “vital” in the Library form
Compile Vtable.vhd
cadence
Modify .synopsys_dc.setup of
Synopsys
Apply for Cell-base Design Kit
Prepare VHDL Cell Library
Compile VHDL Cell Library
Start on VHDL gate-level simulation
http://www.cic.edu.tw/chip_design/desi
gn_petition.html
CIC 0.25um Cell-Based Design kit V1.0
Release
CIC 0.35um Cell-Based Design Kit
(TSMC/TSMC) Release
Invoke ModelSim
vsim&
Create a library – artisan_lib25
vlib artisan_lib25
vmap artisan_lib25 artisan_lib25
Invoke ModelSim
vsim&
Create a library – vital
vlib vital
vmap vital vital
Compile Vtable.vhd to vital library
Select Compile -> Compile...
Select “vital” in the Library form
Compile Vtable.vhd
VHDL 版本
1.Synopsys 合成前:
z 編輯 .synopsys_dc.setup ,如果是.25 製程,則修改或加入一行如下:
vhdlout_use_packages={"IEEE.std_logic_1164", "artisan_lib25.prim"}
z 如果是.35 製程,則修改或加入一行如下:
vhdlout_use_packages={"IEEE.std_logic_1164","tsmc_lib35.vcomponents"}
z 合成出的 vhdl gate-level 電路,可看到以下描述:
use artisan_lib25.prim.all; 或 use tsmc_lib35.vcomponents.all;
2.申請 CIC Cell-Base Design Kit。
z http://www.cic.edu.tw/chip_design/design_petition.html
3.得到所需 VHDL 版本的 Cell Library:
z .25 製程
路徑:CIC_CBDK25_V1/CIC/VHDL/CORE/tsmc25.vhd
z .35 製程
路徑:CBDK035_TSMC_TSMC/CIC/VHDL/*.vhd
4.Compile .25 製程 VHDL Library:
z Invoke modelsim
% vsim&
z Create a library – artisan_lib25
Modelsim> vlib artisan_lib25
Modelsim> vmap artisan_lib25 artisan_lib25
z Compile tsmc25.vhd to artisan_lib25 library
選擇 Compile -> Compile...開啟 Compile HDL Source Files window.
在 Library form 中選擇 artisan_lib25.
開始 compile tsmc25.vhd.
5.Compile .35 製程 VHDL Library:
z Invoke modelsim
% vsim&
z Create a library – vital
Modelsim> vlib vital
Modelsim> vmap vital vital
z Compile Vtable.vhd to vital library
選擇 Compile -> Compile...開啟 Compile HDL Source Files window.
在 Library form 中選擇 vital
開始 compile Vtable.vhd.,
z Create a library – tsmc_lib35
Modelsim> vlib tsmc_lib35
Modelsim> vmap tsmc_lib35 tsmc_lib35
z Compile *.vhd to tsmc_lib35 library
選擇 Compile -> Compile...開啟 Compile HDL Source Files window.
在 Library form 中選擇 tsmc_lib35.
開始 compile *.vhd.
(有 warning 可以忽略)
6.開始 gate-level simulation for modelsim。
Verilog 版本
1.申請 CIC Cell-Base Design Kit。
z http://www.cic.edu.tw/chip_design/design_petition.html
2.得到所需 Verilog 版本的 Cell Library:
z .25 製程
路徑:CIC_CBDK25_V1/CIC/Verilog/tsmc25.v
z .35 製程
路徑:CBDK035_TSMC_TSMC/CIC/Verilog/tcb773p.v
3.Compile .25 製程 Verilog Library:
z Invoke modelsim
% vism&
z Create a library – artisan_lib25
Modelsim> vlib artisan_lib25
Modelsim> vmap artisan_lib25 artisan_lib25
z Compile tsmc25.v to artisan_lib25 library
選擇 Compile -> Compile...開啟 Compile HDL Source Files window.
在 Library form 中選擇 artisan_lib25.
開始 compile tsmc25.v.
4.Compile .35 製程 Verilog Library:
z Invoke modelsim
% vism&
z Create a library –tsmc_lib35
Modelsim> vlib tsmc_lib35
Modelsim> vmap tsmc_lib35 tsmc_lib35
z Compile tcb773p.v to tsmc_lib35 library
選擇 Compile -> Compile...開啟 Compile HDL Source Files window.
在 Library form 中選擇 tsmc_lib35.
開始 compile tcb773p.v
5.Load Design
Simulate -> Simulate…開啟 Simulate window.
選擇 Libraries 標籤,在 Search Libraries[-L]中加入 artisan_lib25 或 tsmc_lib35 的路徑.
選擇 Design 標籤,選取欲模擬的電路,再按 Load.
6.開始 gate-level simulation for modelsim。
How to dump VCD file
1.The VCD file format is specified in the IEEE 1364 standard. It is an ASCII file
containing header information, variable definitions, and variable value changes.
6.When you complete above steps, you can get the dump.vcd.
1.Debussy supports a new and open FSDB file format that has the following advantages over the
standard VCD file format:
An FSDB file is much more compact than the standard VCD file. Typically, an FSDB file is
about 5 to 50 times smaller than a VCD file.
The simulation run time for an FSDB file is faster than that for a VCD file. With FSDB files,
Debussy displays waveform and back-annotated signal values faster.
2.Prepare data file
novas.vhd that provided by Debussy.
/usr/debussy/share/PLI/modelsim_fli/SOLARIS2/novas.vhd
3.Compile novas.vhd.
%vlib novas
%vcom –work novas /usr/debussy/share/PLI/modelsim_fli/SOLARIS2/novas.vhd
4.Set the path of novas_fli.so to your library path.
%setenv LD_LIBRARY_PATH
/usr/debussy/share/PLI/modelsim_fli/SOLARIS2/:$LD_LIBRARY_PATH
5.Start your simulation.
Invoke ModelSim
%vsim&
Compile your design
Modelsim>vcom userdesign.vhd
Load your design to simulate (“userdesign” is the name of top entity or comfiguration)
Modelsim>vsim userdesign novas.novas
6.Assign FSDB command on command field.
Open a FSDB file
VSIM>fsdbDumpfile dump.fsdb
Set the depth of design you want to view signal
VSIM>fsdbDumpvars 2 entity_name
(“2” is the depth. “entity_name” is the name of top entity.)
7.Run your simulation.
VSIM>run 100000ns
8.End simulation to save the dump.fsdb.
Simulate -> End Simulation…
9.Use nWave of Dubussy to view FSDB file.
Invoke nWave
%nWave&
Please refer the Debussy’s training course to get more information.
Other method:
10. Reference the package pkg defined in novas.vhd. Add the following line to your VHDL design:
library novas;
use novas.pkg.all;
11. Compile novas.vhd to the novas library.
Modelsim>vlib novas
Modelsim>vmap novas novas
Modelsim>vcom –work novas novas.vhd
12. Add the routine in the package pkg to your design. For example:
Open a FSDB file
fsdbDumpfile("dump.fsdb");
Set the depth of design you want to view signal
fsdbDumpvars(2,"entity_name");
(“2” is the depth. “entity_name” is the name of top entity.)
13. When your simulation complete and end simulaton, you can get dump.fsdb.
*If your design is Verilog code, you also get dump.fsdb file from step 2 to step 8.
5. Compile VHDL code
VHDL LAB –ModelSim <Compile> -> <Compile…>
a. Use mouse to select source file “multi.vhd” in UP window.
Setup your environment b. Click <Compile> to compile the VHDL code.
1. Log in WS with username/password shown in the KB c. Click <Done> to close Compile window.
2. %/bin/rm –rf * 6. Execute simulation
3. %cicsetup <Simulate> -> <Simulate…>
4. Log out and then log in again a. Select the “Design” slice.
5. Copy setup files for VHD simulator (Mentor ModelSim) and b. Select the “cfg1_multiplier” in work library of middle window.
logic synthesyzer (Synopsys’s Design compiler): c. Click “Load” to load cfg1_multiplier
%cp –r /cad2/lab/VHDL/lab-modelsim ~/VHDL 7. Assign command on command field
>add wave /multiplier/a /multiplier/b /multiplier/z
6. %source /usr/mentor/cic_setup/modelsim.csh >force /multiplier/a 1011
------------------------------------------------------------------------ >force /multiplier/b 0011
LAB1 >run 500
1. %cd ~/VHDL/lab1 >force /multiplier/b 1010
2. Set up working directory for modelsim >run 500
%cp ~/VHDL/modelsim.ini . 8. Write step 7 to test.do. Using command script include test.do
3. Invoke ModelSim >do test.do
%vsim& 9. End Simulation to save results
4. Creat a work library. <Simulate> -> <End Simulation>
<File> -> <New> -> <Library…> 10. Review waveform
a. Enable “a new library and a logical mapping to it” in the Create %vsim –view vsim.wlf
New Library window. >add wave *
b. Fill in “work” in Library Name form. --------------------------------------------------------------------
c. Click <OK>.
1
LAB2 >add wave *
1. %cd ~/VHDL/lab2 >run -all
2. Set up working directory for modelsim ------------------------------------------------------------------------
%cp ~/VHDL/modelsim.ini . LAB3 Co-simulation:VHDL call Verilog
3. Invoke Modelsim 1. %cd ~/VHDL/lab3
%vsim& 2. Set up working directory for modelsim
4. Creat a new library %cp ~/VHDL/modelsim.ini .
>vlib work 3. Prview adder4.vhd and fa.v
5. map the new library to the work library 4. Revise adder4.vhd and run simulation
>vmap work work 5. Simulate 4bit-adder
6. Revise f_adder.vhd and run simulation %vsim&
7. Compile full adder >vlib work
>vcom f_adder.vhd testfixture_fa.vhd >vmap work work
8. Execute simulatioin >vlog fa.v
>vsim -wlf fadder.wlf work.cfg_testfa >vcom adder4.vhd testfixture_add4.vhd
9. Add all signal to wave form viewer. >vsim –wlf add4.wlf cfg_testadd4
>add wave * >add wave *
10. Run simulation >run -all
>run -all ------------------------------------------------------------------------
11. End Simulation to save result. LAB4 Co-simulation:Verilog call VHDL
<Simulate> -> <End Simulation> 1. %cd ~/VHDL/lab4
12. View the f_adder.do and study. 2. Set up working directory for modelsim
%vi f_adder.do %cp ~/VHDL/modelsim.ini .
13. Revise add4.vhd and run simulation 3. Prview adder4.v and fa.vhd
>vcom add4.vhd testfixture_add4.vhd 4. Simulate 4bit-adder
>vsim -wlf add4.wlf work.cfg_testadd4 %vsim&
2
>vlib work LAB6 FSM
>vmap work work 1. %cd ~/VHDL/lab6
>vcom fa.vhd 2. Set up working directory for modelsim
>vlog adder4.v %cp ~/VHDL/modelsim.ini .
>vcom testfixture_add4.vhd 3. Revise fsm.vhd
>vsim –wlf add4.wlf cfg_testadd4 % vi fsm.vhd
>add wave * 4. Simulate FSM
>run -all %vsim&
------------------------------------------------------------------------ >vlib work
LAB5 >vmap work work
1. %cd ~/VHDL/lab5 >vcom fsm.vhd test_fsm.vhd
2. Set up working directory for modelsim >vsim –wlf fsm.wlf work.cfg_testFSM
%cp ~/VHDL/modelsim.ini . >add wave *
3. Revise alu.vhd and test_alu.vhd >run -all
% vi alu.vhd ----------------------------------------------------------------------
% vi test_alu.vhd LAB7 Gate-level implementation and simulation for VHDL
4. Simulate ALU 1. %cd ~/VHDL/lab7
%vsim& 2. Set up working directory for modelsim
>vlib work %cp ~/VHDL/modelsim.ini .
>vmap work work 3. Set up environment for Synopsys Design Compiler
>vcom alu.vhd test_alu.vhd %cp ~/VHDL/.synopsys_dc.setup .
>vsim –wlf alu.wlf work.cfg_testALU %source /usr/synopsys/CICuser_setup/synthesis.csh
>add wave * 4. Run Synopsys Design Compiler
>run -all %da&
5. Revise ALU.vhd to concurrent version <Setup>-><command Window>
----------------------------------------------------------------------
3
5. Read VHDL RTL to DC “ALU.vhd”.
>Read –f vhdl alu.vhd 12. Revise “test_alu.vhd” to let it use the gate-level architecture
6. Choose Design in “alu_gate.vhd”
>current_design alu 13. Re-compile the “test_alu.vhd” and re-run the simulation
7. Perform logic synthesis ALU error?
>compile Because we forget to annotate the timing information into the
8. Create schematic design in “vsim” phase.
>create_schematic -herarchy 14. Add net delay to simulation
9. Change naming rule vhdl >vsim –sdftyp /u=alu.sdf –wlf alu.wlf work.cfg_testALU
>change_names –rule vhdl >add wave *
10. Output vhd gate-level netlist and SDF files >run -all
>write –f vhdl –h –o alu_gate.vhd ----------------------------------------------------------------------
>write_sdf –version 2.1 alu.sdf LAB8 Gate-level implementation and simulation for Verilog
!!!You may write step 5-10 to a dc file. 1. %cd ~/VHDL/lab8
Then type “include ???.dc” in the command field.to run all 2. Set up working directory for modelsim
commands. %cp ~/VHDL/modelsim.ini .
11. Simulate ALU in GATE level 3. Set up environment for Synopsys Design Compiler
%vsim& %cp ~/VHDL/.synopsys_dc.setup .
>vlib work %source /usr/synopsys/CICuser_setup/synthesis.csh
>vmap work work 4. Run Synopsys Design Compiler
>vcom alu_gate.vhd test_alu.vhd %da&
>vsim –wlf alu.wlf work.cfg_testALU <Setup>-><command Window>
>add wave * 5. Read VHDL RTL to DC
>run -all >Read –f vhdl alu.vhd
Have Error Message!!!. 6. Choose Design
Because to “ALU_test.vhd” use the RTL architecture in >current_design alu
4
7. Perform logic synthesis
>set_fix_multiple_port_nets -all -buffer_constants
> compile -map_effort medium
8. Change naming rule verilog
> change_names -rule verilog -hierarchy
9. Output verilog gate-level netlist and SDF files
> write -f verilog -h -o alu_gate.v
> write_sdf -version 2.1 alu.sdf
!!!You may write step 5-10 to a dc file.
Then type “include ???.dc” in the command field.to run all
commands..
10. Simulate ALU in GATE level
%vsim&
>vlib work
>vmap work work
>vlog alu_gate.v
>vcom test_alu.vhd
>vsim –L ../lab7/artisan_lib25 -sdftyp /U=alu.sdf -wlf alu.wlf \
work.cfg_testalu
>add wave *
>run -all