【hdlbits】个人学习交流分享(带答案)——sequential logic部分

hdlbits网站:HDLBits (01xz.net)

其他HDLbits博客:

【hdlbits】个人学习交流分享(带答案)——verilog language部分-优快云博客

【hdlbits】个人学习交流分享(带答案)——combinational logic部分-优快云博客

【hdlbits】个人学习交流分享(带答案)——finite state machines(FSM)-优快云博客

【hdlbits】个人学习交流分享(带答案)——Reading Simulations和Writing Testbenches部分-优快云博客

正文:

latches and filp-flop

D filp-flop

module top_module (
    input clk,    // Clocks are used in sequential circuits
    input d,
    output reg q );//
    always @(posedge clk)begin
       q<=d; 
    end
endmodule

D filp-flops

module top_module (
    input clk,
    input [7:0] d,
    output reg [7:0] q
);
    always @(posedge clk)begin
        q<=d;
    end 
endmodule

DFF with reset

module top_module (
    input clk,
    input reset,            // Synchronous reset
    input [7:0] d,
    output reg [7:0] q
);
    always @(posedge clk)begin
        if(reset)
            q<=8'b0;
        else 
            q<=d;
    end
endmodule

DFF with reset value

module top_module (
    input clk,
    input reset,
    input [7:0] d,
    output reg [7:0] q
);
    always @(negedge clk)begin
        if(reset)
            q<=8'h34;
        else 
            q<=d;
    end
endmodule

DFF with asynchronous reset

module top_module (
    input clk,
    input areset,   // active high asynchronous reset
    input [7:0] d,
    output reg [7:0] q
);
    always @(posedge clk or posedge areset)begin
        if(areset)
            q<=8'b0;
        else
            q<=d;
    end
endmodule

DFF with byte enable

module top_module (
    input clk,
    input resetn,
    input [1:0] byteena,
    input [15:0] d,
    output reg [15:0] q
);
    always @(posedge clk)begin
        if(!resetn) begin
            q<=16'b0;
        end
        else begin
            case(byteena)
                2'b00:q<=q;
                2'b01:q[7:0]<=d[7:0];
                2'b10:q[15:8]<=d[15:8];
                2'b11:q<=d;
            endcase
        end
    end
endmodule

D latch

module top_module (
    input d, 
    input ena,
    output q);
    assign q=ena?d:q;
endmodule

DFF

module top_module (
    input clk,
    input d, 
    input ar,   // asynchronous reset
    output reg q);
    always @(posedge clk or posedge ar)begin
        if(ar)
            q<=1'b0;
        else 
            q<=d;
    end
endmodule

DFF

module top_module (
    input clk,
    input d, 
    input r,   // synchronous reset
    output reg q);
        always @(posedge clk)begin
        if(r)
            q<=1'b0;
        else 
            q<=d;
    end
endmodule

DFF+gate

module top_module (
    input clk,
    input in, 
    output reg out);
    wire d;
    assign d=out^in;
    always @(posedge clk)begin
        out<=d;
    end
endmodule

Mux and DFF

module top_module (
	input clk,
	input L,
	input r_in,
	input q_in,
	output reg Q);
    wire D;
    assign D=L?r_in:q_in;
    always @(posedge clk)begin
        Q<=D;
    end
endmodule

Mux and DFF

module top_module (
    input clk,
    input w, R, E, L,
    output reg Q
);
    wire a,D;
    assign a=E?w:Q;
    assign D=L?R:a;
    always @(posedge clk)begin
        Q<=D;
    end
endmodule

DFF and gates

module top_module (
    input clk,
    input x,
    output z
); 
    wire d1,d2,d3;
    wire q1,q2,q3;
    assign d1=x^q1;
    assign d2=x&(~q2);
    assign d3=x|(~q3);
    DFF DFF_1(.clk(clk),.d(d1),.q(q1));
    DFF DFF_2(.clk(clk),.d(d2),.q(q2));
    DFF DFF_3(.clk(clk),.d(d3),.q(q3));
    assign z=~(q1|q2|q3);
endmodule
module DFF(input clk,d,output reg q);
    initial begin// initial语句可以用作初始化赋值,但是initial不能和always块嵌套
        q=0;// 题意,D触发器在机器启动之前最初复位为零。
    end
    always @(posedge clk)begin
            q<=d;
    end
endmodule

create cirucit form truth table

module top_module (
    input clk,
    input j,
    input k,
    output reg Q); 
    always @(posedge clk)begin
        case({j,k})//注意不要误写成(j,k),{j,k}才能表示j和k拼接,()是case语句的部分
            2'b00:Q<=Q;
            2'b01:Q<=0;
            2'b10:Q<=1;
            2'b11:Q<=~Q;           
       endcase
    end
endmodule

detect an edge 

上升沿检测:对输入信号打一拍,打一拍的信号取反与原信号相与就可以检测出上升沿

下降沿检测:对输入信号打一拍,打一拍的信号与原信号取反相与就可以检测出下降沿<

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值