[文檔].艾米電子 – 移位寄存器,Verilog

來源:互聯網
上載者:User
文章目錄
  • free-running移位寄存器
  • Universa shift register
對讀者的假設

已經掌握:

  • 可程式化邏輯基礎
  • Verilog HDL基礎
  • 使用Verilog設計的Quartus II入門指南
  • 使用Verilog設計的ModelSIm入門指南
內容free-running移位寄存器

自由運行移位寄存器,即在每一個刻度內,寄存器的內容會被左移或右移一位。該寄存器沒有其他的控制訊號。

代碼1 free-running移位寄存器

module free_run_shift_reg#(parameter N=8)(  // global clock and asyn reset  input clk,  input rst_n,  // serial I/O interface  input s_in,  output s_out );// signal declarationreg [N-1:0] r_reg;wire [N-1:0] r_next;// body// registeralways@(posedge clk, negedge rst_n)  if(!rst_n)    r_reg <= 0;  else    r_reg <= r_next;// next-state logicassign r_next = {s_in, r_reg[N-1:1]};// output logicassign s_out = r_reg[0];endmodule

 

次態(next-state)邏輯是一位移位器,作用是將r_reg右移一個位置,然後在最高位(MSB)插入串型輸入s_in。由於1位移位器僅需要重新串連輸入和輸出訊號,因此不需要任何實際的邏輯電路。

Universa shift register

通用移位寄存器可以載入並行資料,然後左移或者右移,抑或保持原有狀態。它可實現並串操作(先載入並行輸入,然後移位輸出),或者串並轉換(先移位輸入,然後一併輸出)。

代碼2 萬用移位寄存器

module univ_shift_reg#(parameter N=8)(  // global clk and asyn reset  input clk,  input rst_n,  // serial I/O interface  input [1:0] ctrl,  input [N-1:0] d,  output [N-1:0] q  );  // signal declarationreg [N-1:0] r_reg, r_next;// body// registeralways@(posedge clk, negedge rst_n)  if(!rst_n)    r_reg <= 0;  else    r_reg <= r_next;// next-state logicalways@*  case(ctrl)    2'b00: r_next = r_reg;                 // no operation    2'b01: r_next = {r_reg[N-2:0], d[0]};  // shift left    2'b10: r_next = {d[N-1], r_reg[N-1:1]};// shift right    defaut: r_next = d;  endcase  // output logicassign q = r_reg;endmodule

次態邏輯使用了一個4選1的多路選取器來選擇寄存器所需的次態值。注意:d的最低位和最高位(d[0]和d[N-1)被用作左移操作和右移操作的串型輸入。

參考

1 Pong P. Chu.FPGA Prototyping By Verilog Examples: Xilinx Spartan-3 Version.Wiley

另見

[與艾米一起學FPGA/SOPC].[邏輯實驗文檔連載計劃]

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.