国产 无码 综合区,色欲AV无码国产永久播放,无码天堂亚洲国产AV,国产日韩欧美女同一区二区

Verilog學(xué)習(xí)筆記——時序邏輯(shift register移位寄存器)

這篇具有很好參考價值的文章主要介紹了Verilog學(xué)習(xí)筆記——時序邏輯(shift register移位寄存器)。希望對大家有所幫助。如果存在錯誤或未考慮完全的地方,請大家不吝賜教,您也可以點(diǎn)擊"舉報(bào)違法"按鈕提交疑問。

1. 4位移位寄存器??4-bit shift register

4位移位寄存器verilog代碼,學(xué)習(xí),筆記,fpga開發(fā)

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)
                   q<=4'b0;
            else if(load)
                q<=data;
            else if(ena)
                   q<={1'b0,q[3:1]};
            else
                   q<=q;
        end
endmodule
module top_module(
	input clk,
	input areset,
	input load,
	input ena,
	input [3:0] data,
	output reg [3:0] q);
	
	// Asynchronous reset: Notice the sensitivity list.
	// The shift register has four modes:
	//   reset
	//   load
	//   enable shift
	//   idle -- preserve q (i.e., DFFs)
	always @(posedge clk, posedge areset) begin
		if (areset)		// reset
			q <= 0;
		else if (load)	// load
			q <= data;
		else if (ena)	// shift is enabled
			q <= q[3:1];	// Use vector part select to express a shift.
	end
	
endmodule

2.?Left/ right register 左移|右移寄存器(1位)

4位移位寄存器verilog代碼,學(xué)習(xí),筆記,fpga開發(fā)

?文章來源地址http://www.zghlxwxcb.cn/news/detail-769768.html

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)            // load
            q<=data;
        else case(ena)      //  ena
            2'b00: q<=q;
            2'b01:q<={q[0],q[99:1]};  //右移
            2'b10:q<={q[98:0],q[99]}; //左移
            2'b11:q<=q;
            default;
        endcase
    end

endmodule
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)            // load
            q<=data;
        else case(ena)      //  ena
            2'b00: q<=q;
            2'b01:q<={q[0],q[99:1]};  //右移
            2'b10:q<={q[98:0],q[99]}; //左移
            2'b11:q<=q;
            default;
        endcase
    end

endmodule

3.?Left/right arithmetic shift by 1 or 8 算數(shù) 左移|右移寄存器(1 或8位)

4位移位寄存器verilog代碼,學(xué)習(xí),筆記,fpga開發(fā)

4位移位寄存器verilog代碼,學(xué)習(xí),筆記,fpga開發(fā)

4位移位寄存器verilog代碼,學(xué)習(xí),筆記,fpga開發(fā)

4位移位寄存器verilog代碼,學(xué)習(xí),筆記,fpga開發(fā)

module top_module(
    input clk,
    input load,
    input ena,
    input [1:0] amount,
    input [63:0] data,
    output reg [63:0] q); 
    
    //左移:算數(shù)左移==邏輯左移,丟棄高位,低位補(bǔ)0
    //算數(shù)右移:丟棄低位,高位補(bǔ)符號位
    //邏輯右移:丟棄低位,高位補(bǔ)0
    
    always@(posedge clk) begin
        if(load)
            q<=data;
        else if(ena)
            begin
                case(amount)
                    2'b00:q<={q[62:0],1'b0};                //左移,空位補(bǔ)0,丟棄高位,低位補(bǔ)0
                    2'b01:q<={q[55:0],8'b0};                //左移,空位補(bǔ)0,丟棄高位,低位補(bǔ)0
                    2'b10:q<={q[63],q[63:1]};                //算數(shù)右移,空位補(bǔ)最高位符號位
                    2'b11:q<={{8{q[63]}},q[63:8]};           //算術(shù)右移,空位補(bǔ)最高位符號位
                endcase
                
            end
        else q<=q;
    end

endmodule

4.?5-bit LFSR

4位移位寄存器verilog代碼,學(xué)習(xí),筆記,fpga開發(fā)

module top_module(
	input clk,
	input reset,
	output reg [4:0] q);
	
	reg [4:0] q_next;		// q_next is not a register

	// Convenience: Create a combinational block of logic that computes
	// what the next value should be. For shorter code, I first shift
	// all of the values and then override the two bit positions that have taps.
	// A logic synthesizer creates a circuit that behaves as if the code were
	// executed sequentially, so later assignments override earlier ones.
	// Combinational always block: Use blocking assignments.
	always @(*) begin
		q_next = q[4:1];	// Shift all the bits. This is incorrect for q_next[4] and q_next[2]
		q_next[4] = q[0];	// Give q_next[4] and q_next[2] their correct assignments
		q_next[2] = q[3] ^ q[0];
	end
	
	
	// This is just a set of DFFs. I chose to compute the connections between the
	// DFFs above in its own combinational always block, but you can combine them if you wish.
	// You'll get the same circuit either way.
	// Edge-triggered always block: Use non-blocking assignments.
	always @(posedge clk) begin
		if (reset)
			q <= 5'h1;
		else
			q <= q_next;
	end
	
