OpenCores
URL https://opencores.org/ocsvn/an-fpga-implementation-of-low-latency-noc-based-mpsoc/an-fpga-implementation-of-low-latency-noc-based-mpsoc/trunk

Subversion Repositories an-fpga-implementation-of-low-latency-noc-based-mpsoc

[/] [an-fpga-implementation-of-low-latency-noc-based-mpsoc/] [trunk/] [mpsoc/] [rtl/] [src_peripheral/] [clk_source/] [xilinx_pll/] [xilinx_pll_sim/] [phase_shift.v] - Blame information for rev 48

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 48 alirezamon
/*
2
 * phase_shift.v: Shifts the input clock by the given degree and can change
3
        it's duty cycle.
4
 * author: Till Mahlburg
5
 * year: 2019-2020
6
 * organization: Universität Leipzig
7
 * license: ISC
8
 *
9
 */
10
 
11
// synthesis translate_off
12
 
13
`timescale 1 ns / 1 ps
14
 
15
module phase_shift (
16
        input RST,
17
        input PWRDWN,
18
        input clk,
19
        /* shift in degrees */
20
        input signed [31:0] shift_1000,
21
        /* period length of the clock */
22
        input [31:0] clk_period_1000,
23
        /* duty cycle in percent */
24
        input [6:0] duty_cycle,
25
 
26
        output reg lock,
27
        output reg clk_shifted);
28
 
29
        /* The formulas used here are composed of the following:
30
         * - clk_period_1000 / 1000.0 calculates the actual period length, which
31
         *   has been multiplied by 1000 to enable a higher precision.
32
         * - shift * ((clk_period_1000 / 1000.0) / 360.0) calculate the basic shift
33
         *   as a multiple of a 360th of the period of the clk to shift
34
         * - if the desired shift is negative, we just add a shift by
35
         *   360 degrees and add the (negative) shift:
36
         *   clk_period + (shift * (clk_period / 360.0))
37
         * - to calculate the duty cycle, we delay or rush the output of
38
         *   0 by adding (or subtracting) the desired duty cycle in 100th
39
         *   of the input clk period from the default (50):
40
         *   (duty_cycle + 50.0) * (clk_period / 100.0)
41
         */
42
 
43
        /* calculate when to put out high */
44
        always @(posedge clk or posedge RST or posedge PWRDWN) begin
45
                if (!RST && !PWRDWN) begin
46
                        if (shift_1000 < 0) begin
47
                                clk_shifted <= #((clk_period_1000 / 1000.0) + ((shift_1000 / 1000.0) * ((clk_period_1000 / 1000.0) / 360.0))) 1;
48
                        end else begin
49
                                clk_shifted <= #((shift_1000 / 1000.0) * ((clk_period_1000 / 1000.0) / 360.0)) 1;
50
                        end
51
                end
52
        end
53
 
54
        /* calculate when to put out low and return when the phase and duty cycle is correctly set */
55
        always @(negedge clk or posedge RST) begin
56
                if (RST) begin
57
                        clk_shifted <= 1'b0;
58
                        lock <= 1'b0;
59
                end else if (lock !== 1'bx) begin
60
                        if (shift_1000 < 0) begin
61
                                clk_shifted <= #((clk_period_1000 / 1000.0) + ((shift_1000/ 1000.0)  * ((clk_period_1000 / 1000.0) / 360.0)) + ((duty_cycle + 50.0) * ((clk_period_1000 / 1000.0) / 100.0))) 0;
62
                                lock <= #((clk_period_1000 / 1000.0) + ((shift_1000/ 1000.0)  * ((clk_period_1000 / 1000.0) / 360.0)) + ((duty_cycle + 50.0) * ((clk_period_1000 / 1000.0) / 100.0))) 1'b1;
63
                        end else begin
64
                                clk_shifted <= #((shift_1000/ 1000.0)  * ((clk_period_1000 / 1000.0) / 360.0) + ((duty_cycle + 50.0) * ((clk_period_1000 / 1000.0) / 100.0))) 0;
65
                                lock <= #((shift_1000/ 1000.0)  * ((clk_period_1000 / 1000.0) / 360.0) + ((duty_cycle + 50.0) * ((clk_period_1000 / 1000.0) / 100.0))) 1'b1;
66
                        end
67
                end
68
        end
69
 
70
        /* PWRDWN for good */
71
        always begin
72
                if (PWRDWN) begin
73
                        clk_shifted <= 1'bx;
74
                        lock <= 1'bx;
75
                        #0.001;
76
                end else begin
77
                #1;
78
                end
79
        end
80
 
81
endmodule
82
 
83
// synthesis translate_on

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.