blob: f20110e9d7dde63a5fecbd3298a5206d6b37d039 [file] [log] [blame]
agorararmard6c766a82020-12-10 18:13:12 +02001// SPDX-FileCopyrightText: 2020 Efabless Corporation
agorararmarde5780bf2020-12-09 21:27:56 +00002//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
agorararmardafa96ea2020-12-09 23:37:31 +020014// SPDX-License-Identifier: Apache-2.0
agorararmarde5780bf2020-12-09 21:27:56 +000015
Matt Venn08cd6eb2020-11-16 12:01:14 +010016`default_nettype none
Tim Edwardscd64af52020-08-07 11:11:58 -040017// Tunable ring oscillator---synthesizable (physical) version.
18//
19// NOTE: This netlist cannot be simulated correctly due to lack
20// of accurate timing in the digital cell verilog models.
21
22module delay_stage(in, trim, out);
23 input in;
24 input [1:0] trim;
25 output out;
26
Tim Edwards581068f2020-11-19 12:45:25 -050027 wire d0, d1, d2, ts;
Tim Edwardscd64af52020-08-07 11:11:58 -040028
Tim Edwardsef8312e2020-09-22 17:20:06 -040029 sky130_fd_sc_hd__clkbuf_2 delaybuf0 (
Tim Edwardscd64af52020-08-07 11:11:58 -040030 .A(in),
31 .X(ts)
32 );
33
Tim Edwardsef8312e2020-09-22 17:20:06 -040034 sky130_fd_sc_hd__clkbuf_1 delaybuf1 (
Tim Edwardscd64af52020-08-07 11:11:58 -040035 .A(ts),
36 .X(d0)
37 );
38
Tim Edwardsef8312e2020-09-22 17:20:06 -040039 sky130_fd_sc_hd__einvp_2 delayen1 (
Tim Edwardscd64af52020-08-07 11:11:58 -040040 .A(d0),
41 .TE(trim[1]),
42 .Z(d1)
43 );
44
Tim Edwardsef8312e2020-09-22 17:20:06 -040045 sky130_fd_sc_hd__einvn_4 delayenb1 (
Tim Edwardscd64af52020-08-07 11:11:58 -040046 .A(ts),
Tim Edwardsc5265b82020-09-25 17:08:59 -040047 .TE_B(trim[1]),
Tim Edwardscd64af52020-08-07 11:11:58 -040048 .Z(d1)
49 );
50
Tim Edwardsef8312e2020-09-22 17:20:06 -040051 sky130_fd_sc_hd__clkinv_1 delayint0 (
Tim Edwardscd64af52020-08-07 11:11:58 -040052 .A(d1),
53 .Y(d2)
54 );
55
Tim Edwardsef8312e2020-09-22 17:20:06 -040056 sky130_fd_sc_hd__einvp_2 delayen0 (
Tim Edwardscd64af52020-08-07 11:11:58 -040057 .A(d2),
58 .TE(trim[0]),
59 .Z(out)
60 );
61
Tim Edwardsef8312e2020-09-22 17:20:06 -040062 sky130_fd_sc_hd__einvn_8 delayenb0 (
Tim Edwardscd64af52020-08-07 11:11:58 -040063 .A(ts),
Tim Edwardsc5265b82020-09-25 17:08:59 -040064 .TE_B(trim[0]),
Tim Edwardscd64af52020-08-07 11:11:58 -040065 .Z(out)
66 );
67
68endmodule
69
70module start_stage(in, trim, reset, out);
71 input in;
72 input [1:0] trim;
73 input reset;
74 output out;
75
76 wire d0, d1, d2, ctrl0, one;
77
Tim Edwardsef8312e2020-09-22 17:20:06 -040078 sky130_fd_sc_hd__clkbuf_1 delaybuf0 (
Tim Edwardscd64af52020-08-07 11:11:58 -040079 .A(in),
80 .X(d0)
81 );
82
Tim Edwardsef8312e2020-09-22 17:20:06 -040083 sky130_fd_sc_hd__einvp_2 delayen1 (
Tim Edwardscd64af52020-08-07 11:11:58 -040084 .A(d0),
85 .TE(trim[1]),
86 .Z(d1)
87 );
88
Tim Edwardsef8312e2020-09-22 17:20:06 -040089 sky130_fd_sc_hd__einvn_4 delayenb1 (
Tim Edwardscd64af52020-08-07 11:11:58 -040090 .A(in),
Tim Edwardsc5265b82020-09-25 17:08:59 -040091 .TE_B(trim[1]),
Tim Edwardscd64af52020-08-07 11:11:58 -040092 .Z(d1)
93 );
94
Tim Edwardsef8312e2020-09-22 17:20:06 -040095 sky130_fd_sc_hd__clkinv_1 delayint0 (
Tim Edwardscd64af52020-08-07 11:11:58 -040096 .A(d1),
97 .Y(d2)
98 );
99
Tim Edwardsef8312e2020-09-22 17:20:06 -0400100 sky130_fd_sc_hd__einvp_2 delayen0 (
Tim Edwardscd64af52020-08-07 11:11:58 -0400101 .A(d2),
102 .TE(trim[0]),
103 .Z(out)
104 );
105
Tim Edwardsef8312e2020-09-22 17:20:06 -0400106 sky130_fd_sc_hd__einvn_8 delayenb0 (
Tim Edwardscd64af52020-08-07 11:11:58 -0400107 .A(in),
Tim Edwardsc5265b82020-09-25 17:08:59 -0400108 .TE_B(ctrl0),
Tim Edwardscd64af52020-08-07 11:11:58 -0400109 .Z(out)
110 );
111
Tim Edwardsef8312e2020-09-22 17:20:06 -0400112 sky130_fd_sc_hd__einvp_1 reseten0 (
Tim Edwardscd64af52020-08-07 11:11:58 -0400113 .A(one),
114 .TE(reset),
115 .Z(out)
116 );
117
Tim Edwardsef8312e2020-09-22 17:20:06 -0400118 sky130_fd_sc_hd__or2_2 ctrlen0 (
Tim Edwardscd64af52020-08-07 11:11:58 -0400119 .A(reset),
120 .B(trim[0]),
121 .X(ctrl0)
122 );
123
Tim Edwardsef8312e2020-09-22 17:20:06 -0400124 sky130_fd_sc_hd__conb_1 const1 (
Tim Edwardscd64af52020-08-07 11:11:58 -0400125 .HI(one),
126 .LO()
127 );
128
129endmodule
130
131// Ring oscillator with 13 stages, each with two trim bits delay
132// (see above). Trim is not binary: For trim[1:0], lower bit
133// trim[0] is primary trim and must be applied first; upper
134// bit trim[1] is secondary trim and should only be applied
135// after the primary trim is applied, or it has no effect.
136//
137// Total effective number of inverter stages in this oscillator
138// ranges from 13 at trim 0 to 65 at trim 24. The intention is
139// to cover a range greater than 2x so that the midrange can be
140// reached over all PVT conditions.
141//
142// Frequency of this ring oscillator under SPICE simulations at
143// nominal PVT is maximum 214 MHz (trim 0), minimum 90 MHz (trim 24).
144
145module ring_osc2x13(reset, trim, clockp);
146 input reset;
147 input [25:0] trim;
148 output[1:0] clockp;
149
Tim Edwardsbb3cd692020-10-09 22:00:23 -0400150`ifdef FUNCTIONAL // i.e., behavioral model below
151
152 reg [1:0] clockp;
153 reg hiclock;
154 integer i;
155 real delay;
156 wire [5:0] bcount;
157
158 assign bcount = trim[0] + trim[1] + trim[2]
159 + trim[3] + trim[4] + trim[5] + trim[6] + trim[7]
160 + trim[8] + trim[9] + trim[10] + trim[11] + trim[12]
161 + trim[13] + trim[14] + trim[15] + trim[16] + trim[17]
162 + trim[18] + trim[19] + trim[20] + trim[21] + trim[22]
163 + trim[23] + trim[24] + trim[25];
164
165 initial begin
166 hiclock <= 1'b0;
167 delay = 3.0;
168 end
169
170 // Fastest operation is 214 MHz = 4.67ns
171 // Delay per trim is 0.02385
172 // Run "hiclock" at 2x this rate, then use positive and negative
173 // edges to derive the 0 and 90 degree phase clocks.
174
175 always #delay begin
176 hiclock <= (hiclock === 1'b0);
177 end
178
179 always @(trim) begin
180 // Implement trim as a variable delay, one delay per trim bit
181 delay = 1.168 + 0.012 * $itor(bcount);
182 end
183
184 always @(posedge hiclock or posedge reset) begin
185 if (reset == 1'b1) begin
186 clockp[0] <= 1'b0;
187 end else begin
188 clockp[0] <= (clockp[0] === 1'b0);
189 end
190 end
191
192 always @(negedge hiclock or posedge reset) begin
193 if (reset == 1'b1) begin
194 clockp[1] <= 1'b0;
195 end else begin
196 clockp[1] <= (clockp[1] === 1'b0);
197 end
198 end
199
200`else // !FUNCTIONAL; i.e., gate level netlist below
201
Tim Edwardscd64af52020-08-07 11:11:58 -0400202 wire [1:0] clockp;
Tim Edwardsbb3cd692020-10-09 22:00:23 -0400203 wire [12:0] d;
Tim Edwardscd64af52020-08-07 11:11:58 -0400204 wire [1:0] c;
205
206 // Main oscillator loop stages
207
208 genvar i;
209 generate
210 for (i = 0; i < 12; i = i + 1) begin : dstage
211 delay_stage id (
212 .in(d[i]),
213 .trim({trim[i+13], trim[i]}),
214 .out(d[i+1])
215 );
216 end
217 endgenerate
218
219 // Reset/startup stage
220
221 start_stage iss (
222 .in(d[12]),
223 .trim({trim[25], trim[12]}),
224 .reset(reset),
225 .out(d[0])
226 );
227
228 // Buffered outputs a 0 and 90 degrees phase (approximately)
229
Tim Edwardsef8312e2020-09-22 17:20:06 -0400230 sky130_fd_sc_hd__clkinv_2 ibufp00 (
Tim Edwardscd64af52020-08-07 11:11:58 -0400231 .A(d[0]),
232 .Y(c[0])
233 );
Tim Edwardsef8312e2020-09-22 17:20:06 -0400234 sky130_fd_sc_hd__clkinv_8 ibufp01 (
Tim Edwardscd64af52020-08-07 11:11:58 -0400235 .A(c[0]),
236 .Y(clockp[0])
237 );
Tim Edwardsef8312e2020-09-22 17:20:06 -0400238 sky130_fd_sc_hd__clkinv_2 ibufp10 (
Tim Edwardscd64af52020-08-07 11:11:58 -0400239 .A(d[6]),
240 .Y(c[1])
241 );
Tim Edwardsef8312e2020-09-22 17:20:06 -0400242 sky130_fd_sc_hd__clkinv_8 ibufp11 (
Tim Edwardscd64af52020-08-07 11:11:58 -0400243 .A(c[1]),
244 .Y(clockp[1])
245 );
246
Tim Edwardsbb3cd692020-10-09 22:00:23 -0400247`endif // !FUNCTIONAL
248
Tim Edwardscd64af52020-08-07 11:11:58 -0400249endmodule
Tim Edwards581068f2020-11-19 12:45:25 -0500250`default_nettype wire