简单组合逻辑

多路选择器

在多路数据传输过程中,能够将任意一路选出来的电路叫做数据选择器,也称多路选择器。对于一个具有2^n个输入和一个输出的多路选择器,有n个选择变量,多路选择器也是FPGA内部的一个基本资源,主要用于内部信号的选通。简单的多路选择器还可以通过级联生成更大的多路选择器。

译码器

译码是编码的逆过程,在编码时,每一种二级制都有特定的含义,都表示一个确定的信号。把代码状态的含义翻译出来的过程叫做译码,实现该功能的电路叫做译码器。或者说,译码器是可以将输入二进制代码的状态翻译成输出信号,以表示原来含义的电路。

译码器是一类 多输入多输出 的组合逻辑电路器件,可以分为变量译码和显示译码。

多路选择器 if else
复制代码
module  mux_2_1
(
    input    wire    in1    ,
    input    wire    in2    ,
    input    wire    sel    ,
        
    output    reg    out
);

    always@(*)
    begin
        if(sel == 1'b1)
        begin
            out = in1    ;
        end
        else
        begin
            out = in2    ;
        end
    end



endmodule
多路选择器 case
复制代码
module mux2_1
(
    input    wire    in1    ,
    input    wire    in2    ,
    input    wire    sel    ,

    output    reg    out    
);

    always@(*)
    begin
        case(sel)
            1'b1:    out    =    in1    ;
            1'b0:    out    =    in2    ;
            default:    out    =    in1    ;
        endcase
    end
    


endmodule

多路选择器 ?:;

复制代码
module mux2_1
(
    input    wire    in1    ,
    input    wire    in2    ,
    input    wire    sel    ,

    output   wire    out
);



    assign    out    =    (sel == 1'b1)?in1:in2;


endmodule

译码器 if else

复制代码
module decode_3_8
(
    input    wire    in1    ,
    input    wire    in2    ,
    input    wire    in3    ,

    output   reg [7:0]    out    

);


    always@(*)
    begin
        if(  {in1,in2,in3}  == 3'b000 )
        begin
            out    =    8'b0000_0001    ;
        end
        else if(  {in1,in2,in3}  == 3'b001  )
        begin
            out    =    8'b0000_0010    ;
        end
        else if(   {in1,in2,in3} == 3'b010   )
        begin
            out    =    8'b0000_0100    ;
        end
        else if(   {in1,in2,in3} == 3'b011   )
        begin
            out    =    8'b0000_1000    ;
        end
        else if(   {in1,in2,in3} == 3'b100     )
        begin
            out    =    8'b0001_0000    ;
        end
        else if(   {in1,in2,in3}  == 3'b101    )
        begin
            out    =    8'b0010_0000    ;
        end
        else if(  {in1,in2,in3} == 3'b110  )
        begin
            out    =    8'b0100_0000    ;
        end
        else if(  {in1,in2,in3} == 3'b111  )
        begin
            out    =    8'b1000_0000    ;
        end
        else
        begin
            out    =    8'b0000_0001    ;
        end
    end



endmodule

译码器 case

复制代码
module decode3_8
(
    input    wire    in1    ,
    input    wire    in2    ,
    input    wire    in3    ,

    output   reg [7:0]    out
);

always@(*)
begin    
    case({in1,in2,in3})
        3'b000    :    out    =    8'b0000_0001    ;
        3'b001    :    out    =    8'b0000_0010    ;
        3'b010    :    out    =    8'b0000_0100    ;
        3'b011    :    out    =    8'b0000_1000    ;
        3'b100    :    out    =    8'b0001_0000    ;
        3'b101    :    out    =    8'b0010_0000    ;
        3'b110    :    out    =    8'b0100_0000    ;
        3'b111    :    out    =    8'b1000_0000    ;
        default   :    out    =    8'b0000_0001    ;
    endcase
end


endmodule

仿真验证

仿真文件编写

复制代码
`timescale 1ns/1ns

module tb_decode3_8();

    reg    in1    ;
    reg    in2    ;
    reg    in3    ;

    wire  [7:0] out    ;

    initial
    begin
        in1 <= 1'b0    ;
        in2 <= 1'b0    ;
        in3 <= 1'b0    ;
    end

    always #10    in1 <= {$random}%2    ;
    always #10    in2 <= {$random}%2    ;
    always #10    in3 <= {$random}%2    ;

    initial
    begin
        $timeformat(-9.0,"ns",6)    ;
        $monitor("@time %t , in1 = %b ,in2 = %b ,in3 = %b , out = %b ",$time,in1,in2,in3,out)    ;
    end


    decoder3_8    decoder3_8_inst
(
    .in1    (in1)    ,
    .in2    (in2)    ,
    .in3    (in3)    ,
    
    .out    (out)
);


endmodule
相关推荐
ZPC82105 天前
docker 镜像备份
人工智能·算法·fpga开发·机器人
ZPC82105 天前
docker 使用GUI ROS2
人工智能·算法·fpga开发·机器人
tiantianuser5 天前
RDMA设计53:构建RoCE v2 高速数据传输系统板级测试平台2
fpga开发·rdma·高速传输·cmac·roce v2
博览鸿蒙5 天前
FPGA 和 IC,哪个前景更好?怎么选?
fpga开发
FPGA_小田老师5 天前
xilinx原语:ISERDESE2原语详解(串并转换器)
fpga开发·iserdese2·原语·串并转换
tiantianuser6 天前
RDMA设计50: 如何验证网络嗅探功能?
网络·fpga开发·rdma·高速传输·cmac·roce v2
Lzy金壳bing6 天前
基于Vivado平台对Xilinx-7K325t FPGA芯片进行程序在线更新升级
fpga开发·vivado·xilinx
unicrom_深圳市由你创科技6 天前
医疗设备专用图像处理板卡定制
图像处理·人工智能·fpga开发
tiantianuser6 天前
RDMA设计52:构建RoCE v2 高速数据传输系统板级测试平台
fpga开发·rdma·高速传输·cmac·roce v2
luoganttcc6 天前
Taalas 将人工智能模型蚀刻到晶体管上,以提升推理能力
人工智能·fpga开发