blob: 9bf6252bbfd8bf725d22d46f7bba23fdf5789b8e [file] [log] [blame]
Tim Edwardscd64af52020-08-07 11:11:58 -04001// Tunable ring oscillator---synthesizable (physical) version.
2//
3// NOTE: This netlist cannot be simulated correctly due to lack
4// of accurate timing in the digital cell verilog models.
5
6module delay_stage(in, trim, out);
7 input in;
8 input [1:0] trim;
9 output out;
10
11 wire d0, d1, d2;
12
Tim Edwardsef8312e2020-09-22 17:20:06 -040013 sky130_fd_sc_hd__clkbuf_2 delaybuf0 (
Tim Edwardscd64af52020-08-07 11:11:58 -040014 .A(in),
15 .X(ts)
16 );
17
Tim Edwardsef8312e2020-09-22 17:20:06 -040018 sky130_fd_sc_hd__clkbuf_1 delaybuf1 (
Tim Edwardscd64af52020-08-07 11:11:58 -040019 .A(ts),
20 .X(d0)
21 );
22
Tim Edwardsef8312e2020-09-22 17:20:06 -040023 sky130_fd_sc_hd__einvp_2 delayen1 (
Tim Edwardscd64af52020-08-07 11:11:58 -040024 .A(d0),
25 .TE(trim[1]),
26 .Z(d1)
27 );
28
Tim Edwardsef8312e2020-09-22 17:20:06 -040029 sky130_fd_sc_hd__einvn_4 delayenb1 (
Tim Edwardscd64af52020-08-07 11:11:58 -040030 .A(ts),
Tim Edwardsc5265b82020-09-25 17:08:59 -040031 .TE_B(trim[1]),
Tim Edwardscd64af52020-08-07 11:11:58 -040032 .Z(d1)
33 );
34
Tim Edwardsef8312e2020-09-22 17:20:06 -040035 sky130_fd_sc_hd__clkinv_1 delayint0 (
Tim Edwardscd64af52020-08-07 11:11:58 -040036 .A(d1),
37 .Y(d2)
38 );
39
Tim Edwardsef8312e2020-09-22 17:20:06 -040040 sky130_fd_sc_hd__einvp_2 delayen0 (
Tim Edwardscd64af52020-08-07 11:11:58 -040041 .A(d2),
42 .TE(trim[0]),
43 .Z(out)
44 );
45
Tim Edwardsef8312e2020-09-22 17:20:06 -040046 sky130_fd_sc_hd__einvn_8 delayenb0 (
Tim Edwardscd64af52020-08-07 11:11:58 -040047 .A(ts),
Tim Edwardsc5265b82020-09-25 17:08:59 -040048 .TE_B(trim[0]),
Tim Edwardscd64af52020-08-07 11:11:58 -040049 .Z(out)
50 );
51
52endmodule
53
54module start_stage(in, trim, reset, out);
55 input in;
56 input [1:0] trim;
57 input reset;
58 output out;
59
60 wire d0, d1, d2, ctrl0, one;
61
Tim Edwardsef8312e2020-09-22 17:20:06 -040062 sky130_fd_sc_hd__clkbuf_1 delaybuf0 (
Tim Edwardscd64af52020-08-07 11:11:58 -040063 .A(in),
64 .X(d0)
65 );
66
Tim Edwardsef8312e2020-09-22 17:20:06 -040067 sky130_fd_sc_hd__einvp_2 delayen1 (
Tim Edwardscd64af52020-08-07 11:11:58 -040068 .A(d0),
69 .TE(trim[1]),
70 .Z(d1)
71 );
72
Tim Edwardsef8312e2020-09-22 17:20:06 -040073 sky130_fd_sc_hd__einvn_4 delayenb1 (
Tim Edwardscd64af52020-08-07 11:11:58 -040074 .A(in),
Tim Edwardsc5265b82020-09-25 17:08:59 -040075 .TE_B(trim[1]),
Tim Edwardscd64af52020-08-07 11:11:58 -040076 .Z(d1)
77 );
78
Tim Edwardsef8312e2020-09-22 17:20:06 -040079 sky130_fd_sc_hd__clkinv_1 delayint0 (
Tim Edwardscd64af52020-08-07 11:11:58 -040080 .A(d1),
81 .Y(d2)
82 );
83
Tim Edwardsef8312e2020-09-22 17:20:06 -040084 sky130_fd_sc_hd__einvp_2 delayen0 (
Tim Edwardscd64af52020-08-07 11:11:58 -040085 .A(d2),
86 .TE(trim[0]),
87 .Z(out)
88 );
89
Tim Edwardsef8312e2020-09-22 17:20:06 -040090 sky130_fd_sc_hd__einvn_8 delayenb0 (
Tim Edwardscd64af52020-08-07 11:11:58 -040091 .A(in),
Tim Edwardsc5265b82020-09-25 17:08:59 -040092 .TE_B(ctrl0),
Tim Edwardscd64af52020-08-07 11:11:58 -040093 .Z(out)
94 );
95
Tim Edwardsef8312e2020-09-22 17:20:06 -040096 sky130_fd_sc_hd__einvp_1 reseten0 (
Tim Edwardscd64af52020-08-07 11:11:58 -040097 .A(one),
98 .TE(reset),
99 .Z(out)
100 );
101
Tim Edwardsef8312e2020-09-22 17:20:06 -0400102 sky130_fd_sc_hd__or2_2 ctrlen0 (
Tim Edwardscd64af52020-08-07 11:11:58 -0400103 .A(reset),
104 .B(trim[0]),
105 .X(ctrl0)
106 );
107
Tim Edwardsef8312e2020-09-22 17:20:06 -0400108 sky130_fd_sc_hd__conb_1 const1 (
Tim Edwardscd64af52020-08-07 11:11:58 -0400109 .HI(one),
110 .LO()
111 );
112
113endmodule
114
115// Ring oscillator with 13 stages, each with two trim bits delay
116// (see above). Trim is not binary: For trim[1:0], lower bit
117// trim[0] is primary trim and must be applied first; upper
118// bit trim[1] is secondary trim and should only be applied
119// after the primary trim is applied, or it has no effect.
120//
121// Total effective number of inverter stages in this oscillator
122// ranges from 13 at trim 0 to 65 at trim 24. The intention is
123// to cover a range greater than 2x so that the midrange can be
124// reached over all PVT conditions.
125//
126// Frequency of this ring oscillator under SPICE simulations at
127// nominal PVT is maximum 214 MHz (trim 0), minimum 90 MHz (trim 24).
128
129module ring_osc2x13(reset, trim, clockp);
130 input reset;
131 input [25:0] trim;
132 output[1:0] clockp;
133
Tim Edwardsbb3cd692020-10-09 22:00:23 -0400134`ifdef FUNCTIONAL // i.e., behavioral model below
135
136 reg [1:0] clockp;
137 reg hiclock;
138 integer i;
139 real delay;
140 wire [5:0] bcount;
141
142 assign bcount = trim[0] + trim[1] + trim[2]
143 + trim[3] + trim[4] + trim[5] + trim[6] + trim[7]
144 + trim[8] + trim[9] + trim[10] + trim[11] + trim[12]
145 + trim[13] + trim[14] + trim[15] + trim[16] + trim[17]
146 + trim[18] + trim[19] + trim[20] + trim[21] + trim[22]
147 + trim[23] + trim[24] + trim[25];
148
149 initial begin
150 hiclock <= 1'b0;
151 delay = 3.0;
152 end
153
154 // Fastest operation is 214 MHz = 4.67ns
155 // Delay per trim is 0.02385
156 // Run "hiclock" at 2x this rate, then use positive and negative
157 // edges to derive the 0 and 90 degree phase clocks.
158
159 always #delay begin
160 hiclock <= (hiclock === 1'b0);
161 end
162
163 always @(trim) begin
164 // Implement trim as a variable delay, one delay per trim bit
165 delay = 1.168 + 0.012 * $itor(bcount);
166 end
167
168 always @(posedge hiclock or posedge reset) begin
169 if (reset == 1'b1) begin
170 clockp[0] <= 1'b0;
171 end else begin
172 clockp[0] <= (clockp[0] === 1'b0);
173 end
174 end
175
176 always @(negedge hiclock or posedge reset) begin
177 if (reset == 1'b1) begin
178 clockp[1] <= 1'b0;
179 end else begin
180 clockp[1] <= (clockp[1] === 1'b0);
181 end
182 end
183
184`else // !FUNCTIONAL; i.e., gate level netlist below
185
Tim Edwardscd64af52020-08-07 11:11:58 -0400186 wire [1:0] clockp;
Tim Edwardsbb3cd692020-10-09 22:00:23 -0400187 wire [12:0] d;
Tim Edwardscd64af52020-08-07 11:11:58 -0400188 wire [1:0] c;
189
190 // Main oscillator loop stages
191
192 genvar i;
193 generate
194 for (i = 0; i < 12; i = i + 1) begin : dstage
195 delay_stage id (
196 .in(d[i]),
197 .trim({trim[i+13], trim[i]}),
198 .out(d[i+1])
199 );
200 end
201 endgenerate
202
203 // Reset/startup stage
204
205 start_stage iss (
206 .in(d[12]),
207 .trim({trim[25], trim[12]}),
208 .reset(reset),
209 .out(d[0])
210 );
211
212 // Buffered outputs a 0 and 90 degrees phase (approximately)
213
Tim Edwardsef8312e2020-09-22 17:20:06 -0400214 sky130_fd_sc_hd__clkinv_2 ibufp00 (
Tim Edwardscd64af52020-08-07 11:11:58 -0400215 .A(d[0]),
216 .Y(c[0])
217 );
Tim Edwardsef8312e2020-09-22 17:20:06 -0400218 sky130_fd_sc_hd__clkinv_8 ibufp01 (
Tim Edwardscd64af52020-08-07 11:11:58 -0400219 .A(c[0]),
220 .Y(clockp[0])
221 );
Tim Edwardsef8312e2020-09-22 17:20:06 -0400222 sky130_fd_sc_hd__clkinv_2 ibufp10 (
Tim Edwardscd64af52020-08-07 11:11:58 -0400223 .A(d[6]),
224 .Y(c[1])
225 );
Tim Edwardsef8312e2020-09-22 17:20:06 -0400226 sky130_fd_sc_hd__clkinv_8 ibufp11 (
Tim Edwardscd64af52020-08-07 11:11:58 -0400227 .A(c[1]),
228 .Y(clockp[1])
229 );
230
Tim Edwardsbb3cd692020-10-09 22:00:23 -0400231`endif // !FUNCTIONAL
232
Tim Edwardscd64af52020-08-07 11:11:58 -0400233endmodule