blob: b8dd69e9a7031c32b167521942879510c97287ef [file] [log] [blame]
Steve Kelly3ab5f032020-12-18 18:35:23 -05001// SPDX-FileCopyrightText: 2020 Efabless Corporation
2//
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.
14// SPDX-License-Identifier: Apache-2.0
15
Matt Venn08cd6eb2020-11-16 12:01:14 +010016`default_nettype none
Tim Edwardscd64af52020-08-07 11:11:58 -040017// Digital PLL (ring oscillator + controller)
18// Technically this is a frequency locked loop, not a phase locked loop.
19
20`include "digital_pll_controller.v"
21`include "ring_osc2x13.v"
22
shalanfd13eb52020-08-21 16:48:07 +020023module digital_pll(
Manar61dce922020-11-10 19:26:28 +020024`ifdef USE_POWER_PINS
manarabdelatya115bdd2020-12-01 11:19:12 +020025 VPWR,
26 VGND,
shalanfd13eb52020-08-21 16:48:07 +020027`endif
Tim Edwards3245e2f2020-10-10 14:02:11 -040028 resetb, enable, osc, clockp, div, dco, ext_trim);
shalanfd13eb52020-08-21 16:48:07 +020029
Manar61dce922020-11-10 19:26:28 +020030`ifdef USE_POWER_PINS
manarabdelatya115bdd2020-12-01 11:19:12 +020031 input VPWR;
32 input VGND;
shalanfd13eb52020-08-21 16:48:07 +020033`endif
Tim Edwardscd64af52020-08-07 11:11:58 -040034
Tim Edwards3245e2f2020-10-10 14:02:11 -040035 input resetb; // Sense negative reset
36 input enable; // Enable PLL
37 input osc; // Input oscillator to match
38 input [4:0] div; // PLL feedback division ratio
39 input dco; // Run in DCO mode
Tim Edwardscd64af52020-08-07 11:11:58 -040040 input [25:0] ext_trim; // External trim for DCO mode
41
Tim Edwardscd64af52020-08-07 11:11:58 -040042 output [1:0] clockp; // Two 90 degree clock phases
Tim Edwardscd64af52020-08-07 11:11:58 -040043
Tim Edwards3245e2f2020-10-10 14:02:11 -040044 wire [25:0] itrim; // Internally generated trim bits
45 wire [25:0] otrim; // Trim bits applied to the ring oscillator
46 wire creset; // Controller reset
47 wire ireset; // Internal reset (external reset OR disable)
Tim Edwardscd64af52020-08-07 11:11:58 -040048
Tim Edwards3245e2f2020-10-10 14:02:11 -040049 assign ireset = ~resetb | ~enable;
Tim Edwardscd64af52020-08-07 11:11:58 -040050
51 // In DCO mode: Hold controller in reset and apply external trim value
Tim Edwards3245e2f2020-10-10 14:02:11 -040052
Tim Edwardscd64af52020-08-07 11:11:58 -040053 assign itrim = (dco == 1'b0) ? otrim : ext_trim;
54 assign creset = (dco == 1'b0) ? ireset : 1'b1;
55
56 ring_osc2x13 ringosc (
Tim Edwards04ba17f2020-10-02 22:27:50 -040057 .reset(ireset),
58 .trim(itrim),
59 .clockp(clockp)
Tim Edwardscd64af52020-08-07 11:11:58 -040060 );
61
62 digital_pll_controller pll_control (
Tim Edwards04ba17f2020-10-02 22:27:50 -040063 .reset(creset),
64 .clock(clockp[0]),
65 .osc(osc),
66 .div(div),
67 .trim(otrim)
Tim Edwardscd64af52020-08-07 11:11:58 -040068 );
69
Tim Edwardscd64af52020-08-07 11:11:58 -040070endmodule
Tim Edwards581068f2020-11-19 12:45:25 -050071`default_nettype wire