endmodule
module top_module(
    input clk,
    input reset,    // Active-high synchronous reset to 5'h1
    output [4:0] q
); 
    
    always@(posedge clk)begin
        if(reset)   q<=5'b1;
        else  
            q<={0^q[0],q[4],q[3]^q[0],q[2],q[1]};
    end

endmodule

5.?3-bit LFSR

4位移位寄存器verilog代碼,學(xué)習(xí),筆記,fpga開發(fā)

?

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


endmodule


module LFSR(
    input r,
    input L,
    input clk,
    input Q,
    output q);
    always@(posedge clk)
        begin 
            q <= L? r:Q ;
        end
endmodule
module top_module (
	input [2:0] SW,      // R
	input [1:0] KEY,     // L and clk
	output [2:0] LEDR);  // Q
	reg ry;
    assign  ry=LEDR[1]^LEDR[2];
    mode_muxdff u0(KEY[0],KEY[1],SW[0],LEDR[2],LEDR[0]);
    mode_muxdff u1(KEY[0],KEY[1],SW[1],LEDR[0],LEDR[1]);
    mode_muxdff u2(KEY[0],KEY[1],SW[2],ry,LEDR[2]);
endmodule
module mode_muxdff (
	input clk,
	input L,
	input r_in,
	input q_in,
	output reg Q);
	wire D;
    assign D=L? r_in:q_in;
    always @(posedge clk)
        begin
            Q<=D;
        end
endmodule

6.?32-bit LFSR

4位移位寄存器verilog代碼,學(xué)習(xí),筆記,fpga開發(fā)

?

module top_module(
    input clk,
    input reset,    // Active-high synchronous reset to 32'h1
    output [31:0] q
); 
    reg[32:0] q_next;
    
    always@(*) begin
        q_next = q[31:1];
        q_next[31] = 0^q[0];
        q_next[21] = q[22]^q[0];
        q_next[1] = q[2]^q[0];
        q_next[0] = q[1]^q[0];
    end
        
    
    always@(posedge clk) begin
        if(reset)
            q<=32'b1;
        else
            q<=q_next;
    end

endmodule

> module top_module(
    input clk,
    input reset,    // Active-high synchronous reset to 32'h1
    output [31:0] q
); 
    always@(posedge clk)
        begin
            if(!reset)begin
                q[0]<=q[0]^q[1];
                q[1]<=q[0]^q[2];
              	q[20:2]<=q[21:3];
                q[30:22]<=q[31:23];
                q[21]<=q[22]^q[0];
                q[31]<=q[0]^1'b0;
              end
              else
                  q<=32'h1;
        end
endmodule

7.?Shift register

4位移位寄存器verilog代碼,學(xué)習(xí),筆記,fpga開發(fā)

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

	reg [3:0] sr;
	
	// Create a shift register named sr. It shifts in "in".
	always @(posedge clk) begin
		if (~resetn)		// Synchronous active-low reset
			sr <= 0;
		else 
			sr <= {sr[2:0], in};
	end
	
	assign out = sr[3];		// Output the final bit (sr[3])

endmodule
module top_module (
    input clk,
    input resetn,   // synchronous reset
    input in,
    output out);
    reg [2:0] q;
    always@(posedge clk)
        begin
            if(!resetn)
            {out,q}<=4'b0;
            else
            {out,q[2:0]}<={q[2:0],in};
        end
endmodule

8.?Shift register

4位移位寄存器verilog代碼,學(xué)習(xí),筆記,fpga開發(fā)

4位移位寄存器verilog代碼,學(xué)習(xí),筆記,fpga開發(fā)?

module top_module (
    input [3:0] SW,      //R
    input [3:0] KEY,     //0-clk,1-E,2-L,3-w
    output [3:0] LEDR    //out
); //
    MUXDFF u_3(SW[3],KEY[0],KEY[1],KEY[2],KEY[3],LEDR[3]);
    MUXDFF u_2(SW[2],KEY[0],KEY[1],KEY[2],LEDR[3],LEDR[2]);
    MUXDFF u_1(SW[1],KEY[0],KEY[1],KEY[2],LEDR[2],LEDR[1]);
    MUXDFF u_0(SW[0],KEY[0],KEY[1],KEY[2],LEDR[1],LEDR[0]);
    

endmodule

module MUXDFF (
    input R,
    input clk,
    input E,
    input L,
    input w,
    output q
);
    reg w1,d;
    always@(posedge clk)
        begin
           w1 = E?w:q;
            d = L?R:w1;
            q<=d;
        end
