提示:文章写完后,目录可以自动生成,如何生成可参考右边的帮助文档

文章目录

  • 前言
  • 一、Shift Registers
    • 1.4-bit shift register
    • 2.Left/right rotator
    • 3.Left/right arithmetic shift by 1 or 8
    • 4.5-bit LFSR
    • 5.3-bit LFSR
    • 6.32-bit LFSR
    • 7.Shift register
    • 8.Shift register
    • 9.3-input LUT
  • 总结

前言

线性反馈移位寄存器是一种移位寄存器,通常带有几个异或门来产生移位寄存器的下一个状态。Galois LFSR是一种特殊的排列方式,其中带有“点击”的位与输出位异或以产生下一个值,而不带“点击”的位则发生移位。如果抽头位置是精心选择的,LFSR可以使“最大长度”。最大长度为n位的LFSR在重复之前会经过2n-1个状态(永远不会达到全零状态)。

一、Shift Registers

1.4-bit shift register

Practice:Build a 4-bit shift register (right shift), with asynchronous reset, synchronous load, and enable.
翻译:设计一个4-bit的移位寄存器(右移),带异步复位信号,同步载入信号和使能信号。

  • areset: 异步复位信号,复位值为0
  • load:有效时,寄存器载入data的值,而不是移位;
  • load优先级高于ena
  • ena: 右移使能信号
  • q: 移位寄存器的内容

Solution(不唯一,仅供参考):

module top_module(input clk,input areset,  // async active-high reset to zeroinput load,input ena,input [3:0] data,output reg [3:0] q); always @(posedge clk or posedge areset)beginif(areset)beginq<=0; endelse if(load)beginq<=data;endelse if(ena)beginq<=(q>>1); endelse beginq<=q; endend
endmodule

Timing Diagram

2.Left/right rotator

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,左右旋转需使能。旋转器从另一端输入移位的位元,不像移位器那样丢弃移位的位元而以零位移位。如果启用,旋转器就会旋转这些位,而不会修改或丢弃它们。

  • load:加载100位的移位寄存器数据
  • ena[1:0]:2’b01 右转1bit; 2’b10 左转1bit;其他情况不转 q:旋转器内容
    提示:本题与上题的区别在于,右移后最低位不舍弃,而是将其放到最高位上;右移后最高位不舍弃,而是将其放到最低位上。比较类似流水灯的效果。此外,设计到左移和右移的选择,所以就可以使用case语句做选择。
    Solution(不唯一,仅供参考):
module top_module(input clk,input load,input [1:0] ena,input [99:0] data,output reg [99:0] q); always @(posedge clk)beginif(load)beginq<=data; endelse begincase(ena)2'b01:q<={q[0],q[99:1]};2'b10:q<={q[98:0],q[99]};default: q<=q;endcaseendend
endmodule

3.Left/right arithmetic shift by 1 or 8

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)beginif(load)beginq<=data; endelse if(ena)begincase(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]};endcaseendelse beginq<=q; endend
endmodule

Timing Diagram

4.5-bit LFSR

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'h1output [4:0] q
); always @(posedge clk)beginif(reset)beginq<=5'h1; endelse beginq[4]<=(1'b0)^q[0];q[3]<=q[4];q[2]<=q[3]^q[0];q[1]<=q[2];q[0]<=q[1];endend
endmodule

Timing Diagram

5.3-bit LFSR

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,      // Rinput [1:0] KEY,     // L and clkoutput reg [2:0] LEDR);  // Qalways @(posedge KEY[0])beginif(KEY[1])beginLEDR<=SW;    endelse beginLEDR[0]<=LEDR[2];LEDR[1]<=LEDR[0];LEDR[2]<=LEDR[2]^LEDR[1];endend
endmodule

6.32-bit LFSR

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'h1output reg [31:0] q
); always @(posedge clk)beginif(reset)beginq<=32'h1; endelse beginfor(int i=0;i<32;i++)beginif(i==21|i==1|i==0)beginq[i]<=q[i+1]^q[0];endelse if(i==31)beginq[31]<=1'b0^q[0]; endelse begin q[i]<=q[i+1]; endendendend
endmodule

7.Shift register

Practice:Implement the following circuit:
翻译:实现以下电路

提示:可以看到,每个时钟周期,后一位的输入都来自前一位的输出,所以这是一个左移的移位寄存器(假设out为最高位)

Solution(不唯一,仅供参考):

module top_module (input clk,input resetn,   // synchronous resetinput in,output  out);reg [3:0] temp;assign out = temp[3];always @(posedge clk)beginif(!resetn)begintemp<=0; endelse begintemp<={temp[2:0],in};endend
endmodule

8.Shift register

Practice:Consider the n-bit shift register circuit shown below:

  • Connect the R inputs to the SW switches,
  • clk to KEY[0],
  • E to KEY[1],
  • L to KEY[2], and
  • w to KEY[3].
  • Connect the outputs to the red lights LEDR[3:0].

翻译:考虑如下所示的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]),
);
endmodulemodule MUXDFF (input clk,input w, R, E, L,output Q
);always@(posedge clk)beginQ <= L ? R : (E ? w : Q); endendmodule

