Circuits--Sequential--Registers_2

  1. 3-bit LFSR

    module top_module (
    input [2:0] SW, // R
    input [1:0] KEY, // L and clk
    output [2:0] LEDR); // Q

    复制代码
     wire clk = KEY[0];
     always @(posedge clk)
         begin
             case(KEY[1])
                 1'b0:	
                     begin
                         LEDR[0]<=LEDR[2];
                         LEDR[1]<=LEDR[0];
                         LEDR[2]<=LEDR[1]^LEDR[2];
                     end
                 1'b1:	
                     begin
                         LEDR[0]<=SW[0];
                         LEDR[1]<=SW[1];
                         LEDR[2]<=SW[2];
                     end
             endcase
         end

    endmodule

  2. 32-bit LFSR

    module top_module(
    input clk,
    input reset, // Active-high synchronous reset to 32'h1
    output [31:0] q
    );

    复制代码
     integer i;
     always@(posedge clk)
         begin
             if(reset)
                 q<=32'h1;
             else
                 begin
                     for(i=0;i<32;i++)
                         begin
                             if(i==0||i==1||i==21) 
                                 q[i]<=q[i+1]^q[0];
                             else if(i==31)
                                 q[31]<=q[0]^1'b0;
                             else
                                 q[i]<=q[i+1];
                         end
                     
                 end
             
         end

    endmodule

3.shift register

复制代码
module top_module (
    input clk,
    input resetn,   // synchronous reset
    input in,
    output out);
    
    reg [3:0] q;
    
    assign out = q[3];
    always@(posedge clk)
        begin
            if(!resetn)
                q<=0;
            else
                begin                 
                    q<={q[2:0],in};                       
                end
        end
endmodule
相关推荐
_落纸21 小时前
三大基础无源电子元件——电阻(R)、电感(L)、电容(C)
笔记
Alice-YUE21 小时前
【CSS学习笔记3】css特性
前端·css·笔记·html
2303_Alpha21 小时前
SpringBoot
笔记·学习
风_峰1 天前
Ubuntu Linux SD卡分区操作
嵌入式硬件·ubuntu·fpga开发
FPGA_Linuxer1 天前
FPGA 40 DAC线缆和光模块带光纤实现40G UDP差异
网络协议·fpga开发·udp
Hello_Embed1 天前
STM32HAL 快速入门(二十):UART 中断改进 —— 环形缓冲区解决数据丢失
笔记·stm32·单片机·学习·嵌入式软件
咸甜适中1 天前
rust语言 (1.88) 学习笔记:客户端和服务器端同在一个项目中
笔记·学习·rust
Grassto1 天前
RAG 从入门到放弃?丐版 demo 实战笔记(go+python)
笔记
Magnetic_h1 天前
【iOS】设计模式复习
笔记·学习·ios·设计模式·objective-c·cocoa
周周记笔记1 天前
学习笔记:第一个Python程序
笔记·学习