数字逻辑电路基础-时序逻辑电路之移位寄存器

文章目录


一、移位寄存器定义

移位寄存器定义

A shift register is a type of digital circuit using a cascade of flip flops where the output of one flip-flop is connected to the input of the next.

移位寄存器是一种将一组D触发器进行级联输出而形成的一种时序逻辑电路。

在设计中经常会用到的一种基础时序电路,比如下面串转并电路,通过将串行输入的码流移位将其转换成并行数据输出。

本文设计一个简单的串并转换器,实现将串行输入数据转换成8位的并行数据进行输出,同时输出一个转换完成标志。


二、verilog源码

c 复制代码
// implement a simple 8bit serial to paralle convertor

module s2p_demo (clk, rstn, din, dout, done);
	input clk;
	input rstn;
	input din;
	output [7:0] dout;
	output done;
	
	reg [2:0] cnt;
	reg done;
	reg done_dly;
	reg [7:0] dout;
	reg [7:0] dout_dly;
	
	always@(posedge clk or negedge rstn)
	begin
		if(!rstn) begin
			dout_dly <= 8'bx; end
		else begin
			dout_dly[cnt] <= din; end
	end
	
	always@(posedge clk or negedge rstn)
	begin
		if(!rstn) begin
			dout <= 8'b0; end
		else if(done_dly) begin
			dout <= dout_dly;
			done <= done_dly; end
		else begin
			dout <= 8'b0;
			done <= done_dly; end
	end
	
	always@(posedge clk or negedge rstn)
	begin
		if(!rstn) begin
			cnt <= 3'b0;
			done_dly <= 1'b0; end
		else if(cnt == 3'b111) begin
			cnt <= 3'b0;
			done_dly <= 1'b1; end
		else begin
			cnt <= cnt + 1'b1;
			done_dly <= 1'b0;
		end
	end
endmodule

三、仿真结果


转载请注明出处!

相关推荐
通信小小昕2 小时前
FPGA|Verilog-SPI驱动
fpga开发·蓝桥杯·优化·verilog·spi·竞赛
TJ_Dream3 小时前
clk_prepare函数详细解析
驱动开发·fpga开发
起床学FPGA9 小时前
IBUF和BUFG
fpga开发
_Hello_Panda_13 小时前
基于AMD AU15P FPGA的SLVS-EC桥PCIe设计方案分享
fpga开发
数字芯片实验室14 小时前
3-2 深入解析数字电路设计中的竞争条件及解决策略
fpga开发
c-u-r-ry301 天前
009---基于Verilog HDL的单比特信号边沿检测
嵌入式硬件·fpga开发
数字芯片实验室1 天前
【AI速读】突破形式验证的极限:数据包协议验证实战指南
fpga开发
博览鸿蒙1 天前
Verilog学习方法—基础入门篇(二)
fpga开发
博览鸿蒙1 天前
Verilog学习方法—基础入门篇(一)
fpga开发
qq_416560201 天前
fmql之Linux WDT
linux·fpga开发