9.3-input LUT

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)beginif(enable)beginQ<={Q[6:0],S};endelse beginQ<=Q;endendassign 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、第七题,第九题需要多练练。

继续加油!!!!!

Verilog学习笔记HDLBits——Shift Registers相关推荐

  1. Verilog学习笔记HDLBits——Finite State Machines(1)

    提示:文章写完后,目录可以自动生成,如何生成可参考右边的帮助文档 文章目录 前言 一.Finite State Machines 1.Simple FSM 1(asychronous reset) 2 ...

  2. Verilog学习笔记-——Verilog模块例化

    Verilog学习笔记---Verilog模块例化 在一个模块中引用另一个模块,对其端口进行相关连接,叫做模块例化.模块例化建立了描述的层次.信号端口可以通过位置或名称关联,端口连接也必须遵循一些规则 ...

  3. 【Verilog学习笔记】D触发器(门级和行为级)+4位寄存器+一个完整的激励程序

    [Verilog学习笔记]D触发器(门级和行为级)+4位寄存器+一个完整的激励程序 首先展示以下完整的程序 `timescale 1ns / 1psmodule hardreg( input wire ...

  4. verilog学习笔记之一--(简化)华莱士(Wallace)树形乘法器设计--(原代码出自用芯学项目)

    verilog学习笔记之一–(简化)华莱士(Wallace)树形乘法器设计–(原代码出自用芯学项目) 学习准备1: 树形乘法器原理:参考<数字集成电路-电路.系统与设计(第二版)>–P43 ...

  5. Verilog学习笔记——入门

    Verilog学习笔记 01 基本逻辑门代码设计与仿真 Veriog基本逻辑门代码结构--以一位反相器为例 ModelSim仿真基本流程 02 组合逻辑代码设计与仿真--多路选择器 二选一逻辑--as ...

  6. Verilog学习笔记

    Verilog学习笔记 本文根据学习菜鸟教程下Verilog教程总结得到,主要记载一些硬件语言描述下的骚操作,仅供学习. 归约操作符 归约操作符包括:归约与(&),归约与非( ~ &) ...

  7. Verilog学习笔记(5):Verilog高级程序设计

    文章目录 1.数字电路系统设计的层次化 2.典型电路设计 2.1加法器树乘法器 2.2Wallace树乘法器 2.3复数乘法器 2.4 FIR滤波器设计 2.5 片内存储器的设计 2.6 FIFO设计 ...

  8. verilog学习笔记- 4)Modelsim 软件的安装、使用

    目录 Modelsim 的安装: 安装: Modelsim 的使用: 手动仿真: 建立 TestBench 仿真文件: 编译仿真文件: 配置仿真环境: 自动仿真: 选择 EDA 仿真工具: 编写 Te ...

  9. 【verilog学习】HDLBits:Four Wires

    [HDLBits]Four Wires 1.代码编写 2.提交结果 3.题目分析 1.代码编写 module top_module( input a,b,c,output w,x,y,z );assi ...

最新文章

  1. Google Test(GTest)使用方法和源码解析——死亡测试技术分析和应用
  2. STM32 之十五 奇怪问题处理及驱动库 BUG 汇总(持续更新中)
  3. SQL Server 2008 复习(三)
  4. 通过命令解锁Oracle,在命令行下进行Oracle用户解锁
  5. 给 Android 开发人员的 RxJava 具体解释
  6. mysql 复制 二进制文件命令_Mysql中复制详细解析
  7. CocosCreator2.1.0渲染流程与shader
  8. 动态sql (sql-if,sql-foreach)
  9. 优先级反转实验,使用信号量实现【RT-Thread学习笔记 5】
  10. Commons-Collections4 集合工具类的使用(一):集合操作
  11. 自动化部署工具Fabric简介
  12. 采用通信方式控制台达B2伺服驱动器运行在速度模式
  13. 从T7模型中取训练参数
  14. 每日英语听力 Mac
  15. python 开发微信小游戏_教你快速开发一个微信小游戏好友排行榜
  16. 四、《云原生 | Kubernetes篇》二进制安装部署k8s高可用集群V1.24
  17. 第三方对接-支付宝支付
  18. Win10 曝激活失效问题,专业版突变家庭版;GitHub 项目库破亿
  19. 子组件向父组件传参的几种方法
  20. 深入浅出JS—15 ES6中Proxy及Reflect的使用

热门文章

  1. 2019腾讯广告算法大赛之清洗曝光广告数据集以及构造标签
  2. 计算机等级考试考几级才能成为数据库工程师?
  3. Python抖音弹幕
  4. Golang可视化工具——go-callvis
  5. 大白菜U盘装系统工具,被爆出病毒!
  6. scrapy_redis实现分布式爬取京东图书数据
  7. 机器学习基石(林軒田)笔记之十二
  8. Kafka 2.8.0 学习
  9. flex布局实现无缝滚动
  10. 转载和积累系列 - 为什么 HashMap 加载因子是0.75?而不是0.8,0.6?