endmodule

?9.?3-input LUT

4位移位寄存器verilog代碼,學(xué)習(xí),筆記,fpga開發(fā)

?

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)
                q<={q[6:0],S};
            else
                q<=q;
        end
    always@(*)
        begin
            case({A,B,C})
                3'b0:Z=q[0];
                3'b001:Z=q[1];
                3'b010:Z=q[2];
                3'b011:Z=q[3];
                3'b100:Z=q[4];
                3'b101:Z=q[5];
                3'b110:Z=q[6];
                3'b111:Z=q[7];
            endcase
        end
endmodule
module top_module (
	input clk,
	input enable,
	input S,
	
	input A, B, C,
	output reg Z
);

	reg [7:0] q;
	
	// The final circuit is a shift register attached to a 8-to-1 mux.
	


	// Create a 8-to-1 mux that chooses one of the bits of q based on the three-bit number {A,B,C}:
	// There are many other ways you could write a 8-to-1 mux
	// (e.g., combinational always block -> case statement with 8 cases).
	assign Z = q[ {A, B, C} ];



	// Edge-triggered always block: This is a standard shift register (named q) with enable.
	// When enabled, shift to the left by 1 (discarding q[7] and and shifting in S).
	always @(posedge clk) begin
		if (enable)
			q <= {q[6:0], S};	
	end
	
	
	
endmodule

到了這里,關(guān)于Verilog學(xué)習(xí)筆記——時序邏輯(shift register移位寄存器)的文章就介紹完了。如果您還想了解更多內(nèi)容,請?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!

本文來自互聯(lián)網(wǎng)用戶投稿,該文觀點(diǎn)僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務(wù),不擁有所有權(quán),不承擔(dān)相關(guān)法律責(zé)任。如若轉(zhuǎn)載,請注明出處: 如若內(nèi)容造成侵權(quán)/違法違規(guī)/事實(shí)不符,請點(diǎn)擊違法舉報(bào)進(jìn)行投訴反饋,一經(jīng)查實(shí),立即刪除!

領(lǐng)支付寶紅包贊助服務(wù)器費(fèi)用

