Latches and Filp-Flops

Dff16e

byteena 使能信号在时钟边沿触发。byteena [1] 作为 d[15:8] 高8位使能端,byteena [0] 作为低8位使能端。

resetn 为低电平有效同步复位。

时钟上升沿触发。

module top_module (
    input clk,
    input resetn,
    input [1:0] byteena,
    input [15:0] d,
    output [15:0] q
);
    
    always@(posedge clk)begin 
        //同步时都拿始终当信号,不要添加复位为敏感变量
        if(~resetn)begin
        	q[15:0]<=16'b0;
        end
        else begin
        	if(byteena[0])begin
        		q[7:0]<=d[7:0];
        	end
        	//不应该考虑这种情况
        	//else begin
        		//q[7:0]<=8'b0;
        	//end
        	if(byteena[1])begin
        		q[15:8]<=d[15:8];
        	end
        	//同上
        end 
    end

endmodule

Exams/m2014 q4b

Exams m2014q4b.png

module top_module (
    input clk,
    input d, 
    input ar,   // asynchronous reset
    output q);
    
    always@(posedge clk or posedge ar)begin
    //图中显示复位信号上升沿有效
        if(ar)begin
            q<=0;
        end
        else begin
            q<=d;
        end
    end

endmodule

Exams/ece241 2014 q4

Ece241 2014 q4.png

module top_module (
    input clk,
    input x,
    output z
); 
    reg Q1,Q2,Q3;
    
    always@(posedge clk)begin
        Q1<=x^Q1;
        Q2<=x&~Q2;
        Q3<=x|~Q3;
        //z<=~( Q1 | Q2 | Q3);
        //非阻塞赋值各语句同时进行,z放在always块内不能准确赋值
    end
    
    assign z=~( Q1 | Q2 | Q3);

endmodule

Edgedetect

module top_module (
    input clk,
    input [7:0] in,
    output [7:0] pedge
);
    
    reg[7:0] in_last=8'b0;
    
    always@(posedge clk)begin
        in_last <= in;//上升沿检测,D触发器保留上一时钟的输入;
        pedge <= ~in_last & in;//上升沿检测,上一时钟0 现时钟1 为上升沿;
    end

endmodule

Edgedetect2

module top_module (
    input clk,
    input [7:0] in,
    output [7:0] anyedge //边沿检测
);
    
    reg[7:0] in_last;
    
    always@(posedge clk)begin
        in_last<=in;
        anyedge<=~in_last&in|in_last&~in; //上边沿及下边沿;
    end

endmodule

Edgecapture

(最高优先级)当reset为1时,out置0。(次级reset为0)① 检测下降沿,检测到后out置1; ② 但当reset不为1也没有下降沿时,out不变。

module top_module (
    input clk,
    input reset,
    input [31:0] in,
    output [31:0] out
);
    
    reg[31:0] in_last;
    
    always@(posedge clk)begin
        in_last<=in;
        if(reset)begin
            out<=32'b0;
        end
        else begin //reset=0;
            out<=~in&in_last | out; //有下降沿将out置1,否则out不变;
        end
        
    end

endmodule

Dualedge

module top_module (
    input clk,
    input d,
    output q
);
    
    reg q1,q2; //定义上升沿结果q1和下降沿结果q2;
    
    always@(posedge clk)begin
        q1<=d;
    end
    
    always@(negedge clk)begin
        q2<=d;
    end
    
    assign q=clk?q1:q2; //clk上升沿选q1,下降沿选q2;
    
endmodule

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值