14通信工程光健+电赛FPGA作业

计数器

第一题

  • 电路生成的RTL图
    14通信工程光健+电赛FPGA作业_第1张图片

  • 仿真波形图
    14通信工程光健+电赛FPGA作业_第2张图片

  • HDL代码

module cnt3(clk,rst,cnt);
input clk,rst;
output [2:0] cnt;
reg [2:0] cnt;
reg [2:0] q=5;
always @(posedge clk)
    begin
        if(!rst) begin
        cnt<=3'b000;
        end
    else begin 
        if(cnt==q) begin
        cnt<=3'b000;
        end
    else begin
        cnt<=cnt+3'b001;
    end
    end
    end
endmodule 

第二题

  • 电路生成的RTL图
    14通信工程光健+电赛FPGA作业_第3张图片

  • 仿真波形图
    14通信工程光健+电赛FPGA作业_第4张图片

  • HDL代码

module cnt4 (clk,cnt,rst);
input clk,rst;
output [3:0] cnt;
reg [3:0] cnt;
reg [3:0] q=6;
always @ (posedge clk)
    begin
        if(!rst) begin
        cnt <= 4'b0000;
        end
    else begin
        if(q==10) begin
        cnt <= 4'b0000;
        q <= 6;
        end
        if(cntbegin
        cnt <= cnt+4'b0001;
        end
    else begin
        cnt <= 4'b0000;
        q <= q+1;
    end
    end
    end
endmodule 

你可能感兴趣的:(14通信工程光健+电赛FPGA作业)