相關(guān)文章

  • verilog——移位寄存器

    在Verilog中,你可以使用移位寄存器來實(shí)現(xiàn)數(shù)據(jù)的移位操作。移位寄存器是一種常用的數(shù)字電路,用于將數(shù)據(jù)向左或向右移動一個或多個位置。這在數(shù)字信號處理、通信系統(tǒng)和其他應(yīng)用中非常有用。以下是一個使用Verilog實(shí)現(xiàn)的簡單移位寄存器的示例: module ShiftRegister ( ? inpu

    2024年02月05日
    瀏覽(32)
  • Verilog實(shí)現(xiàn)移位寄存器

    Verilog實(shí)現(xiàn)移位寄存器

    Verilog實(shí)現(xiàn)8位環(huán)形移位寄存器 左移: 環(huán)形就是首尾相連 右移: 普通的移位寄存器用for語句實(shí)現(xiàn): 普通左移: tb測試: 圖形分析: 雙向shift:就是加個判斷

    2024年02月11日
    瀏覽(24)
  • 數(shù)字IC前端學(xué)習(xí)筆記:LSFR(線性反饋移位寄存器)

    數(shù)字IC前端學(xué)習(xí)筆記:LSFR(線性反饋移位寄存器)

    相關(guān)文章 數(shù)字IC前端專欄 https://blog.csdn.net/weixin_45791458/category_12173698.html?spm=1001.2014.3001.5482 引言 LFSR(線性反饋移位寄存器)用于產(chǎn)生可重復(fù)的偽隨機(jī)序列PRBS(Pseudo-Random Binary Sequence),結(jié)構(gòu)包括n級D觸發(fā)器和一些異或門(或同或門)組成,在每個時鐘沿,后級D觸發(fā)器輸出會以

    2024年02月02日
    瀏覽(24)
  • verilog 學(xué)習(xí)筆記 —— 時序邏輯 Sequential Logics (Latches and Flip-Flops 鎖存器和觸發(fā)器)

    verilog 學(xué)習(xí)筆記 —— 時序邏輯 Sequential Logics (Latches and Flip-Flops 鎖存器和觸發(fā)器)

    1.?D flip-flop D觸發(fā)器 2.?D flip-flop? D觸發(fā)器 3.?DFF with reset? 帶復(fù)位的D觸發(fā)器? 4. 帶復(fù)位值的D觸發(fā)器 5. DFF with asynchronous reset 帶異步復(fù)位功能的 D觸發(fā)器 6.?DFF with byte enable? ?帶位啟動的觸發(fā)器 7.?D Latch? D鎖存器 8.?DFF ?9.?DFF ? 10.?DFF+gate ? 11.?Mux and DFF ? 12.?DFFs and gates ? 13

    2024年02月04日
    瀏覽(14)
  • Verilog基礎(chǔ)之十一、移位寄存器實(shí)現(xiàn)

    Verilog基礎(chǔ)之十一、移位寄存器實(shí)現(xiàn)

    目錄 一、前言 二、工程設(shè)計(jì) ?2.1 工程代碼 2.2 綜合結(jié)果 2.3 仿真結(jié)果 ????移位寄存器SRL在工程中屬于使用頻率較高個模塊,可用于存儲數(shù)據(jù),實(shí)現(xiàn)串并轉(zhuǎn)換;根據(jù)數(shù)據(jù)移動方向可分為左移寄存器,右移寄存器,左移是向數(shù)據(jù)高位移動,右移是向數(shù)據(jù)低位移動。? 工程中包

    2024年02月11日
    瀏覽(25)
  • 【Verilog編程】線性反饋移位寄存器(LFSR)原理及Verilog代碼實(shí)現(xiàn)

    【Verilog編程】線性反饋移位寄存器(LFSR)原理及Verilog代碼實(shí)現(xiàn)

    移位寄存器 :指若干個寄存器排成一列,每個寄存器中存放1bit二進(jìn)制數(shù)據(jù)(0或1),每個時鐘周期向左或向右移動一個bit。下圖所示為一個向右移動的移位寄存器。 反饋移位寄存器(Feedback Shift Register,F(xiàn)SR) :每個時鐘脈沖,移位寄存器向右移動一位,則移位寄存器的左左側(cè)就

    2024年02月15日
    瀏覽(21)
  • hdlbits系列verilog解答(8位寬移位寄存器)-24

    這項(xiàng)練習(xí)是module_shift移位寄存器的延伸。模塊端口不是只有單個引腳,我們現(xiàn)在有以向量作為端口的模塊,您將在其上附加線向量而不是普通線網(wǎng)數(shù)據(jù)。與 Verilog 中的其他位置一樣,端口的向量長度不必與連接到它的導(dǎo)線匹配,但這會導(dǎo)致向量的零填充或截?cái)?。本練?xí)不使用

    2024年02月08日
    瀏覽(23)
  • (數(shù)字邏輯筆記)用Verilog實(shí)現(xiàn)4位計(jì)數(shù)器。(時序邏輯)

    (數(shù)字邏輯筆記)用Verilog實(shí)現(xiàn)4位計(jì)數(shù)器。(時序邏輯)

    實(shí)驗(yàn)描述: 輸入: Clock:如果計(jì)數(shù)器enable信號為1,那么在時鐘上升沿,count加1 Enable:如果enable為1,那么在時鐘上升沿,count加1;如果enable為0,count保持不變 Reset:重置信號,如果reset為0,count重置為0 輸出: Count[3:0]:4位計(jì)數(shù)信號,范圍:4‘b0000 – 4’b1111 實(shí)現(xiàn)代碼: Tes

    2024年02月11日
    瀏覽(20)
  • 【FGPA】Verilog:移位寄存器 | 環(huán)形計(jì)數(shù)器 | 4bit移位寄存器的實(shí)現(xiàn) | 4bit環(huán)形計(jì)數(shù)器的實(shí)現(xiàn)

    【FGPA】Verilog:移位寄存器 | 環(huán)形計(jì)數(shù)器 | 4bit移位寄存器的實(shí)現(xiàn) | 4bit環(huán)形計(jì)數(shù)器的實(shí)現(xiàn)

    ? 目錄 Ⅰ. 理論部分 0x00 移位寄存器(Shift Register) 0x01 環(huán)形計(jì)數(shù)器(Ring Counter)

    2024年02月05日
    瀏覽(64)
  • Verilog 實(shí)現(xiàn)偽隨機(jī)數(shù)生成器(線性反饋移位寄存器)

    Verilog 實(shí)現(xiàn)偽隨機(jī)數(shù)生成器(線性反饋移位寄存器)

    參考文獻(xiàn)1 不簡單的進(jìn)行移位,而是在移位的基礎(chǔ)上加上異或門,如題目所示,這就相當(dāng)于每進(jìn)行一次移位,寄存器中的值會發(fā)生改變,一直移動,一直改變,就形成了偽隨機(jī)數(shù)。

    2024年02月09日
    瀏覽(28)

覺得文章有用就打賞一下文章作者

支付寶掃一掃打賞

博客贊助

微信掃一掃打賞

請作者喝杯咖啡吧~博客贊助

支付寶掃一掃領(lǐng)取紅包,優(yōu)惠每天領(lǐng)

二維碼1

領(lǐng)取紅包

二維碼2

領(lǐng)紅包