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
相关推荐
xian_wwq20 小时前
【学习笔记】数据血缘
笔记·学习·数据血缘
日更嵌入式的打工仔21 小时前
实用:嵌入式执行时间测量常用方法
笔记·单片机
map_vis_3d21 小时前
JSAPIThree LODModel 性能优化学习笔记:细节层次模型加载
笔记·学习·3d
im_AMBER1 天前
数据结构 13 图 | 哈希表 | 树
数据结构·笔记·学习·算法·散列表
会思考的猴子1 天前
UE5 笔记敌人自动追踪
笔记·ue5
wdfk_prog1 天前
[Linux]学习笔记系列 -- [fs][drop_caches]
linux·笔记·学习
2021_fc1 天前
Flink笔记
大数据·笔记·flink
UVM_ERROR1 天前
RDMA Scheduler + TX + Completion RTL 开发经验分享
笔记·vscode·ssh·github·芯片
Vizio<1 天前
STM32HAL库开发笔记-GPIO输入
笔记·stm32·单片机·嵌入式硬件
chinalihuanyu1 天前
蓝牙开发笔记(BlueTooth,BLE,CH592)
笔记