当前位置:网站首页>[Verilog] HDLBits Problem Solution - Circuits/Sequential Logic/Latches and Flip-Flops
[Verilog] HDLBits Problem Solution - Circuits/Sequential Logic/Latches and Flip-Flops
2022-08-03 12:11:00 【wjh776a68】
Sequential Logic
Latches and Flip-Flops
D flip-flop
题目链接
module top_module (
input clk, // Clocks are used in sequential circuits
input d,
output reg q );//
// Use a clocked always block
// copy d to q at every positive edge of clk
// Clocked always blocks should use non-blocking assignments
always @ (posedge clk) begin
q <= d;
end
endmodule
D flip-flops
题目链接
module top_module (
input clk,
input [7:0] d,
output [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 [7:0] q
);
always @ (posedge clk) begin
if (reset)
q <= 0;
else
q <= d;
end
endmodule
DFF with reset value
题目链接
module top_module (
input clk,
input reset,
input [7:0] d,
output [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 [7:0] q
);
always @ (posedge clk or posedge areset) begin
if (areset)
q <= 0;
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 [15:0] q
);
always @ (posedge clk) begin
if (~resetn) begin
q <= 16'b0;
end
else begin
q <= {
(({
8{
byteena[1]}} & d[15:8]) | ({
8{
~byteena[1]}} & q[15:8])), (({
8{
byteena[0]}} & d[7:0]) | ({
8{
~byteena[0]}} & q[7:0]))};
end
end
endmodule
D Latch
题目链接
module top_module (
input d,
input ena,
output q);
reg q_reg;
assign q = q_reg;
always @ (*) begin
if (ena)
q_reg <= d;
end
endmodule
DFF
题目链接
module top_module (
input clk,
input d,
input ar, // asynchronous reset
output q);
always @ (posedge clk or posedge ar) begin
if (ar)
q <= 0;
else
q <= d;
end
endmodule
DFF
题目链接
module top_module (
input clk,
input d,
input r, // synchronous reset
output q);
always @ (posedge clk) begin
if (r) begin
q <= 0;
end
else begin
q <= d;
end
end
endmodule
DFF + Gate
题目链接
module top_module (
input clk,
input in,
output out);
always @ (posedge clk) begin
out <= (in ^ out);
end
endmodule
Mux and DFF
题目链接
module top_module (
input clk,
input L,
input r_in,
input q_in,
output reg Q);
wire ff_in = L ? r_in : q_in;
always @ (posedge clk) begin
Q <= ff_in;
end
endmodule
Mux and DFF
题目链接
module top_module (
input clk,
input w, R, E, L,
output Q
);
wire ff_in_1 = E ? w : Q;
wire ff_in = L ? R : ff_in_1;
always @ (posedge clk) begin
Q <= ff_in;
end
endmodule
DFFs and gates
题目链接
module top_module (
input clk,
input x,
output z
);
reg Q_ff1 = 0, Q_ff2 = 0, Q_ff3 = 0;
wire D_ff1, D_ff2, D_ff3;
assign D_ff1 = x ^ Q_ff1;
assign D_ff2 = ~Q_ff2 & x;
assign D_ff3 = ~Q_ff3 | x;
assign z = ~(Q_ff1 | Q_ff2 | Q_ff3);
always @ (posedge clk) begin
Q_ff1 <= D_ff1;
Q_ff2 <= D_ff2;
Q_ff3 <= D_ff3;
end
endmodule
Create circuit from truth table
题目链接
module top_module (
input clk,
input j,
input k,
output Q);
reg Q_old;
always @ (posedge clk) begin
case({
j,k})
2'b00: Q <= Q_old;
2'b01: Q <= 0;
2'b10: Q <= 1;
2'b11: Q <= ~Q_old;
endcase
end
always @ (*) begin
Q_old <= Q;
end
endmodule
Detect an edge
题目链接
module top_module (
input clk,
input [7:0] in,
output [7:0] pedge
);
reg [7:0] in_old = 8'b0;
always @ (posedge clk) begin
pedge <= (in & ~in_old);
in_old <= in;
end
endmodule
Detect both edges
题目链接
module top_module (
input clk,
input [7:0] in,
output [7:0] anyedge
);
reg [7:0] in_old;
always @ (posedge clk) begin
anyedge <= in_old ^ in;
in_old <= in;
end
endmodule
Edge capture register
题目链接
module top_module (
input clk,
input reset,
input [31:0] in,
output [31:0] out = 32'b0
);
reg [31:0] in_old = 32'b0;
//reg reset_old = 0;
reg [31:0] out_last = 32'b0;
always @ (posedge clk) begin
if (reset) begin
out <= 'b0;
end
else begin
out <= (in_old & ~in) | out_last;
end
in_old <= in;
end
always @ (*) begin
out_last <= out;
end
endmodule
Edge capture register
题目链接
module top_module (
input clk,
input d,
output q
);
reg q_1, q_2;
assign q = clk ? q_1 : q_2;
always @ (posedge clk) begin
q_1 <= d;
end
always @ (negedge clk) begin
q_2 <= d;
end
endmodule
## Counters ## Shift Registers ## More Circuits ## Finite State Machines 边栏推荐
- [论文阅读] (23)恶意代码作者溯源(去匿名化)经典论文阅读:二进制和源代码对比
- 微信小程序获取手机号
- mysql advanced (twenty-four) method summary of defense against SQL injection
- Knowledge Graph Question Answering System Based on League of Legends
- 什么是bin文件?「建议收藏」
- PC client automation testing practice based on Sikuli GUI image recognition framework
- 流式编程使用场景
- 详解虚拟机!京东大佬出品HotSpot VM源码剖析笔记(附完整源码)
- 一文带你弄懂 CDN 技术的原理
- I in mother's womb SOLO20 years
猜你喜欢
随机推荐
LeetCode-48. 旋转图像
R语言使用zoo包中的rollapply函数以滚动的方式、窗口移动的方式将指定函数应用于时间序列、计算时间序列的滚动标准差(设置每个窗口不重叠)
什么是Weex
【一起学Rust】Rust学习前准备——注释和格式化输出
[深入浅出]三位数排序
最牛逼的集群监控系统,它始终位列第一!
解决oracle安装在linux中jdk的冲突
肝完Alibaba这份面试通关宝典,我成功拿下今年第15个Offer
php microtime 封装工具类,计算接口运行时间(打断点)
bash for循环
数据库系统原理与应用教程(075)—— MySQL 练习题:操作题 151-159(十九):综合练习
AMS simulation
深度学习中数据到底要不要归一化?实测数据来说明!
App自动化测试怎么做?实战分享App自动化测试全流程
长城简漫·暑期安全篇⑤ 这个强,不能逞
深入理解MySQL事务MVCC的核心概念以及底层原理
《数字经济全景白皮书》金融数字用户篇 重磅发布!
-找树根2-
第3章 搭建短视频App基础架构
mysql advanced (twenty-four) method summary of defense against SQL injection