Professional Documents
Culture Documents
HCM-Khoa in-in T
L Ch Thng - chithong@gmail.com
Hng dn c bn
Khi ng ModelSim
Page 1 of 12
L Ch Thng - chithong@gmail.com
Nhp tn project l comb_ckt, thng chn tn project ging vi tn file cha m VHDL (.vhd) v thng thng cng ging vi tn ca entity ca m VHDL. Bm Browse chn th mc cha project. Nn to mt th mc ring cha cc file ca mt project. Bm OK
Bm Create New File to mt file mi. (Nu li g on m v d sau y th chn Add Existing File, ri chn fie comb_ckt.vhd km theo hng dn ny )
Nhp tn file l comb_ckt, chn loi file l VHDL, gi nguyn Folder l Top Level, ri bm OK. Page 2 of 12
L Ch Thng - chithong@gmail.com
-- behavior des.
Page 3 of 12
L Ch Thng - chithong@gmail.com
-- behavior des.
-------------------------------------------------------------library ieee; use ieee.std_logic_1164.all; use work.all; entity comb_ckt is port( input1: in std_logic; input2: in std_logic; input3: in std_logic; output: out std_logic ); end comb_ckt; architecture struct of comb_ckt is component AND_GATE is port( A: in std_logic; B: in std_logic; F1: out std_logic ); end component; component OR_GATE is port( X: in std_logic; Y: in std_logic; F2: out std_logic ); end component; signal wire: std_logic; begin -- use sign "=>" to clarify the pin mapping Gate1: AND_GATE port map (A=>input1, B=>input2, F1=>wire); Gate2: OR_GATE port map (X=>wire, Y=>input3, F2=>output); end struct; ----------------------------------------------------------------- as entity of AND_GATE -- top level circuit
-- as entity of OR_GATE
lu chng trnh.
Page 4 of 12
L Ch Thng - chithong@gmail.com
Page 5 of 12
L Ch Thng - chithong@gmail.com
Xem bo li g v ti dng lnh no. (Trong v d trn, li thiu du ; ti dng lnh 43) Bm Close ng ca s bo li. Sa li, lu v bin dch li cho n khi khng cn li.
To Testbench
Bm Project -> Add to Project -> New File to mt file testbench. (Nu li g on m v d sau y th chn Existing File, ri chn fie tb_ckt.vhd km theo hng dn ny )
Nhp vo tn file testbench l tb_ckt, , chn loi file l VHDL, gi nguyn Folder l Top Level, ri bm OK.
Page 6 of 12
L Ch Thng - chithong@gmail.com
Tng t nh phn to file comb_ckt.vhd, nhp on m VHDL sau cho file tb_ckt.vhd.
--------------------------------------------------------------------- Test Bench for comb_ckt.vhd -- (ESD figure 2.4) -- by Weijun Zhang, 04/2001 --- Testbench is used to ensure the design is working properly -- according to the specification. -- assert statements are used to test the wrong value against -- our desired one. we should test as many cases as possible, -- particularly, we should include upper and lower limits -- of the operations. -------------------------------------------------------------------library IEEE; use IEEE.std_logic_1164.all; use IEEE.std_logic_arith.all; entity CKT_TB is end CKT_TB; -- empty entity
------------------------------------------------------------------architecture TB of CKT_TB is -- declare the whole circuit(entity of comb_ckt.vhd) as a component component comb_ckt is port( input1: in std_logic; input2: in std_logic; input3: in std_logic; output: out std_logic ); end component; -- declare all I/O ports from unit under test as signals. -- signals are usually declared within architecture signal T_input1, T_input2, T_input3, T_output: std_logic; begin U_UT: comb_ckt port map (T_input1,T_input2,T_input3,T_output); process variable err_cnt: integer := 0; begin -- Test case 1 T_input1 <= '0'; T_input2 <= '0'; T_input3 <= '0'; wait for 10 ns; assert (T_output=((T_input1 or T_input2) and T_input3)) report "Failed Case1!" severity error; if (T_output/=((T_input1 or T_input2) and T_input3)) then err_cnt := err_cnt +1; end if; -- Test case 2
Page 7 of 12
L Ch Thng - chithong@gmail.com
Page 8 of 12
L Ch Thng - chithong@gmail.com
Chy m phng
Bm chn tab Library
Page 9 of 12
L Ch Thng - chithong@gmail.com
Page 10 of 12
L Ch Thng - chithong@gmail.com
Bm chn ca s Objects, ri bm Add -> To Wave -> Signals in Region thm cc tn hiu cn quan st vo ca s Wave Cc tn hiu va thm vo
Bt u chy m phng
Cch 1: Bm Simulate -> Run -> Run 100 chy m phng trong 100 ns
(Run)
Page 11 of 12
L Ch Thng - chithong@gmail.com
Cch 3: Nhp lnh run 100 vo du nhc lnh trong ca s Transcript ri Enter.
Quan st dng sng thu c trn ca s Wave. d quan st, bm nt phi chut trn ca s Wave, ri bm Zoom Full.
Kt qu t dng sng: Thi gian t_input1 t_input2 t_input3 t_output 0 10 ns 0 0 0 0 10 20 ns 1 1 1 1 20 30 ns 1 0 1 1 30 40 ns 0 1 0 0 Kt qu ny chng t mch t hp thit k ng !
Trong v d trn, ta vit m VHDL ca AND_GATE v OR_GATE chung vi comb_ckt trong cng mt file comb_ckt.vhd. Ta cng c th vit m VHDL ca AND_GATE v OR_GATE trong hai file ring r l AND_GATE.vhd v OR_GATE.vhd. Khi , ta phi thm vo project tng cng l 4 file (comb_ckt.vhd, AND_GATE.vhd, OR_GATE.vhd v tb_ckt.vhd). Xem thm v th chy m phng cc mch trong th mc VHDL codes km theo bi hng dn ny. Cc m VHDL dng trong bi hng dn ny v trong th mc VHDL codes l ca tc gi Weijun Zhang, University of California Riverside. Page 12 of 12