4-1 Verilog 4位移位寄存器的设计与实现

来源:互联网 发布:方齐禾淘宝 编辑:程序博客网 时间:2024/06/06 16:34

使用工具:Xilinx ISE 14.7


移位寄存器,不但可以寄存数码,还可以在脉冲信号的作用下,寄存数码可以根据需求发生偏移。在本次设计中使用分频信号来充当脉冲信号,控制在人眼可视范围内(始终频率低于10Hz)寄存自动发生发生偏移,代码如下:

module Design_Code(<span style="white-space:pre"></span>input clk,<span style="white-space:pre"></span>//input by "V10"<span style="white-space:pre"></span>input clr,<span style="white-space:pre"></span>input data,<span style="white-space:pre"></span>output reg [3:0] out    );<span style="white-space:pre"></span> reg [26:0] c;assign mclk = c[5];<span style="white-space:pre"></span>// The Data of Simulation<span style="white-space:pre"></span>//assign mclk = c[26];<span style="white-space:pre"></span>//Easy for person to distinguishalways @ (posedge clk)<span style="white-space:pre"></span>begin<span style="white-space:pre"></span>//c<= c + 1;<span style="white-space:pre"></span>if(clr)<span style="white-space:pre"></span>c<=0;<span style="white-space:pre"></span>else<span style="white-space:pre"></span>c <= c+1'b1;<span style="white-space:pre"></span>endalways @ (posedge mclk or posedge clr)<span style="white-space:pre"></span>begin<span style="white-space:pre"></span>if(clr)<span style="white-space:pre"></span>out <= 4'b0;<span style="white-space:pre"></span>else<span style="white-space:pre"></span>out <= {data, out[3:1]};<span style="white-space:pre"></span>endendmodule
在本次设计中使用到了非阻塞赋值“<=”。它与阻塞赋值“=”是有区别的。

阻塞赋值:算式y=b,一旦执行当前的赋值语句,赋值目标变量y几颗获得等号右边表达式的计算值。在这里值得注意的是,如果一块语句中含有多条阻塞赋值语句,那么当执行某一条语句时其他语句被阻塞,将禁止执行。阻塞赋值的执行有点像串行执行。

非阻塞赋值:算式y<=b,必须在语句块结束时完成整体赋值。在执行某一条语句时,对于语句块的其他赋值算式不进行限制,换句话说,语句块中的非阻塞赋值算式是并行执行的。

注意:由于assign不能引导语句块,故只能使用阻塞赋值。

注意:阻塞赋值与非阻塞赋值不可以混合使用。

测试文件:

initial begin// Initialize Inputsdata = 1;clr = 1;clk = 0;endalwaysbegin#1clk = ~clk;endalwaysbegin#100000clr = ~clr;endalwaysbegin#500data = ~data;end
注意:在写仿真部分时always与initial不能相互嵌套。使用复位信号(例如:clr)时,x先使能复位信号,一段时间后取消复位信号(避免系统一直处于复位状态)

仿真结果:

在这里可能需要仿真的时间比较长,可以通过调节仿真器的属性更改仿真时间,操作如下



0 0