赞
踩
提示:文章写完后,目录可以自动生成,如何生成可参考右边的帮助文档
线性反馈移位寄存器是一种移位寄存器,通常带有几个异或门来产生移位寄存器的下一个状态。Galois LFSR是一种特殊的排列方式,其中带有“点击”的位与输出位异或以产生下一个值,而不带“点击”的位则发生移位。如果抽头位置是精心选择的,LFSR可以使“最大长度”。最大长度为n位的LFSR在重复之前会经过2n-1个状态(永远不会达到全零状态)。
Practice:Build a 4-bit shift register (right shift), with asynchronous reset, synchronous load, and enable.
翻译:设计一个4-bit的移位寄存器(右移),带异步复位信号,同步载入信号和使能信号。
Solution(不唯一,仅供参考):
module top_module( input clk, input areset, // async active-high reset to zero input load, input ena, input [3:0] data, output reg [3:0] q); always @(posedge clk or posedge areset)begin if(areset)begin q<=0; end else if(load)begin q<=data; end else if(ena)begin q<=(q>>1); end else begin q<=q; end end endmodule
Timing Diagram
Practice:Build a 100-bit left/right rotator, with synchronous load and left/right enable. A rotator shifts-in the shifted-out bit from the other end of the register, unlike a shifter that discards the shifted-out bit and shifts in a zero. If enabled, a rotator rotates the bits around and does not modify/discard them.
翻译:构建一个100位的左右旋转器,同步load,左右旋转需使能。旋转器从另一端输入移位的位元,不像移位器那样丢弃移位的位元而以零位移位。如果启用,旋转器就会旋转这些位,而不会修改或丢弃它们。
module top_module( input clk, input load, input [1:0] ena, input [99:0] data, output reg [99:0] q); always @(posedge clk)begin if(load)begin q<=data; end else begin case(ena) 2'b01:q<={q[0],q[99:1]}; 2'b10:q<={q[98:0],q[99]}; default: q<=q; endcase end end endmodule
Practice:Build a 64-bit arithmetic shift register, with synchronous load. The shifter can shift both left and right, and by 1 or 8 bit positions, selected by amount.
翻译:建立一个64位的算术移位寄存器,同步加载。移位器可以左移和右移,并按1位或8位的位置,按数量选择。
算术右移将移位移位寄存器中数字(在本例中为q[63])的符号位,而不是逻辑右移所做的零。另一种考虑算术右移的方法是它假设被移的数是有符号的并保留符号,所以算术右移可以将一个有符号的数除以2的幂。逻辑左移和算术左移之间没有区别。
load:加载数据
ena:决定是否移位
amount:决定移位方向与数量:2’b00:左移1位;2’b01:左移8位;2’b10:右移1位;2’b11:右移8位
q:寄存器内容(输出)
提示:
逻辑移位:左移时,低位补0;右移时,高位补0。
算数移位:左移时,低位补0;算术右移符号位要一起移动,并且在左边补上符号位,也就是如果符号位是1就补1符号位是0就补0 。
Solution(不唯一,仅供参考):
module top_module( input clk, input load, input ena, input [1:0] amount, input [63:0] data, output reg [63:0] q); always @(posedge clk)begin if(load)begin q<=data; end else if(ena)begin case(amount) 2'b00:q<={q[62:0],1'b0}; 2'b01:q<={q[55:0],8'b00000000}; 2'b10:q<={q[63],q[63:1]}; 2'b11:q<={{8{q[63]}},q[63:8]}; endcase end else begin q<=q; end end endmodule
Timing Diagram
Practice:Build this LFSR. The reset should reset the LFSR to 1.
翻译:下图显示了一个5位最大长度的Galois LFSR,它在5和3位处进行了取样(抽头为3、5,抽头位置通常从1开始编号)。注意,为了一致性,我在5号位置画了异或门,但其中一个异或门输入是0。
Solution(不唯一,仅供参考):
module top_module( input clk, input reset, // Active-high synchronous reset to 5'h1 output [4:0] q ); always @(posedge clk)begin if(reset)begin q<=5'h1; end else begin q[4]<=(1'b0)^q[0]; q[3]<=q[4]; q[2]<=q[3]^q[0]; q[1]<=q[2]; q[0]<=q[1]; end end endmodule
Timing Diagram
Practice:Write the Verilog code for this sequential circuit (Submodules are ok, but the top-level must be named top_module). Assume that you are going to implement the circuit on the DE1-SoC board. Connect the R inputs to the SW switches, connect Clock to KEY[0], and L to KEY[1]. Connect the Q outputs to the red lights LEDR.
翻译: 为这个序列电路编写Verilog代码。假设你要在DE1-SoC板上实现这个电路。将R输入连接到SW开关,将时钟连接到key[0],将L连接到key[1],将Q输出连接到红灯LEDR上。
Solution(不唯一,仅供参考):
module top_module ( input [2:0] SW, // R input [1:0] KEY, // L and clk output reg [2:0] LEDR); // Q always @(posedge KEY[0])begin if(KEY[1])begin LEDR<=SW; end else begin LEDR[0]<=LEDR[2]; LEDR[1]<=LEDR[0]; LEDR[2]<=LEDR[2]^LEDR[1]; end end endmodule
Practice:See Lfsr5 for explanations.Build a 32-bit Galois LFSR with taps at bit positions 32, 22, 2, and 1.
翻译:构建一个32位的Galois LFSR,其抽头位置为32、22、2和1。
Solution(不唯一,仅供参考):
module top_module( input clk, input reset, // Active-high synchronous reset to 32'h1 output reg [31:0] q ); always @(posedge clk)begin if(reset)begin q<=32'h1; end else begin for(int i=0;i<32;i++)begin if(i==21|i==1|i==0)begin q[i]<=q[i+1]^q[0]; end else if(i==31)begin q[31]<=1'b0^q[0]; end else begin q[i]<=q[i+1]; end end end end endmodule
Practice:Implement the following circuit:
翻译:实现以下电路
提示:可以看到,每个时钟周期,后一位的输入都来自前一位的输出,所以这是一个左移的移位寄存器(假设out为最高位)
Solution(不唯一,仅供参考):
module top_module ( input clk, input resetn, // synchronous reset input in, output out); reg [3:0] temp; assign out = temp[3]; always @(posedge clk)begin if(!resetn)begin temp<=0; end else begin temp<={temp[2:0],in}; end end endmodule
Practice:Consider the n-bit shift register circuit shown below:
翻译:考虑如下所示的n位移位寄存器电路:
Solution(不唯一,仅供参考):
使用generate语句(具体使用看总结)
module top_module ( input [3:0] SW, input [3:0] KEY, output [3:0] LEDR ); // MUXDFF MUXDFF1( .clk(KEY[0]), .w(KEY[3]), .R(SW[3]), .E(KEY[1]), .L(KEY[2]), .Q(LEDR[3]), ); MUXDFF MUXDFF2( .clk(KEY[0]), .w(LEDR[3]), .R(SW[2]), .E(KEY[1]), .L(KEY[2]), .Q(LEDR[2]), ); MUXDFF MUXDFF3( .clk(KEY[0]), .w(LEDR[2]), .R(SW[1]), .E(KEY[1]), .L(KEY[2]), .Q(LEDR[1]), ); MUXDFF MUXDFF4( .clk(KEY[0]), .w(LEDR[1]), .R(SW[0]), .E(KEY[1]), .L(KEY[2]), .Q(LEDR[0]), ); endmodule module MUXDFF ( input clk, input w, R, E, L, output Q ); always@(posedge clk)begin Q <= L ? R : (E ? w : Q); end endmodule
Practice:In this question, you will design a circuit for an 8x1 memory, where writing to the memory is accomplished by shifting-in bits, and reading is “random access”, as in a typical RAM. You will then use the circuit to realize a 3-input logic function.
First, create an 8-bit shift register with 8 D-type flip-flops. Label the flip-flop outputs from Q[0]…Q[7]. The shift register input should be called S, which feeds the input of Q[0] (MSB is shifted in first). The enable input controls whether to shift. Then, extend the circuit to have 3 additional inputs A,B,C and an output Z. The circuit’s behaviour should be as follows: when ABC is 000, Z=Q[0], when ABC is 001, Z=Q[1], and so on. Your circuit should contain ONLY the 8-bit shift register, and multiplexers. (Aside: this circuit is called a 3-input look-up-table (LUT)).
翻译:
Solution(不唯一,仅供参考):
module top_module ( input clk, input enable, input S, input A, B, C, output Z ); reg [7:0] Q; always @(posedge clk)begin if(enable)begin Q<={Q[6:0],S}; end else begin Q<=Q; end end assign Z=Q[{A,B,C}]; endmodule
Timing Diagram
1、 LFSR定义:
线性反馈移位寄存器(linear feedback shift register, LFSR)是指,给定前一状态的输出,将该输出的线性函数再用作输入的移位寄存器。异或运算是最常见的单比特线性函数:对寄存器的某些位进行异或操作后作为输入,再对寄存器中的各比特进行整体移位(百度百科定义)。
LFSR用于产生可重复的伪随机序列,该电路有n级触发器和一些异或门组成,如下图所示。
其中,gn为反馈系数,取值只能为0或1,取为0时表明不存在该反馈之路,取为1时表明存在该反馈之路;这里的反馈系数决定了产生随机数的算法的不同。
LFSR的初始值被称为伪随机序列的种子,影响下一个状态的比特位叫做抽头。
1.2、举例
下图的抽头为 3,2,则其反馈多项式为 .
以下需要注意:
1.抽头的数量必须为偶数;
2.抽头之间不能成对出现必须是互质的;
若设定初始种子为100,则下一个状态为:D0=D2=1,D1=D0=0;D2=D1^D2=1,则该状态为101,以此类推,有:100–101–111–011–110–001–010,状态个数为 2^n-1,(不能包含全零状态,全零将导致永远出不来),D触发器的个数越多,产生的状态就越多,也就越随机。
2、第七题,第九题需要多练练。
继续加油!!!!!
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。