1. Trang chủ
  2. » Giáo Dục - Đào Tạo

Báo cáo môn thiết kế logic số4

15 5 0

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

THÔNG TIN TÀI LIỆU

Thông tin cơ bản

Định dạng
Số trang 15
Dung lượng 909,85 KB

Các công cụ chuyển đổi và chỉnh sửa cho tài liệu này

Nội dung

Viết chương trình mô tả bộ đếm tiến/lùi thập phân và hiển thị kết quả đếm trên LED 7 đoạn... BCDout: out std_logic_vector 3 downto 0 ; end Main; ---architecture Behavioral of Main is be

Trang 1

HỌC VIỆN CÔNG NGHỆ BƯU CHÍNH VIỄN THÔNG

KHOA: KĨ THUẬT ĐIỆN TỬ I

-🙞🙞🙞🙞🙞 -BÁO CÁO BÀI TẬP LỚN MÔN THIẾT KẾ LOGIC SỐ

Giảng viên : Ts.Trần Thúy Hà

Sinh viên thực hiện: Vũ Quang Sáng B18DCDT234

Nguyễn Tiến Thành B18DCDT202

Nhóm :02

Nhóm bài tập lớn:10

2021

Trang 2

I. Viết chương trình mô tả bộ đếm tiến/lùi thập phân và hiển thị kết quả đếm trên LED 7 đoạn.

1. Nguyên lý

1 đèn LED có thể hiển thị từ 0 đến 9 trong hệ thập phân thông qua 7 thanh diode hoạt động ở 2 mức tích cực 0,1

Mạch đếm thập phân tiến/lùi có clock , reset hoạt động khi clk=1 và trở về

0 khi reset=1

2. Code VHDL

library IEEE;

use IEEE.STD_LOGIC_1164.ALL;

-entity main is Port ( clk,reset,up : in STD_LOGIC := '0';

z : out STD_LOGIC := '0';

led : out STD_LOGIC_VECTOR (6 downto 0) :="0000000");

end main;

-architecture Behavioral of main is

signal reg,next_reg : integer := 0;

begin -process(clk)

