使用FPGA实现多路复用器

本文介绍了如何仅用逻辑运算符通过when语句设计一个四输入多路复用器,展示了输入输出对应关系及两种实现方式,并给出了测试文件和仿真结果。
摘要由CSDN通过智能技术生成

介绍

对于多路复用器,大家肯定都已经不陌生了。多个输入通过多路复用器后只有一路输出。这里我实现一个四输入的多路复用器。

对于多路复用器,事实上只用逻辑运算操作符就可以实现,我这里给大家提供一种使用when语句实现的方法。


输入输出的对应关系

从上面的图中可以看到,电路有四个输入,1个输出。通过设置sel信号,当sel信号取不同的值时,对应输出a,b,c,d。


设计文件

library ieee;
use ieee.std_logic_1164.all;
entity mux_1 is
    port(
            a,b,c,d : in std_logic;
            sel : in std_logic_vector(1 downto 0);
            y : out std_logic);
end mux_1;
architecture mux_1 of mux_1 is
begin 
    y <= a when sel = "00"else
          b when sel = "01"else
          c when sel = "10"else
          d;
end mux_1;


下面使用另外一种when语句来实现相同的功能。

library ieee;
use ieee.std_logic_1164.all;
entity mux_2 is
    port(
            a,b,c,d : in std_logic;
            sel : in std_logic_vector(1 downto 0);
            y : out std_logic);
end mux_2;
architecture mux_2 of mux_2 is
begin 
    with sel select
        y <= a when "00",
              b when "01",
              c when "10",
              d when others;
end mux_2;


测试文件

library ieee;
use ieee.std_logic_1164.all;
entity tb_mux_1 is

end tb_mux_1;
architecture mux_1 of tb_mux_1 is
component mux_1 is
    port(
            a,b,c,d : in std_logic;
            sel : in std_logic_vector(1 downto 0);
            y : out std_logic);
end component mux_1;

signal a,b,c,d : std_logic;
signal sel : std_logic_vector(1 downto 0);
signal y : std_logic;

begin 
    dut : mux_1
    port map(
                a,b,c,d,sel,y);
    process
        begin
            a <= '0';
            b <= '1';
            c <= '1';
            d <= '0';
            sel <= "00";
            wait for 20ns;
            a <= '1';
            c <= '0';
            sel <= "01";
            wait for 20ns;
            b <= '0';
            c <= '0';
            d <= '1';
            sel <= "10";
            wait for 20ns;
            sel <= "11";
            wait for 20ns;
            sel <= "01";
            wait;
    end process;
end mux_1;


仿真结果


结语

有问题的话欢迎指出奥,哈哈哈哈。

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值