天天看點

【續】FPGA電路邏輯的Verilog HDL程式設計方式設計與驗證FPGA電路邏輯的Verilog HDL程式設計方式設計與驗證

FPGA電路邏輯的Verilog HDL程式設計方式設計與驗證

上一篇是講述了原理圖的設計方式,這次使用Verilog HDL程式設計的方式進行設計和驗證, 在EDA工具中重新應用一次。
  • 實驗1:拼接 4-16譯碼器
  • 實驗2A : 設計M=12的計數器
  • 實驗2B : 設計M=20的計數器
  • 0-9往複的計數器

實驗1:拼接 4-16譯碼器

Verilog HDL設計4-16譯碼器:

module text_416(in_abc, out_d);
    input [:] in_abc;
    output  out_d;
    reg[:] out_d;

    [email protected](in_abc)
        begin
            case(in_abc)
                'b0000 : out_d = 'hfffe;
                'b0001 : out_d = 'hfffd;
                'b0010 : out_d = 'hfffb;
                'b0011 : out_d = 'hfff7;
                'b0100 : out_d = 'hffef;
                'b0101 : out_d = 'hffdf;
                'b0110 : out_d = 'hffbf;
                'b0111 : out_d = 'hff7f;
                'b1000 : out_d = 'hfeff;
                'b1001 : out_d = 'hfdff;
                'b1010 : out_d = 'hfbff;
                'b1011 : out_d = 'hf7ff;
                'b1100 : out_d = 'hefff;
                'b1101 : out_d = 'hdfff;
                'b1110 : out_d = 'hbfff;
                'b1111 : out_d = 'h7fff;

            endcase
        end

endmodule
           

仿真結果如下圖:

【續】FPGA電路邏輯的Verilog HDL程式設計方式設計與驗證FPGA電路邏輯的Verilog HDL程式設計方式設計與驗證

實驗2A : 設計M=12的計數器

Verilog HDL設計M=12計數器:

module text2a_12(CLK, Qabcd, CO);
    input CLK;
    output Qabcd,CO;
    reg[3:0] Qabcd,count;
    reg CO;

    [email protected](posedge CLK )
        begin
            if(count==)
                    count <= ;
            else
                    count <= count +  ;
        end
    [email protected](count )
        begin
            Qabcd = count;
            if(count == 11)
                CO = 1;
            else  CO= 0;
        end


endmodule

           

仿真結果如下圖:

【續】FPGA電路邏輯的Verilog HDL程式設計方式設計與驗證FPGA電路邏輯的Verilog HDL程式設計方式設計與驗證

實驗2B : 設計M=20的計數器

Verilog HDL設計M=20計數器:

module text2b_20(clk,Q,co);
    input clk;
    output Q,co;
    reg[:] Q,count;
    reg co;

    [email protected](posedge clk )
        begin
            if(count == )
                    count <= ;
            else 
                    count <= count + ;
        end
    [email protected](count)
        begin
            Q = count;
            if(count==)
                CO = ;
            else  CO = ;
        end

endmodule

           

仿真結果如下圖:

【續】FPGA電路邏輯的Verilog HDL程式設計方式設計與驗證FPGA電路邏輯的Verilog HDL程式設計方式設計與驗證

附加實驗 : 設計0-9往複計數器

Verilog HDL設計0-9往複計數器:

module text3_jiajian(clk,outq);
    input clk;
    output outq;

    reg[:] outq;
    reg[:] count;
    reg[:] count1;

    always @ ( negedge clk )
        begin
            if(count1 == )
                begin
                    count <= count + ;
                    if(count == )
                        begin
                            count1 <= count;
                            count <= count - ;
                        end
                end
            if(count1 == )
                begin
                    count <= count - ;
                    if(count == )
                        begin
                            count1 <= count;
                        end
                end

            outq <= count;
        end
endmodule
           

仿真結果如下圖:

【續】FPGA電路邏輯的Verilog HDL程式設計方式設計與驗證FPGA電路邏輯的Verilog HDL程式設計方式設計與驗證

通過以上實驗,可以看到,使用FPGA晶片,可以用Verilog HDL語言進行程式設計實作,能夠直接對電路功能進行設計, 更直接明了。