Bài giảng Thiết kế logic số - Chương 2: Ngôn ngữ VHDL (Tiết 3)
Thiết kế logic số
(VLSI design)
TS. Hoàng Văn Phúc
Bộ môn KT Xung, số, Vi xử lý
02/2017
Nội dung
Nội dung: Phát biểu tuần tự
Thời lượng: 3 tiết bài giảng
2
VHDL statements
VHDL
statements
Sequential
Concurrent
Tuần tự
Đồng thời
3
Sequential statements (Phát biểu tuần tự)
KN: Là các phát biểu được thực thi một cách tuần tự
Việc thực thi phụ thuộc vào vị trí xuất hiện của chúng
trong chương trình.
Vị trí:
Trong các khối Processes (Quá trình), Procedures
(chương trình con) and Functions (Hàm)
Ứng dụng:
Dùng mô tả cho mạch tuần tự
Dùng mô tả mạch tổ hợp (ít dùng)
Dùng cho các cấu trúc mô phỏng, kiểm tra
4
Sequential statements
1. IF, CASE
2. WAIT, ASSERT, REPORT
3. LOOP
4. Sequential Signal Assignment
5
PROCESS
[label]: Process (sensitive list)
Variable: …
Begin
-- sequential statements
End process [label];
SENSITIVE LIST?
6
Lệnh IF
IF condition1 THEN
-- [sequence-of-statements1]
ELSIF condition2 THEN
--- [sequence-of-statements2]
ELSIF condition3 THEN
[sequence-of-statements3]
..
ELSE
[sequence-of-statementsN]
END IF;
7
IF Example 1: D-Flip Flop
Điều khiển theo sườn clock:
if rising_edge(clk) then …
if (clk='1' and clk'event) then …
if falling_edge(clk) then …
if (clk=‘0' and clk'event) then …
8
library ieee ;
use ieee.std_logic_1164.all;
entity dff is
port ( d: in std_logic;
rst: in std_logic;
clk: in std_logic;
q: out std_logic);
end dff;
architecture behv of dff is
begin
dff_proc: process(rst, clk)
begin
if (rst = ‘1’) then
q <= ‘0’;
-- clock rising edge
elsif (clk='1' and clk'event) then
q <= d;
end if;
end process dff_proc;
end behv;
9
IF Example 2: Register
D
clk, reset
REG1
Q
10
IF Example 3: Simple Counter
Counter enable?
Kd #= 2N
11
Lệnh CASE
CASE expression IS
WHEN choice1 =>
--[sequence-of-statements1]
WHEN choice2 =>
--[sequence-of-statements2]
...
WHEN others => -- optional if all choices covered
--[sequence-of-statementsN]
END CASE;
12
CASE – Example: Multiplexer
IN2(n-bit) IN1(n-bit)
Sel
MUX
Dout(n-bit)
13
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
entity mulx2_1 is
port (
in1 : in std_logic_vector(7 downto 0);
in2 : in std_logic_vector(7 downto 0);
sel : in std_logic;
dout : out std_logic_vector(7 downto 0)
);
end mux2_1;
architecture Behavioral of mux2_1 is
begin
process(in1, in2,sel)
begin
case sel is
when ’0’ => dout <= in1;
when others => dout <= in2;
end case;
end process;
end Behavioral;
14
Lệnh LOOP: 3 kiểu
for variable in range loop
-- sequence-of-statements
end loop;
while condition loop
-- sequence-of-statements
end loop;
loop
-- sequence-of-statements
exit when condition
end loop;
15
Lệnh LOOP: Ví dụ (1) – Không có điều kiện
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
-----------------------------------------
entity loop_example is
port(
vector_in : in std_logic_vector(7 downto 0);
out1
);
: out std_logic
end loop_example;
------------------------------------------
architecture loop1 of loop_example is
begin
loop_p: process (vector_in)
variable i : integer;
variable p : std_logic;
begin
p := '1';
for i in 7 downto 0 loop
p := p and vector_in(i);
end loop;
out1 <= p;
end process loop_p;
end loop1;
16
Lệnh LOOP: Ví dụ (2)
architecture loop2 of loop_example is
begin
loop_p: process (vector_in)
variable i: integer;
variable p: std_logic;
begin
i := 7;
p := '1';
while (i >= 0) loop
p := p and vector_in(i);
i := i-1;
end loop;
out1 <= p;
end process loop_p;
end loop2;
17
Lệnh LOOP: Ví dụ (3)
architecture loop3 of loop_example is
begin
loop_p: process (vector_in)
variable i: integer;
variable p: std_logic;
begin
p := '1';
i := 7;
loop
p := p and vector_in(i);
i := i-1;
exit when i < 0;
end loop;
out1 <= p;
end process loop_p;
end loop3;
18
Trắc nghiệm
Câu 1: Điểm đặc trưng nhất của các phát biểu tuần tự
trong VHDL
A. Câu lệnh được thực thi một cách tuần tự theo thứ tự
xuất hiện
B. Lệnh tuần tự được biên dịch thành mã máy giống như
câu lệnh của phần mềm.
C. Lệnh tuần tự chỉ xuất hiện trong khối process hoặc
chương trình con
D. Câu lệnh tuần tự dùng để mô tả mạch tuần tự
19
Trắc nghiệm
Câu 2: Đặc điểm khác biệt giữa lệnh IF và lệnh CASE
A. Không có sự khác biệt, hai lệnh này có thể sử dụng
thay thế lẫn nhau.
B. Điều kiện trong câu lệnh CASE là điều kiện cùng cấp
còn điều kiện trong câu lệnh IF là điều kiện phân cấp
C. Lệnh CASE thường dùng cho các khối tổ hợp, còn
lệnh IF sử dụng cho khối mạch tuần tự
D. Không có sự khác biệt rõ rệt giữa hai câu lệnh
20
Tải về để xem bản đầy đủ
Bạn đang xem 20 trang mẫu của tài liệu "Bài giảng Thiết kế logic số - Chương 2: Ngôn ngữ VHDL (Tiết 3)", để tải tài liệu gốc về máy hãy click vào nút Download ở trên
File đính kèm:
bai_giang_thiet_ke_logic_so_chuong_2_ngon_ngu_vhdl_tiet_4.pdf