begin if(clk'event and clk='1') then reg <= next_reg;

end if;

end process;

process(reg,up,reset) begin

if(reset='1') then next_reg <= 0; else case (reg) is

when 0 =>

if(up='1') then next_reg <= 1;

else next_reg <= 8;end if;

Trang 3

when 1 =>

if(up='1') then next_reg <= 2;

else next_reg <= 0;end if;

when 2 =>

if(up='1') then next_reg <= 3;

else next_reg <= 1;end if;

when 3 =>

if(up='1') then next_reg <= 4;

else next_reg <= 2;end if;

when 4 =>

if(up='1') then next_reg <= 5;

else next_reg <= 3;end if;

when 5 =>

if(up='1') then next_reg <= 6;

else next_reg <= 4;end if;

when 6 =>

if(up='1') then next_reg <= 7;

else next_reg <= 5;end if;

when 7 =>

if(up='1') then next_reg <= 8;

else next_reg <= 6;end if;

when 8 =>

if(up='1') then next_reg <= 0;

else next_reg <= 7;end if;

when others => next_reg <= 0;

end case;

end if;

end process;

-process(reg)

begin

if(up='1') then

if(reg=8) then z <= '1'; else z <= '0'; end if; else

if(reg=0) then z <= '1'; else z <= '0'; end if; end if;

case reg is abcdefg

Trang 4

when 0 => Led <= "1111110";

when 1 => Led <= "0110000";

when 2 => Led <= "1101101";

when 3 => Led <= "1111001";

when 4 => Led <= "0110011";

when 5 => Led <= "1011011";

when 6 => Led <= "1011111";

when 7 => Led <= "1110000";

when 8 => Led <= "1111111";

when 9 => Led <= "1111011";

when others => Led <= "0000000";

end case;

end process;

-end Behavioral;

3. Code Testbench

library IEEE;

use IEEE.STD_LOGIC_1164.ALL;

entity tb is

end tb;

architecture Behavioral of tb is

COMPONENT main

Port ( reset,up,clk : in STD_LOGIC:='0';

z : out STD_LOGIC:='0';

led : out STD_LOGIC_VECTOR (6 downto 0):="0000000" );

END COMPONENT;

Inputs

signal reset : std_logic := '0';

signal up : std_logic := '0';

signal clk : std_logic := '0';

Outputs

signal z : std_logic;

signal led : std_logic_vector(6 downto 0);

Trang 5

BEGIN uut: main PORT MAP ( reset => reset,

up => up, clk => clk,

z => z, led => led );

reset <='1' after 300ns;

clk <= not clk after 10ns;

up <='1';

END;

4. Kết quả hiển thị

II. Viết chương trình mô tả mạch phát hiện chuỗi bit nhị phân liên tiếp, đầu ra của nó là 1 khi xuất hiện chuỗi bit “111” và đầu ra là 0 trong các trường hợp còn lại.

1. Nguyên lý

Khi đọc 1 chuỗi bit có sẵn , 3 bit gần nhau sẽ được gộp vào để đọc và dịch bit dần từ trái qua phải

Khi xuất hiện chuỗi bit 111 thì đầu ra xuất ra ở mức tích cực cao

2. Code VHDL

library IEEE;

use IEEE.STD_LOGIC_1164.ALL;

Trang 6

entity main is

Port ( CLK : in STD_LOGIC;

CLR : in STD_LOGIC;

Din : in STD_LOGIC;

OutPut : out STD_LOGIC);

end main;

architecture Behavioral of main is

TYPE state is(S0,S1,S2,S3,S4,S5,S6,S7); Signal Current_state , next_state : state; Signal Flag : STD_LOGIC := '0';

begin

No1: process(CLK, CLR)

begin

if CLR = '1' then

Current_state <= S0;

elsif CLK'event and CLK = '1' then Current_state <= next_state;

end if;

end process;

No2: process(Current_state,Din)

begin

case Current_state is

when S0 =>

if Din = '0' then

next_state <= S0;

else next_state <= S1;

end if;

when S1 =>

if Din = '0' then

next_state <= S2;

else next_state <= S3;

end if;

when S2 =>

if Din = '0' then

next_state <= S4;

else next_state <= S5;

Trang 7

end if;

when S3 =>

if Din = '0' then next_state <= S6; else next_state <= S7; end if;

when S4 =>

next_state <= S0;

Flag <= '0';

when S5 =>

next_state <= S0;

Flag <= '0';

when S6 =>

next_state <= S0;

Flag <= '0';

when S7 =>

next_state <= S0;

Flag <= '1';

end case;

end process;

OutPut <= Flag;

end Behavioral;

3. Code Testbench

library IEEE;

use IEEE.STD_LOGIC_1164.ALL;

entity main is end main;

architecture Behavioral of main is component cau2 is

Port ( CLK : in STD_LOGIC; CLR : in STD_LOGIC;

Din : in STD_LOGIC;

Trang 8

OutPut : out STD_LOGIC);

end component;

Signal CLK, CLR ,Din: STD_LOGIC := '0';

Signal OutPut : STD_LOGIC;

begin VVT: cau2 port map(

CLK => CLK, CLR => CLR, Din => Din, OutPut => OutPut );

CLK <= not CLK after 10 ns;

CLR <= '0';

Din <= '1', '0' after 100 ns;

end Behavioral;

4. Kết quả hiển thị

III. Viết chương trình mô tả bộ biến mã từ Gray sang nhị phân 4 bit.

1. Nguyên lý hoạt động

Bộ chuyển đổi mã hóa từ Gray sang nhị phân 4 bit dựa theo nguyên lý : mỗi bit đằng sau bit 1 của mã Gray khi chuyển qua mã nhị phân đều sẽ đảo giá trị từ 0 sang 1 và ngược lại

2. Code Vhdl

library IEEE;

use IEEE.STD_LOGIC_1164.ALL;

-entity Main is

Port( GRAYin: in std_logic_vector (3 downto 0);

Trang 9

BCDout: out std_logic_vector (3 downto 0) );

end Main;

-architecture Behavioral of Main is

begin

BCDout <= "0000" when GRAYin = "0000" else

"0001" when GRAYin = "0001" else

"0010" when GRAYin = "0011" else

"0011" when GRAYin = "0010" else

"0100" when GRAYin = "0110" else

"0101" when GRAYin = "0111" else

"0110" when GRAYin = "0101" else

"0111" when GRAYin = "0100" else

"1000" when GRAYin = "1100" else

"1001" when GRAYin = "1101" else

"1010" when GRAYin = "1111" else

"1011" when GRAYin = "1110" else

"1100" when GRAYin = "1010" else

"1101" when GRAYin = "1011" else

"1110" when GRAYin = "1001" else

"1111" when GRAYin = "1000";

end Behavioral;

3. Code Testbench

LIBRARY ieee;

USE ieee.std_logic_1164.ALL;

USE ieee.std_logic_arith.ALL;

USE ieee.std_logic_unsigned.ALL;

- ENTITY Main_tb IS

END Main_tb;

- ARCHITECTURE behavior OF Main_tb IS

COMPONENT Main

PORT(

GRAYin : IN std_logic_vector(3 downto 0);

Trang 10

BCDout : OUT std_logic_vector(3 downto 0)

);

END COMPONENT;

Inputs

signal GRAYin : std_logic_vector(3 downto 0) := (others => '0');

Outputs

signal BCDout : std_logic_vector(3 downto 0);

BEGIN

Instantiate the Unit Under Test (UUT)

uut: Main PORT MAP (

GRAYin => GRAYin,

BCDout => BCDout

);

process

begin

GRAYin <= "0000";

for i in 0 to 15 loop

wait for 10 ns;

GRAYin <= GRAYin + 1;

end loop;

end process;

END;

4. Kết quả hiển thị

Trang 11

IV. Viết chương trình mô tả bộ hợp kênh 16:1, có đầu vào điều khiển hoạt động ở mức cao

1. Nguyên lý hoạt động

Bộ hợp kênh 16 đầu vào 1 đầu ra sử dụng cổng select 4 bit thay đổi 16 trạng thái Enable =1 mạch sẽ reset chạy lại từ đầu

2. Code Vhdl

library IEEE;

use IEEE.STD_LOGIC_1164.ALL;

entity mainc is Port ( A : in STD_LOGIC_VECTOR (15 downto 0);

S : in STD_LOGIC_VECTOR (3 downto 0);

E : in STD_LOGIC;

Y : out STD_LOGIC);

end mainc;

architecture Behavioral of mainc is signal P : STD_LOGIC_VECTOR(15 DOWNTO 0);

begin P(0) <= E AND A(0) AND (NOT S(0)) AND (NOT S(1)) AND (NOT S(2)) AND (NOT S(3));

P(1) <= E AND A(0) AND (NOT S(0)) AND (NOT S(1)) AND (NOT S(2)) AND S(3);

P(2) <= E AND A(0) AND (NOT S(0)) AND (NOT S(1)) AND S(2) AND (NOT S(3));

P(3) <= E AND A(0) AND (NOT S(0)) AND (NOT S(1)) AND S(2) AND S(3);

P(4) <= E AND A(0) AND (NOT S(0)) AND S(1) AND (NOT S(2)) AND (NOT S(3));

P(5) <= E AND A(0) AND (NOT S(0)) AND S(1) AND (NOT S(2)) AND S(3);

P(6) <= E AND A(0) AND (NOT S(0)) AND S(1) AND S(2) AND (NOT S(3));

P(7) <= E AND A(0) AND (NOT S(0)) AND S(1) AND S(2) AND S(3);

P(8) <= E AND A(0) AND S(0) AND (NOT S(1)) AND (NOT S(2)) AND (NOT S(3));

Trang 12

P(9) <= E AND A(0) AND S(0) AND (NOT S(1)) AND (NOT S(2)) AND S(3);

P(10) <= E AND A(0) AND S(0) AND (NOT S(1)) AND S(2) AND (NOT S(3));

P(11) <= E AND A(0) AND S(0) AND (NOT S(1)) AND S(2) AND S(3);

P(12) <= E AND A(0) AND S(0) AND S(1) AND (NOT S(2) AND (NOT S(3));

P(13) <= E AND A(0) AND S(0) AND S(1) AND (NOT S(2) AND S(3);

P(14) <= E AND A(0) AND S(0) AND S(1) AND S(2) AND (NOT S(3));

P(15) <= E AND A(0) AND S(0) AND S(1) AND S(2) AND S(3);

Y <= P(0) OR P(1) OR P(2) OR P(3) OR P(4) OR P(5) OR P(6) OR P(7) OR P(8) OR P(9) OR P(10) OR P(11) OR P(12) OR P(13) OR P(14) OR P(15);

end Behavioral;

3. Code Testbench

LIBRARY ieee;

USE ieee.std_logic_1164.ALL;

-ENTITY tb IS

END tb;

-ARCHITECTURE behavior OF tb IS

COMPONENT main

PORT( A : IN STD_LOGIC_VECTOR(15 DOWNTO 0);

S : IN STD_LOGIC_VECTOR( 3 DOWNTO 0);

E : IN STD_LOGIC;

Y : OUT STD_LOGIC );

END COMPONENT;

Inputs

signal A : std_logic_vector(15 downto 0):=(others => '0');

signal S : std_logic_vector(3 downto 0):=(others => '0');

Trang 13

signal E : std_logic :='0';

Outputs

signal Y : std_logic;

BEGIN

Instantiate the Unit Under Test (UUT)

uut: main PORT MAP (

A => A,

S => S,

E => E,

Y => Y

);

stim_proc : process

begin

wait for 10ns;

E <= '1' ; S <= "0000" ; A <=

wait for 10ns;

E <= '1' ; S <= "0001" ; A <=

wait for 10ns;

E <= '1' ; S <= "0010" ; A <=

wait for 10ns;

E <= '1' ; S <= "0011" ; A <=

wait for 10ns;

E <= '1' ; S <= "0100" ; A <=

wait for 10ns;

E <= '1' ; S <= "0101" ; A <=

wait for 10ns;

E <= '1' ; S <= "0110" ; A <= wait for 10ns;

E <= '1' ; S <= "0111" ; A <=

Trang 14

wait for 10ns;

E <= '1' ; S <= "1000" ; A <=

wait for 10ns;

E <= '1' ; S <= "1001" ; A <=

wait for 10ns;

E <= '1' ; S <= "1010" ; A <=

wait for 10ns;

E <= '1' ; S <= "1011" ; A <=

wait for 10ns;

E <= '1' ; S <= "1100" ; A <=

wait for 10ns;

E <= '1' ; S <= "1101" ; A <=

wait for 10ns;

E <= '1' ; S <= "1110" ; A <=

wait for 10ns;

E <= '1' ; S <= "1111" ; A <=

wait for 10ns;

wait;

end process;

end;

4. Kết quả hiển thị

Ngày đăng: 11/10/2022, 16:35

w