Steve Kelly | 3ab5f03 | 2020-12-18 18:35:23 -0500 | [diff] [blame] | 1 | // 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 Venn | 08cd6eb | 2020-11-16 12:01:14 +0100 | [diff] [blame] | 16 | `default_nettype none |
Tim Edwards | cd64af5 | 2020-08-07 11:11:58 -0400 | [diff] [blame] | 17 | // 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 | |
shalan | fd13eb5 | 2020-08-21 16:48:07 +0200 | [diff] [blame] | 23 | module digital_pll( |
Manar | 61dce92 | 2020-11-10 19:26:28 +0200 | [diff] [blame] | 24 | `ifdef USE_POWER_PINS |
manarabdelaty | a115bdd | 2020-12-01 11:19:12 +0200 | [diff] [blame] | 25 | VPWR, |
| 26 | VGND, |
shalan | fd13eb5 | 2020-08-21 16:48:07 +0200 | [diff] [blame] | 27 | `endif |
Tim Edwards | 3245e2f | 2020-10-10 14:02:11 -0400 | [diff] [blame] | 28 | resetb, enable, osc, clockp, div, dco, ext_trim); |
shalan | fd13eb5 | 2020-08-21 16:48:07 +0200 | [diff] [blame] | 29 | |
Manar | 61dce92 | 2020-11-10 19:26:28 +0200 | [diff] [blame] | 30 | `ifdef USE_POWER_PINS |
manarabdelaty | a115bdd | 2020-12-01 11:19:12 +0200 | [diff] [blame] | 31 | input VPWR; |
| 32 | input VGND; |
shalan | fd13eb5 | 2020-08-21 16:48:07 +0200 | [diff] [blame] | 33 | `endif |
Tim Edwards | cd64af5 | 2020-08-07 11:11:58 -0400 | [diff] [blame] | 34 | |
Tim Edwards | 3245e2f | 2020-10-10 14:02:11 -0400 | [diff] [blame] | 35 | 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 Edwards | cd64af5 | 2020-08-07 11:11:58 -0400 | [diff] [blame] | 40 | input [25:0] ext_trim; // External trim for DCO mode |
| 41 | |
Tim Edwards | cd64af5 | 2020-08-07 11:11:58 -0400 | [diff] [blame] | 42 | output [1:0] clockp; // Two 90 degree clock phases |
Tim Edwards | cd64af5 | 2020-08-07 11:11:58 -0400 | [diff] [blame] | 43 | |
Tim Edwards | 3245e2f | 2020-10-10 14:02:11 -0400 | [diff] [blame] | 44 | 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 Edwards | cd64af5 | 2020-08-07 11:11:58 -0400 | [diff] [blame] | 48 | |
Tim Edwards | 3245e2f | 2020-10-10 14:02:11 -0400 | [diff] [blame] | 49 | assign ireset = ~resetb | ~enable; |
Tim Edwards | cd64af5 | 2020-08-07 11:11:58 -0400 | [diff] [blame] | 50 | |
| 51 | // In DCO mode: Hold controller in reset and apply external trim value |
Tim Edwards | 3245e2f | 2020-10-10 14:02:11 -0400 | [diff] [blame] | 52 | |
Tim Edwards | cd64af5 | 2020-08-07 11:11:58 -0400 | [diff] [blame] | 53 | assign itrim = (dco == 1'b0) ? otrim : ext_trim; |
| 54 | assign creset = (dco == 1'b0) ? ireset : 1'b1; |
| 55 | |
| 56 | ring_osc2x13 ringosc ( |
Tim Edwards | 04ba17f | 2020-10-02 22:27:50 -0400 | [diff] [blame] | 57 | .reset(ireset), |
| 58 | .trim(itrim), |
| 59 | .clockp(clockp) |
Tim Edwards | cd64af5 | 2020-08-07 11:11:58 -0400 | [diff] [blame] | 60 | ); |
| 61 | |
| 62 | digital_pll_controller pll_control ( |
Tim Edwards | 04ba17f | 2020-10-02 22:27:50 -0400 | [diff] [blame] | 63 | .reset(creset), |
| 64 | .clock(clockp[0]), |
| 65 | .osc(osc), |
| 66 | .div(div), |
| 67 | .trim(otrim) |
Tim Edwards | cd64af5 | 2020-08-07 11:11:58 -0400 | [diff] [blame] | 68 | ); |
| 69 | |
Tim Edwards | cd64af5 | 2020-08-07 11:11:58 -0400 | [diff] [blame] | 70 | endmodule |
Tim Edwards | 581068f | 2020-11-19 12:45:25 -0500 | [diff] [blame] | 71 | `default_nettype wire |