【續】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 [3:0] in_abc;
    output  out_d;
    reg[15:0] out_d;

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

            endcase
        end

endmodule

仿真結果如下圖:

這裏寫圖片描述

實驗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;

    always@(posedge CLK )
        begin
            if(count==11)
                    count <= 0else
                    count <= count + 1 ;
        end
    always@(count )
        begin
            Qabcd = count;
            if(count == 11)
                CO = 1;
            else  CO= 0;
        end


endmodule

仿真結果如下圖:

空間有限

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

Verilog HDL設計M=20計數器:


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

    always@(posedge clk )
        begin
            if(count == 19)
                    count <= 0;
            else 
                    count <= count + 1;
        end
    always@(count)
        begin
            Q = count;
            if(count==19)
                CO = 1;
            else  CO = 0;
        end

endmodule

仿真結果如下圖:

空間有限

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

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


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

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

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

            outq <= count;
        end
endmodule

仿真結果如下圖:

這裏寫圖片描述

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

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章