ĐỀ CƯƠNG ÔN TẬP THIẾT KẾ HỆ THỐNG SỐ
ĐỀ CƯƠNG ÔN TẬP THIẾT KẾ HỆ THỐNG SỐ
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
entity clk_div is
rst : in std_logic;
end clk_div;
begin
begin
count1s <= 0;
tmp2 <= '0';
count2s <= 0;
count5s <= 0;
else
count1s <= 0;
else
end if;
count2s <= 0;
else
end if;
count5s <= 0;
else
count5s <= count5s + 1;
end if;
end if;
end if;
end process;
end Behavioral;
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
entity Mach_giai_ma_led is
generic (
);
end Mach_giai_ma_led;
begin
PROCESS(clk)
BEGIN
if rising_edge(clk) then
cnt <= 0;
else
END IF;
end if;
END PROCESS;
begin
end if;
end process;
end Behavioral;
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
entity Adder_register is
clk : in STD_LOGIC;
end Adder_register;
component adder1
port(
);
end component;
component register_adder
clk: in std_logic;
enable: in std_logic;
);
end component;
component div10
port(clk100M : in std_logic;
end component;
begin
u1: adder1
port map(
B => Re_out,
);
u2: register_adder
port map(
);
u3: div10
library ieee;
use IEEE.STD_LOGIC_1164.ALL;
use ieee.std_logic_unsigned.all;
entity adder1 is
port (
);
end adder1;
begin
process(B)
begin
if B = x"99" then
end if;
end process;
end Behavioral;
library ieee;
use IEEE.STD_LOGIC_1164.ALL;
entity register_adder is
port (
rst : in std_logic;
clk: in std_logic;
enable: in std_logic;
);
end register_adder;
begin
process(clk, rst)
begin
end if;
end process;
end Behavioral;
LIBRARY IEEE;
USE IEEE.STD_LOGIC_1164.ALL;
USE IEEE.STD_LOGIC_UNSIGNED.ALL;
ENTITY div10 IS
END div10;
BEGIN
PROCESS(clk100M)
BEGIN
if rising_edge(clk100M) then
cnt <= 0;
else
END IF;
end if;
END PROCESS;
END behav;
Yêu cầu:
Chú ý: các trường hợp yêu cầu hiển thị trên led 7 đoạn đều sử dụng pmod_ssd
Nội dung:
1. Thiết kế mạch cộng hai số 4 bit BCD hiển thị kết quả trên led 7 đoạn
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.std_logic_unsigned.ALL;
entity bai1 is
Port (a,b: in std_logic_vector(3 downto 0);
sum :out std_logic_vector(4 downto 0) );
end bai1;
architecture Behavioral of bai1 is
signal temp: std_logic_vector (4 downto 0);
begin
temp <= ('0'& a) + b;
process(temp)
begin
if temp >9 then sum <= temp + 6;
else sum <= temp;
end if;
end process;
end Behavioral;
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.std_logic_unsigned.ALL;
entity tb_bai1 is
-- Port ( );
end tb_bai1;
a <= "0111";
b <= "1000";
a <= "1111";
b <= "0100";
entity bai2 is
Port ( A, B : in STD_LOGIC_VECTOR (7 downto 0);
Load, Reset : in STD_LOGIC;
Sum : out STD_LOGIC_VECTOR (7 downto 0);
Borrow : out STD_LOGIC);
end bai2;
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
entity tb_bai2 is
end tb_bai2;
begin
UUT: bai2
port map (A => A, B => B, Load => Load, Reset => Reset, Sum =>
Sum, Borrow => Borrow);
process
begin
A <= "11011010"; -- Example input A
B <= "00110101"; -- Example input B
Load <= '1'; -- Load inputs
Reset <='1';
wait for 10 ns; -- Allow time for computation
A <= "11001111"; -- Example input A
B <= "11110101"; -- Example input B
Load <= '1'; -- Load inputs
Reset <='0';
wait for 10 ns; -- Allow time for A
A <= "11000000"; -- Example input A
B <= "00110101"; -- Example input B
Load <= '0'; -- Load inputs
Reset <='0';
wait for 10 ns; -- Allow time for computation
A <= "11111111"; -- Example input A
B <= "10110101"; -- Example input B
Load <= '0'; -- Load inputs
Reset <='0';
wait for 10 ns; -- Allow time for computation
wait;
end process;
end Behavioral;
3. Thiết kế mạch chuyển đổi mã nhị phân 4 bit sang mã Gray 4 bit, kết quả
hiển thị trên led 7 đoạn
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
entity bai3 is
Port ( BinaryInput : in STD_LOGIC_VECTOR (3 downto 0);
GrayOutput : out STD_LOGIC_VECTOR (3 downto 0));
end bai3;
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
entity tb_bai3 is
end tb_bai3;
begin
UUT: bai3
port map (BinaryInput => BinaryInput, GrayOutput => GrayOutput);
process
begin
BinaryInput <= "1101"; -- Example input (binary)
wait for 10 ns; -- Allow time for computation
BinaryInput <= "0010"; -- Example input (binary)
wait for 10 ns; -- Allow time for APPEND_MODE
BinaryInput <= "1111"; -- Example input (binary)
wait for 10 ns; -- Allow time for APPEND_MODE
BinaryInput <= "0001"; -- Example input (binary)
wait for 10 ns; -- Allow time for computation
wait;
end process;
end Behavioral;
4. Thiết kế mạch chuyển đổi từ mã Gray 4 bit sang mã nhị phân 4 bit, kết quả
hiển thị trên led 7 đoạn
library IEEE;
use IEEE.STD_LOGIC_1164.ALL, IEEE.numeric_std.all;
entity bai4 is
Port ( gray_value : in std_logic_vector (3 downto 0);
numeric_value: out unsigned (3 downto 0) );
end bai4;
begin
--with gray_value select
--numeric_value <="0000" when "0000", "0001" when "0001",
--"0010" when "0011", "0011" when "0010",
--"0100" when "0110", "0101" when "0111",
--"0110" when "0101", "0111" when "0100",
--"1000" when "1100", "1001" when "1101",
--"1010" when "1111", "1011" when "1110",
--"1100" when "1010", "1101" when "1011",
--"1101" when "1001", "1111" when others;
numeric_value(3)<= gray_value(3);
numeric_value(2)<= gray_value(3) xor gray_value(2);
numeric_value(1)<= gray_value(3) xor gray_value(2) xor
gray_value(1);
numeric_value(0)<= gray_value(3) xor gray_value(2) xor
gray_value(1) xor gray_value(0);
end Behavioral;
library IEEE;
use IEEE.STD_LOGIC_1164.ALL, IEEE.numeric_std.all;
entity tb_bai4 is
-- Port ( );
end tb_bai4;
end Behavioral;
5. Thiết kế khối nhân hai số 4 bit BCD hiển thị kết quả trên led 7 đoạn
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
use IEEE.numeric_std.all;
entity bai5 is
Port (
BCD1 : in STD_LOGIC_VECTOR (3 downto 0);
BCD2 : in STD_LOGIC_VECTOR (3 downto 0);
Result : out STD_LOGIC_VECTOR (7 downto 0)
);
end bai5;
begin
process(BCD1, BCD2)
variable int1 : integer;
variable int2 : integer;
variable product : integer;
begin
int1 := BCD_to_Integer(BCD1);
int2 := BCD_to_Integer(BCD2);
product := int1 * int2;
Result <= Integer_to_BCD(product);
end process;
end Behavioral;
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
entity tb_bai5 is
end tb_bai5;
component bai5
Port (
BCD1 : in STD_LOGIC_VECTOR (3 downto 0);
BCD2 : in STD_LOGIC_VECTOR (3 downto 0);
Result : out STD_LOGIC_VECTOR (7 downto 0)
);
end component;
begin
uut: bai5
Port Map (
BCD1 => BCD1,
BCD2 => BCD2,
Result => Result
);
process
begin
-- Test case 1: 4 * 3 = 12
BCD1 <= "0100"; -- 4 in BCD
BCD2 <= "0011"; -- 3 in BCD
wait for 10 ns;
-- Test case 2: 7 * 5 = 35
BCD1 <= "0111"; -- 7 in BCD
BCD2 <= "0101"; -- 5 in BCD
wait for 10 ns;
6. Thiết kế khối chia hai số nhị phân 4 bit, kết quả phần thương số hiển thị trên
led RGB, và phần dư hiển thị trên led thường.
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
entity bai6 is
Port (
dividend : in STD_LOGIC_VECTOR(3 downto 0);
divisor : in STD_LOGIC_VECTOR(3 downto 0);
quotient : out STD_LOGIC_VECTOR(3 downto 0); -- thương
remainder : out STD_LOGIC_VECTOR(3 downto 0)
);
end bai6;
-- Division algorithm
for i in 0 to 3 loop
temp_remainder := temp_remainder(2 downto 0) &
temp_dividend(7);
temp_dividend := temp_dividend(6 downto 0) & '0';
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
entity tb_bai6 is
end tb_bai6;
component bai6
Port (
dividend : in STD_LOGIC_VECTOR(3 downto 0);
divisor : in STD_LOGIC_VECTOR(3 downto 0);
quotient : out STD_LOGIC_VECTOR(3 downto 0);
remainder : out STD_LOGIC_VECTOR(3 downto 0)
);
end component;
begin
uut: bai6
Port Map (
dividend => dividend,
divisor => divisor,
quotient => quotient,
remainder => remainder
);
process
begin
-- Test case 1: 10 / 3
dividend <= "1010"; -- 10 in binary
divisor <= "0011"; -- 3 in binary
wait for 10 ns;
-- Test case 2: 15 / 2
dividend <= "1111"; -- 15 in binary
divisor <= "0010"; -- 2 in binary
wait for 10 ns;
-- Test case 3: 8 / 4
dividend <= "1000"; -- 8 in binary
divisor <= "0100"; -- 4 in binary
wait for 10 ns;
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.NUMERIC_STD.ALL;
entity count is
Port (
clk100M: in std_logic;
reset: in std_logic;
clk1s: out std_logic;
cat1: out std_logic;
led_7segment: out std_logic_vector(6 downto 0)
);
end count;
architecture Behavioral of count is
component frequency is
generic(
N: natural:=1e8
);
port(
clk: in std_logic;
clk1s: out std_logic;
reset: in std_logic
);
end component;
component BCDto7seg is
Port (
clk: in std_logic;
reset: in std_logic;
cat: in std_logic;
led7seg: out std_logic_vector(6 downto 0)
);
end component;
component frequency1 is
Generic (
N: integer:=1e8
);
Port(
clk: in std_logic;
reset: in std_logic;
clk100s: out std_logic
);
end component;
signal cat_temp: std_logic;
signal clk_1s: std_logic;
begin
D1: frequency Generic map(N=>1e8)
Port map(
clk=>clk100M,
clk1s=>clk_1s,
reset=>reset
);
D100: frequency1 Generic map(N=>1e8)
port map(
clk=>clk100M,
reset=>reset,
clk100s=>cat_temp
);
C1: BCDto7seg port map(
clk=>clk_1s,
reset=>reset,
cat=>cat_temp,
led7seg=>led_7segment
);
cat1<=cat_temp;
end Behavioral;
8. Thiết kế mạch đếm tiến có reset đồng bộ/ không đồng bộ có thể là mã nhị
phân, mã BCD dư 3, mã Gray.
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
entity demBCDdu3 is
Port (
clk : in STD_LOGIC;
reset : in STD_LOGIC;
count_en : in STD_LOGIC;
BCD_out : out STD_LOGIC_VECTOR (3 downto 0);
BCD_div3 : out STD_LOGIC
);
end demBCDdu3;
begin
-- Output BCD_div3
BCD_div3 <= '1' when BCD_counter = "0011" else '0';
end Behavioral;
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
entity tb_demBCDdu3 is
end tb_demBCDdu3;
-- Component instantiation
component demBCDdu3
Port (
clk : in STD_LOGIC;
reset : in STD_LOGIC;
count_en : in STD_LOGIC;
BCD_out : out STD_LOGIC_VECTOR (3 downto 0);
BCD_div3 : out STD_LOGIC
);
end component;
begin
-- Instantiate the demBCDdu3 component
UUT: demBCDdu3
port map (
clk => clk,
reset => reset,
count_en => count_en,
BCD_out => BCD_out,
BCD_div3 => BCD_div3
);
-- Clock process
process
begin
while true loop
clk <= '0';
wait for clk_period / 2;
clk <= '1';
wait for clk_period / 2;
end loop;
end process;
-- Stimulus process
process
begin
-- Reset initially
reset <= '1';
count_en <= '0';
wait for 20 ns; -- Hold reset for a short period
reset <= '0';
wait for 10 ns;
-- Enable counting
count_en <= '1';
wait for 100 ns;
-- Hold counting
count_en <= '0';
wait for 20 ns;
-- Enable counting
count_en <= '1';
wait for 100 ns;
-- Hold counting
count_en <= '0';
wait for 20 ns;
-- End simulation
wait;
end process;
end behavior;
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
entity demgray is
Port (
clk : in STD_LOGIC;
reset : in STD_LOGIC;
Gray_out : out STD_LOGIC_VECTOR (3 downto 0)
);
end demgray;
begin
process(clk, reset)
begin
if reset = '1' then
binary_counter <= 0;
Gray_counter <= "0000";
elsif rising_edge(clk) then
binary_counter <= binary_counter + 1;
case binary_counter is
when 0 => Gray_counter <= "0000";
when 1 => Gray_counter <= "0001";
when 2 => Gray_counter <= "0011";
when 3 => Gray_counter <= "0010";
when 4 => Gray_counter <= "0110";
when 5 => Gray_counter <= "0111";
when 6 => Gray_counter <= "0101";
when 7 => Gray_counter <= "0100";
when 8 => Gray_counter <= "1100";
when 9 => Gray_counter <= "1101";
when 10 => Gray_counter <= "1111";
when 11 => Gray_counter <= "1110";
when 12 => Gray_counter <= "1010";
when 13 => Gray_counter <= "1011";
when 14 => Gray_counter <= "1001";
when 15 => Gray_counter <= "1000";
when others => Gray_counter <= "0000";
end case;
end if;
end process;
end Behavioral;
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
entity tb_demgray is
end tb_demgray;
-- Component instantiation
component demgray
Port (
clk : in STD_LOGIC;
reset : in STD_LOGIC;
Gray_out : out STD_LOGIC_VECTOR (3 downto 0)
);
end component;
begin
-- Instantiate the demgray component
UUT: demgray
port map (
clk => clk,
reset => reset,
Gray_out => Gray_out
);
-- Clock process
process
begin
while true loop
clk <= '0';
wait for clk_period / 2;
clk <= '1';
wait for clk_period / 2;
end loop;
end process;
-- Stimulus process
process
begin
-- Reset initially
reset <= '1';
wait for 20 ns; -- Hold reset for a short period
reset <= '0';
wait for 10 ns;
-- Enable counting
wait for 200 ns;
-- Hold counting
wait for 20 ns;
-- Hold counting
wait for 20 ns;
-- End simulation
wait;
end process;
end behavior;
9. Thiết kế mạch led 8 bit nháy theo yêu cầu: Ví dụ: yêu cầu led nháy lần lượt,
sáng lần lượt, hoặc tắt lần lượt theo thời gian yêu cầu
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
entity sang_led is
Port (clk, rst: in std_logic;
led: out std_logic_vector(7 downto 0));
end sang_led;
process (pr_state)
begin
case pr_state is
when idle =>
tmp <= "00000000";
nx_state <= S1;
when S1 =>
tmp <= "00000001";
nx_state <= S2;
when S2 =>
tmp <= "00000010";
nx_state <= S3;
when S3 =>
tmp <= "00000100";
nx_state <= S4;
when S4 =>
tmp <= "00001000";
nx_state <= S5;
when S5 =>
tmp <= "00010000";
nx_state <= S6;
when S6 =>
tmp <= "00100000";
nx_state <= S7;
when S7 =>
tmp <= "01000000";
nx_state <= S8;
when S8 =>
tmp <= "10000000";
nx_state <= S1;
when others =>
tmp <= "11111111";
nx_state <= idle;
end case;
end process;
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
entity tat_led is
Port (clk, rst: in std_logic;
led: out std_logic_vector(7 downto 0));
end tat_led;
architecture Behavioral of tat_led is
type tatled is (Idle, S1, S2, S3, S4, S5, S6, S7, S8);
signal pr_state, nx_state: tatled;
signal tmp: std_logic_vector(7 downto 0);
signal clk_1, clk_2, clk_5: std_logic;
component clk_div
Port ( clk_100M: in std_logic;
rst : in std_logic;
process (pr_state)
begin
case pr_state is
when idle =>
tmp <= "11111111";
nx_state <= S1;
when S1 =>
tmp <= "11111110";
nx_state <= S2;
when S2 =>
tmp <= "11111101";
nx_state <= S3;
when S3 =>
tmp <= "11111011";
nx_state <= S4;
when S4 =>
tmp <= "11110111";
nx_state <= S5;
when S5 =>
tmp <= "11101111";
nx_state <= S6;
when S6 =>
tmp <= "11011111";
nx_state <= S7;
when S7 =>
tmp <= "10111111";
nx_state <= S8;
when S8 =>
tmp <= "01111111";
nx_state <= S1;
when others =>
tmp <= "00000000";
nx_state <= idle;
end case;
end process;
10.Thiết kế mạch kiểm tra dãy tín hiệu đầu vào, yêu cầu: kiểm tra dãy tín hiệu
đầu vào là 1010….
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
entity fsm is
clk : in STD_LOGIC;
x : in STD_LOGIC;
end fsm;
begin
process(clk, reset)
begin
if rising_edge(clk) then
else
pr_moore <= nx_moore;
end process;
-------MOORE------
moore: process(pr_moore, x)
begin
case pr_moore is
if x ='0' then
else
end if;
when s1 =>
if x ='0' then
else
end if;
if x ='0' then
end if;
if x ='0' then
else
end if;
if x ='0' then
else
end if;
end case;
end process;
------OUT_MOORE------
out_moore: process(pr_moore)
begin
case pr_moore is
end case;
end process;
end Behavioral;
Yêu cầu: mỗi sinh viên đem theo tài liệu là USB vào phòng thi, mở vivado bằng
lệnh trên hệ điều hành Ubuntu như sau:
Source /opt/Xilinx/Vivado/2016.4/settings64.sh
Vivado