xilinx verilog語法技巧

  • 2019 年 10 月 29 日
  • 筆記

xilinx verilog語法技巧 一

硬體描述語言(HDL)編碼技術讓您: •描述數字邏輯電路中最常見的功能。 •充分利用Xilinx®器件的架構特性。

1 Flip-Flops and Registers :

Vivado綜合根據HDL程式碼的編寫方式推斷出四種類型的暫存器原語: •FDCE:具有時鐘使能和非同步清除的D觸發器 •FDPE:具有時鐘使能和非同步預設的D觸發器 •FDSE:具有時鐘使能和同步設置的D觸發器 •FDRE:具有時鐘使能和同步複位的D觸發器 Register with Rising-Edge Coding Example (Verilog)

// 8-bit Register with  // Rising-edge Clock  // Active-high Synchronous Clear  // Active-high Clock Enable  // File: registers_1.v    module registers_1(d_in,ce,clk,clr,dout);  input [7:0] d_in;  input ce;  input clk;  input clr;  output [7:0] dout;  reg [7:0] d_reg;    always @ (posedge clk)  begin   if(clr)    d_reg <= 8'b0;   else if(ce)    d_reg <= d_in;  end    assign dout = d_reg;  endmodule  

2 Latches

// Latch with Positive Gate and Asynchronous Reset  // File: latches.v  module latches (  input G, input D, input CLR, output reg Q );  always @ *  begin  if(CLR) Q = 0; else if(G) Q = D;  end  endmodule  

3 Shift Registers

移位暫存器是一系列觸發器,允許跨固定(靜態)數量的延遲級傳播數據。 相反,在動態移位暫存器中,傳播鏈的長度在電路操作期間動態變化。 Vivado綜合在SRL類資源上實現了推斷的移位暫存器,例如: •SRL16E •SRLC32E 8-Bit Shift Register Coding Example One (Verilog)

// 8-bit Shift Register  // Rising edge clock  // Active high clock enable  // Concatenation-based template  // File: shift_registers_0.v  module shift_registers_0 (clk, clken, SI, SO);  parameter WIDTH = 32;  input clk, clken, SI;  output SO;  reg [WIDTH-1:0] shreg;  always @(posedge clk)  begin if (clken) shreg <= {shreg[WIDTH-2:0], SI}; end  assign SO = shreg[WIDTH-1];  endmodule  

32-Bit Shift Register Coding Example Two (Verilog)

// 32-bit Shift Register  // Rising edge clock  // Active high clock enable  // For-loop based template  // File: shift_registers_1.v  module shift_registers_1 (clk, clken, SI, SO);  parameter WIDTH = 32;  input clk, clken, SI;  output SO;  reg [WIDTH-1:0] shreg;  integer i;  always @(posedge clk)  begin  if (clken) begin for (i = 0; i < WIDTH-1; i = i+1) shreg[i+1] <= shreg[i]; shreg[0] <= SI; end  end  assign SO = shreg[WIDTH-1];  endmodule  

Dynamic Shift Registers 動態移位暫存器是移位暫存器,其長度可在電路操作期間動態變化。 動態移位暫存器可以看作: •一系列觸發器,它們在電路工作期間可以接受的最大長度。 •多路復用器,在給定的時鐘周期內選擇從傳播鏈中提取數據的階段。

32-Bit Dynamic Shift Registers Coding Example (Verilog)

// 32-bit dynamic shift register.  // Download:  // File: dynamic_shift_registers_1.v  module dynamic_shift_register_1 (CLK, CE, SEL, SI, DO);  parameter SELWIDTH = 5;  input CLK, CE, SI;  input [SELWIDTH-1:0] SEL;  output DO;  localparam DATAWIDTH = 2**SELWIDTH;  reg [DATAWIDTH-1:0] data;  assign DO = data[SEL];  always @(posedge CLK)  begin if (CE == 1'b1) data <= {data[DATAWIDTH-2:0], SI}; end  endmodule

verilog常用語法一讓您的FPGA設計更輕鬆

verilog常用語法二讓您的FPGA設計更輕鬆

verilog常用語法三讓您的FPGA設計更輕鬆

xilinx verilog 語法技巧–綜合屬性