利用FPGA的lut实现Ring Oscillator - minichao9901/TangNano-20k-Zynq-7020 GitHub Wiki

例程

RO.rar

verilog代码

  • 31级RO
  • 直接例化lut构成反相器
  • 关键是要加约束,避免逻辑优化掉
module ro_n_v2 #(
    parameter N=31
)
(
    input en,
    output out,
    input clk
    );
    
(* DONT_TOUCH="TRUE"*)    wire [N-1:0] net;

  genvar i;
  generate
    for(i=1; i<N-1; i=i+1) begin
        (* keep_hierarchy="yes" *) LUT1 #(
          .INIT(2'b01)  // Specify LUT Contents
       ) LUT1_inst (
          .O(net[i+1]),   // LUT general output
          .I0(net[i])  // LUT input
       );        
    end
  endgenerate
    
  (* keep_hierarchy="yes" *)  LUT1 #(
      .INIT(2'b01)  // Specify LUT Contents
   ) LUT1_inst1 (
      .O(net[1]),   // LUT general output
      .I0(netx)  // LUT input
   );  
   
  (* keep_hierarchy="yes" *)  LUT1 #(
      .INIT(2'b01)  // Specify LUT Contents
   ) LUT1_inst2 (
      .O(net[0]),   // LUT general output
      .I0(net[N-1])  // LUT input
   );      

   assign netx=net[0] && en;   
   assign out=net[1];        


ila_0 your_instance_name (
	.clk(clk), // input wire clk


	.probe0(net) // input wire [30:0] probe0
);
    
endmodule

约束问题

set_property -dict {PACKAGE_PIN T14 IOSTANDARD LVCMOS33} [get_ports en]
set_property -dict {PACKAGE_PIN T15 IOSTANDARD LVCMOS33} [get_ports out]

set_property -dict {PACKAGE_PIN U18 IOSTANDARD LVCMOS33} [get_ports clk]
create_clock -period 20.000 -name clk [get_ports clk]

set_property ALLOW_COMBINATORIAL_LOOPS TRUE [get_nets *]

综合结果

image

RO用了32个lut

波形

image

ILA采样到的波形是忽快忽慢的,因为ILA的时钟才50MHz,去采样44MHz的东西,肯定是不行的。

image

逻辑分析仪采样到的时钟是稳定的,44MHz。符合理论预期。

补充说明

  • 3级和5级不能起振
  • 去掉ILA后,31级频率55MHz左右,15级频率125MHz左右