当前位置:网站首页>[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 边栏推荐
- 使用.NET简单实现一个Redis的高性能克隆版(一)
- pandas连接oracle数据库并拉取表中数据到dataframe中、筛选当前时间(sysdate)到一天之前的所有数据(筛选一天范围数据)
- 从器件物理级提升到电路级
- TiKV & TiFlash 加速复杂业务查询丨TiFlash 应用实践
- 特征工程学习笔记
- R语言ggplot2可视化:使用patchwork包的plot_layout函数将多个可视化图像组合起来,ncol参数指定行的个数、byrow参数指定按照行顺序排布图
- 622. 设计循环队列
- 【一起学Rust】Rust包管理工具Cargo初步了解
- 解决oracle安装在linux中jdk的冲突
- Vs 快捷键---探索不一样的编程
猜你喜欢
零拷贝、MMAP、堆外内存,傻傻搞不明白...
5个超好用手机开源自动化工具,哪个适合你?
mysql advanced (twenty-four) method summary of defense against SQL injection
基于SSM和Web实现的农作物生长监控系统
零信任的基本概念【新航海】
After completing the interview and clearance collection of Alibaba, I successfully won the 15th Offer this year
肝完Alibaba这份面试通关宝典,我成功拿下今年第15个Offer
QGIS绘制演习区域示意图
TiKV & TiFlash 加速复杂业务查询丨TiFlash 应用实践
Knowledge Graph Question Answering System Based on League of Legends
随机推荐
bash if conditional judgment
Take you understand the principle of CDN technology
一个扛住 100 亿次请求的红包系统,写得太好了!!
基于英雄联盟的知识图谱问答系统
【Verilog】HDLBits题解——Circuits/Sequential Logic/Latches and Flip-Flops
零信任的基本概念【新航海】
(通过页面)阿里云云效上传jar
什么是Weex
OFDM 十六讲 4 -What is a Cyclic Prefix in OFDM
微信小程序获取手机号
R语言ggplot2可视化:使用ggpubr包的ggline函数可视化折线图、设置add参数为mean_se和dotplot可视化不同水平均值的折线图并为折线图添加误差线(se标准误差)和点阵图
ThreadLocal源码解析及使用场景
Simple implementation of a high-performance clone of Redis using .NET (1)
【倒计时5天】探索音画质量提升背后的秘密,千元大礼等你来拿
数据库系统原理与应用教程(075)—— MySQL 练习题:操作题 151-159(十九):综合练习
分享一款实用的太阳能充电电路(室内光照可用)
数据库系统原理与应用教程(073)—— MySQL 练习题:操作题 131-140(十七):综合练习
bash for loop
Vs 快捷键---探索不一样的编程
无监督学习KMeans学习笔记和实例