Hướng dẫn dùng Modelsim để mô phỏng cơ bản

 Chúng ta có thể sử dụng bản Modelsim-Altera được tích hợp sẵn khi cài đặt Quartus II.

Ta sẽ thiết kế 1 cổng AND bằng VHDL, viết testbench cho nó và mô phỏng.

Đầu tiên ta tạo 2 file: and_gate.vhd chứa code VHDL thiết kế cổng AND và and_gate_tb.vhd chứa testbench.

and_gate.vhd:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
library ieee;
use ieee.std_logic_1164.all;
 
entity and_gate is
  port (
    input_1    : in  std_logic;
    input_2    : in  std_logic;
    and_result : out std_logic
    );
end and_gate;
 
architecture rtl of and_gate is
  signal and_gate : std_logic;
begin
  and_gate   <= input_1 and input_2;
  and_result <= and_gate;
end rtl;

and_gate_tb.vhd:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
library ieee;
use ieee.std_logic_1164.all;
 
entity and_gate_tb is
end and_gate_tb;
 
architecture behave of and_gate_tb is
  signal r_SIG1   : std_logic := '0';
  signal r_SIG2   : std_logic := '0';
  signal w_RESULT : std_logic;
   
  component and_gate is
    port (
      input_1    : in  std_logic;
      input_2    : in  std_logic;
      and_result : out std_logic);
  end component and_gate;
   
begin
   
  and_gate_INST : and_gate
    port map (
      input_1    => r_SIG1,
      input_2    => r_SIG2,
      and_result => w_RESULT
      );
 
  process is
  begin
    r_SIG1 <= '0';
    r_SIG2 <= '0';
    wait for 10 ns;
    r_SIG1 <= '0';
    r_SIG2 <= '1';
    wait for 10 ns;
    r_SIG1 <= '1';
    r_SIG2 <= '0';
    wait for 10 ns;
    r_SIG1 <= '1';
    r_SIG2 <= '1';
    wait for 10 ns;   
  end process;
     
end behave;

Mở Modelsim bằng cách gõ modelsim từ Start:


Ta được cửa sổ như sau:










Nhận xét

Bài đăng phổ biến từ blog này

Một số nguyên tắc khi đặt tên tín hiệu, biến trong VHDL và Verilog

Cơ bản về FPGA: Khái niệm FPGA và ASIC