简单组合逻辑

多路选择器

在多路数据传输过程中,能够将任意一路选出来的电路叫做数据选择器,也称多路选择器。对于一个具有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
相关推荐
电棍2338 小时前
verilog笔记
笔记·fpga开发
ZxsLoves19 小时前
【【Systemverilog学习参考 简单的加法器验证-含覆盖率】】
学习·fpga开发
Ronin-Lotus21 小时前
嵌入式硬件篇---数字电子技术中的触发器
嵌入式硬件·fpga开发·触发器·数字电子技术·上位机知识
ehiway1 天前
FPGA+GPU+CPU国产化人工智能平台
人工智能·fpga开发·硬件工程·国产化
蓑衣客VS索尼克2 天前
什么是逻辑分析仪?
arm开发·人工智能·fpga开发
Terasic友晶科技3 天前
第29篇 基于ARM A9处理器用C语言实现中断<五>
c语言·fpga开发·定时器中断
9527华安3 天前
FPGA实现GTY光口视频转USB3.0传输,基于FT601+Aurora 8b/10b编解码架构,提供2套工程源码和技术支持
fpga开发·音视频·aurora·gty·usb3.0·ft601
博览鸿蒙3 天前
FPGA开发要学些什么?如何快速入门?
fpga开发
@晓凡3 天前
FPGA中利用fifo时钟域转换---慢时钟域转快时钟域
fpga开发
乘风~&3 天前
fpga助教面试题
fpga开发