FPGA project : MUX2_1

博客提及FPGA开发的提升练习,但未给出具体内容。FPGA开发是信息技术领域重要部分,相关练习有助于提升开发能力。

 

 

module mux2_1 (
    input       wire    [0:0]   data_1      ,
    input       wire    [0:0]   data_2      ,
    input       wire    [0:0]   sel         ,

    output      reg     [0:0]   data_out 
);
    // method 1
    always @(*) begin
        if(sel == 1'b1) begin
            data_out = data_1 ;
        end else begin
            data_out = data_2 ;
        end
    end
    // method 2
    always @(*) begin
        case (sel)
            0 : begin
                data_out = data_1 ;
            end
            1 : begin
                data_out = data_2 ;
            end
            default: data_out = data_1 ;
        endcase
    end
    // method 3
    data_out = ( sel == 1'b1 ) ? data_1 : data_2 ;
endmodule
`timescale 1ps/1ps
module test();
    reg     [0:0]   data_1_tb      ;
    reg     [0:0]   data_2_tb      ;
    reg     [0:0]   sel_tb         ;
    wire    [0:0]   data_out_tb    ;

mux2_1 mux2_1_insert(
    .data_1             ( data_1_tb  ) ,
    .data_2             ( data_2_tb  ) ,
    .sel                ( sel_tb     ) ,

    .data_out           ( data_out_tb) 
);

    parameter CYCLE = 20 ;
    initial begin
        data_1_tb = 1'b1 ;
        data_2_tb = 1'b1 ;
        sel_tb    = 1'b1 ;
    end

    always #(CYCLE)     data_1_tb <= {$random} % 2 ;
    always #(CYCLE)     data_2_tb <= {$random} % 2 ;
    always #(CYCLE * 5) sel_tb    <= {$random} % 2 ;
    
endmodule

exercises for improvement :

module MUX8_1 (
    input    wire [07:00]           data_1  ,
    input    wire [07:00]           data_2  ,
    input    wire [07:00]           data_3  ,
    input    wire [07:00]           data_4  ,
    input    wire [07:00]           data_5  ,
    input    wire [07:00]           data_6  ,
    input    wire [07:00]           data_7  ,
    input    wire [07:00]           data_8  ,
    input    wire [02:00]           sel     ,

    output   reg  [07:00]           data_out
);

/*     always @(*) begin
        case (sel)
            3'b000 : begin
                data_out = data_1 ;
            end
            3'b001 : begin
                data_out = data_2 ;
            end
            3'b010 : begin
                data_out = data_3 ;
            end
            3'b011 : begin
                data_out = data_4 ;
            end
            3'b100 : begin
                data_out = data_5 ;
            end
            3'b101 : begin
                data_out = data_6 ;
            end
            3'b110 : begin
                data_out = data_7 ;
            end
            3'b111 : begin
                data_out = data_8 ;
            end
            default: data_out = data_1 ;
        endcase
    end */

/*     always@(*) begin
        if(sel == 3'b000)
            data_out = data_1 ;
        else if(sel == 3'b001)
            data_out = data_2 ;
        else if(sel == 3'b010)
            data_out = data_3 ;
        else if(sel == 3'b011)
            data_out = data_4 ;
        else if(sel == 3'b100)
            data_out = data_5 ;
        else if(sel == 3'b101)
            data_out = data_6 ;
        else if(sel == 3'b110)
            data_out = data_7 ;
        else if(sel == 3'b111)
            data_out = data_8 ;
        else 
            data_out = data_1 ;
    end */

    wire    [07:00]         data_out_w ;
    assign data_out_w = (sel == 3'b000) ? data_1 : (sel == 3'b001) ? data_2 : (sel == 3'b010) ? data_3 : (sel == 3'b011) ? data_4 : (sel == 3'b100) ? data_5 : (sel == 3'b101) ? data_6 : (sel == 3'b110) ? data_7 : (sel == 3'b111) ? data_8 : data_1 ;
    
    always @(*) begin
        data_out = data_out_w ;
    end

endmodule

Info: ******************************************************************* Info: Running Quartus II 64-Bit Analysis & Synthesis Info: Version 13.0.1 Build 232 06/12/2013 Service Pack 1 SJ Full Version Info: Processing started: Sat Oct 18 14:06:36 2025 Info: Command: quartus_map --read_settings_files=on --write_settings_files=off COExp -c COExp Info (20030): Parallel compilation is enabled and will use 16 of the 16 processors detected Info (12021): Found 1 design units, including 1 entities, in source file test_dff.bdf Info (12023): Found entity 1: test_dff Info (12021): Found 1 design units, including 1 entities, in source file gprs.bdf Info (12023): Found entity 1: GPRs Info (12021): Found 2 design units, including 1 entities, in source file lpm_decode_2to4.vhd Info (12022): Found design unit 1: lpm_decode_2to4-SYN Info (12023): Found entity 1: lpm_decode_2to4 Info (12021): Found 2 design units, including 1 entities, in source file lpm_mux_4to1_8bit.vhd Info (12022): Found design unit 1: lpm_mux_4to1_8bit-SYN Info (12023): Found entity 1: lpm_mux_4to1_8bit Info (12127): Elaborating entity "GPRs" for the top level hierarchy Info (12128): Elaborating entity "lpm_mux_4to1_8bit" for hierarchy "lpm_mux_4to1_8bit:inst6" Info (12128): Elaborating entity "LPM_MUX" for hierarchy "lpm_mux_4to1_8bit:inst6|LPM_MUX:LPM_MUX_component" Info (12130): Elaborated megafunction instantiation "lpm_mux_4to1_8bit:inst6|LPM_MUX:LPM_MUX_component" Info (12133): Instantiated megafunction "lpm_mux_4to1_8bit:inst6|LPM_MUX:LPM_MUX_component" with the following parameter: Info (12134): Parameter "LPM_WIDTH" = "8" Info (12134): Parameter "LPM_SIZE" = "4" Info (12134): Parameter "LPM_WIDTHS" = "2" Info (12134): Parameter "LPM_PIPELINE" = "0" Info (12134): Parameter "LPM_TYPE" = "LPM_MUX" Info (12134): Parameter "LPM_HINT" = "UNUSED" Info (12021): Found 1 design units, including 1 entities, in source file db/mux_j6e.tdf Info (12023): Found entity 1: mux_j6e Info (12128): Elaborating entity "mux_j6e" for hierarchy "lpm_mux_4to1_8bit:inst6|LPM_MUX:LPM_MUX_component|mux_j6e:auto_generated" Info (12128): Elaborating entity "test_dff" for hierarchy "test_dff:inst" Error (275061): Can't name logic function test_dff of instance "dff_inst4" -- function has same name as current design file Error (275061): Can't name logic function test_dff of instance "dff_inst1" -- function has same name as current design file Error (275061): Can't name logic function test_dff of instance "dff_inst2" -- function has same name as current design file Error (275061): Can't name logic function test_dff of instance "dff_inst3" -- function has same name as current design file Error (12152): Can't elaborate user hierarchy "test_dff:inst" Error: Quartus II 64-Bit Analysis & Synthesis was unsuccessful. 5 errors, 0 warnings Error: Peak virtual memory: 4637 megabytes Error: Processing ended: Sat Oct 18 14:06:38 2025 Error: Elapsed time: 00:00:02 Error: Total CPU time (on all processors): 00:00:01 Error (293001): Quartus II Full Compilation was unsuccessful. 7 errors, 0 warnings
10-19
Info: ******************************************************************* Info: Running Quartus Prime Analysis & Synthesis Info: Version 18.1.0 Build 625 09/12/2018 SJ Lite Edition Info: Processing started: Thu Jun 19 20:28:49 2025 Info: Command: quartus_map --read_settings_files=on --write_settings_files=off digital_calendar_top -c digital_calendar_top Warning (18236): Number of processors has not been specified which may cause overloading on shared machines. Set the global assignment NUM_PARALLEL_PROCESSORS in your QSF to an appropriate value for best performance. Info (20030): Parallel compilation is enabled and will use 16 of the 16 processors detected Info (12021): Found 1 design units, including 1 entities, in source file /shixun2/timer/timer.v Info (12023): Found entity 1: timer Info (12021): Found 1 design units, including 1 entities, in source file /shixun2/seg7_driver/seg7_driver.v Info (12023): Found entity 1: seg7_driver Info (12021): Found 1 design units, including 1 entities, in source file /shixun2/nyr2009/nyr2009.v Info (12023): Found entity 1: nyr2009 Info (12021): Found 1 design units, including 1 entities, in source file /shixun2/display_mux/display_mux.v Info (12023): Found entity 1: display_mux Info (12021): Found 1 design units, including 1 entities, in source file /shixun2/control/control.v Info (12023): Found entity 1: control Info (12021): Found 1 design units, including 1 entities, in source file /shixun2/clk_div/clk_div.v Info (12023): Found entity 1: clk_div Info (12021): Found 1 design units, including 1 entities, in source file /shixun2/adjust_mux/adjust_mux.v Info (12023): Found entity 1: adjust_mux Info (12021): Found 1 design units, including 1 entities, in source file digital_calendar_top.v Info (12023): Found entity 1: digital_calendar_top Info (12127): Elaborating entity "digital_calendar_top" for the top level hierarchy Info (12128): Elaborating entity "clk_div" for hierarchy "clk_div:u_clk_div" Warning (10230): Verilog HDL assignment warning at clk_div.v(22): truncated value with size 32 to match size of target (26) Warning (10230): Verilog HDL assignment warning at clk_div.v(30): truncated value with size 32 to match size of target (28) Info (12128): Elaborating entity "control" for hierarchy "control:u_control" Info (12128): Elaborating entity "adjust_mux" for hierarchy "adjust_mux:u_adjust_mux" Info (12128): Elaborating entity "timer" for hierarchy "timer:u_timer" Warning (10230): Verilog HDL assignment warning at timer.v(18): truncated value with size 32 to match size of target (6) Warning (10230): Verilog HDL assignment warning at timer.v(19): truncated value with size 32 to match size of target (6) Warning (10230): Verilog HDL assignment warning at timer.v(20): truncated value with size 32 to match size of target (5) Warning (10230): Verilog HDL assignment warning at timer.v(24): truncated value with size 32 to match size of target (6) Warning (10230): Verilog HDL assignment warning at timer.v(27): truncated value with size 32 to match size of target (6) Warning (10230): Verilog HDL assignment warning at timer.v(30): truncated value with size 32 to match size of target (5) Info (12128): Elaborating entity "display_mux" for hierarchy "display_mux:u_display_mux" Warning (10230): Verilog HDL assignment warning at display_mux.v(13): truncated value with size 32 to match size of target (4) Warning (10230): Verilog HDL assignment warning at display_mux.v(14): truncated value with size 32 to match size of target (4) Warning (10230): Verilog HDL assignment warning at display_mux.v(15): truncated value with size 32 to match size of target (4) Warning (10230): Verilog HDL assignment warning at display_mux.v(16): truncated value with size 32 to match size of target (4) Warning (10230): Verilog HDL assignment warning at display_mux.v(17): truncated value with size 32 to match size of target (4) Warning (10230): Verilog HDL assignment warning at display_mux.v(18): truncated value with size 32 to match size of target (4) Warning (10230): Verilog HDL assignment warning at display_mux.v(20): truncated value with size 32 to match size of target (4) Warning (10230): Verilog HDL assignment warning at display_mux.v(21): truncated value with size 32 to match size of target (4) Warning (10230): Verilog HDL assignment warning at display_mux.v(22): truncated value with size 32 to match size of target (4) Warning (10230): Verilog HDL assignment warning at display_mux.v(23): truncated value with size 32 to match size of target (4) Warning (10230): Verilog HDL assignment warning at display_mux.v(24): truncated value with size 32 to match size of target (4) Warning (10230): Verilog HDL assignment warning at display_mux.v(25): truncated value with size 32 to match size of target (4) Info (12128): Elaborating entity "seg7_driver" for hierarchy "seg7_driver:u_seg7_driver" Error (12006): Node instance "u_date" instantiates undefined entity "date". Ensure that required library paths are specified correctly, define the specified entity, or change the instantiation. If this entity represents Intel FPGA or third-party IP, generate the synthesis files for the IP. Error: Quartus Prime Analysis & Synthesis was unsuccessful. 1 error, 21 warnings Error: Peak virtual memory: 4767 megabytes Error: Processing ended: Thu Jun 19 20:28:56 2025 Error: Elapsed time: 00:00:07 Error: Total CPU time (on all processors): 00:00:16 Error (293001): Quartus Prime Full Compilation was unsuccessful. 3 errors, 21 warnings
06-20
评论 1
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值