Circuits--Sequential Logic--Shift Registers--Exams/m2014 q4k

news/2024/6/3 7:30:28 标签: fpga, verilog

网址:https://hdlbits.01xz.net/wiki/Exams/m2014_q4k
自己写:

module top_module (
    input clk,
    input resetn,   // synchronous reset
    input in,
    output out);
    
    reg 	r_in1;
    reg		r_in2;
    reg		r_in3;

    always@(posedge clk)begin
        if(resetn == 1'b0)
            begin                
            	r_in1 <= 1'b0;
            	r_in2 <= 1'b0;                
            	r_in3 <= 1'b0;                
            end    
        else 
            begin                
            	r_in1 <= in;
            	r_in2 <= r_in1;                
            	r_in3 <= r_in2;   
                out <= r_in3;
            end 
    end
 
endmodule

第二种方法:

module top_module (
    input clk,
    input resetn,   // synchronous reset
    input in,
    output out);
    

    reg [3:1] q;
    
    always @ (posedge clk)
        begin
            if (~resetn)
            {q,out} <= 4'b0;
           else
               begin
                   q[3] <= in;
                   q[2] <= q[3];
                   q[1] <= q[2];
                   out <= q[1];   
                   //{q,out} <= {in, q};
               end         
        end

    
endmodule


http://www.niftyadmin.cn/n/948294.html

相关文章

Circuits--Sequential Logic--Shift Registers--Lfsr32

网址:https://hdlbits.01xz.net/wiki/Lfsr32 module top_module(input clk,input reset, // Active-high synchronous reset to 32h1output [31:0] q ); reg [31:0] q_next;always @ (

Circuits--Sequential Logic--Shift Refisters--Lfsr5

网址&#xff1a;https://hdlbits.01xz.net/wiki/Lfsr5 module top_module(input clk,input reset, // Active-high synchronous reset to 5h1output [4:0] q ); always(posedge clk)beginif(reset 1b1)q < 5h1;else beginq[4] < 1b0 ^ q[0];q[3] < q[4];q[2] &l…

Circuits--Sequential Logic--Shift Registers--Shift18

网址&#xff1a;https://hdlbits.01xz.net/wiki/Shift18 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 1b1)q < data;else if(ena 1b1)begincase(amount)2b00: q &l…

Circuits--Sequential Logic--Counters--Countbcd

网址&#xff1a;https://hdlbits.01xz.net/wiki/Countbcd module bcdcount ( input clk,input reset,input ena,output reg [3:0] q );always (posedge clk)beginif (reset 1b1)q < 4b0;else if (ena 1b1)beginif (q 4h9)q < 4b0;elseq < q 1b1 ; endend endmo…

Circuits--Sequential Logic--Shift Registers--Rotate 100

网址&#xff1a;https://hdlbits.01xz.net/wiki/Rotate100 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 1b1)q < data;else begincase(ena)2b01: q < {q[0],q[99:1]};2b10: q …

Circuits--Swquential Logic--Shift Registers--Shift4

网址&#xff1a;https://hdlbits.01xz.net/wiki/Shift4 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 1b1)q < 4d…

Circuits--Sequential Logic--Finite State Machines--Fsm onehot

网址&#xff1a;https://hdlbits.01xz.net/wiki/Fsm_onehot module top_module(input in,input [9:0] state,output [9:0] next_state,output out1,output out2);parameter S0 0, S1 1, S2 2, S3 3, S4 4,S5 5, S6 6, S7 7, S8 8, S9 9;assign next_state[S0] (stat…

Circuits--Sequential Logic--Counters--Count clock

网址:https://hdlbits.01xz.net/wiki/Count_clock 自己写: module top_module(input clk,input reset,input ena,output pm,output [7:0] hh,output [7:0] mm,output [7