1.. _nrf-clock-skew-sample:
2
3nRF5x Clock Skew Demo
4#####################
5
6Overview
7********
8
9This sample uses the API for correlating time sources to measure the
10skew between HFCLK (used for the CPU) and LFCLK (used for system time).
11It also shows how to use this skew to correct durations measured in the
12LFCLK domain to durations in the HFCLK domain.
13
14The ``CONFIG_APP_ENABLE_HFXO`` Kconfig option can be select to configure
15the high frequency clock to use a crystal oscillator rather than the
16default RC oscillator.  (Capabilities like Bluetooth that require an
17accurate high-frequency clock generally enable this source
18automatically.)  The relative error is significantly lower when HFXO is
19enabled.
20
21Requirements
22************
23
24This application uses any nRF51 DK or nRF52 DK board for the demo.
25
26Building, Flashing and Running
27******************************
28
29.. zephyr-app-commands::
30   :zephyr-app: samples/boards/nrf/clock_skew
31   :board: nrf52dk_nrf52840
32   :goals: build flash
33   :compact:
34
35Running:
36
37
38Sample Output
39=============
40
41.. code-block:: console
42
43   *** Booting Zephyr OS build v2.5.0-rc3-94-g06a4b650467b  ***
44   Power-up clocks: LFCLK[ON]: Running LFXO ; HFCLK[OFF]: Running HFINT
45   Start TIMER_0: 0
46   Timer-running clocks: LFCLK[ON]: Running LFXO ; HFCLK[OFF]: Running HFINT
47   Checking TIMER_0 at 16000000 Hz against ticks at 32768 Hz
48   Timer wraps every 268 s
49
50   Ty  Latest           Base             Span             Err
51   HF  00:00:00.015666
52   LF  00:00:00.404937
53   Started sync: 0
54
55   Ty  Latest           Base             Span             Err
56   HF  00:00:09.978436  00:00:00.015666  00:00:09.962769
57   LF  00:00:10.414520  00:00:00.404937  00:00:10.009582  00:00:00.046813
58   RHF 00:00:09.978435                                   -00:00:00.000000
59   Skew 0.995323 ; err 4676818 ppb
60
61   Ty  Latest           Base             Span             Err
62   HF  00:00:19.959136  00:00:00.015666  00:00:19.943469
63   LF  00:00:20.441589  00:00:00.404937  00:00:20.036651  00:00:00.093182
64   RHF 00:00:19.959117                                   -00:00:00.000018
65   Skew 0.995349 ; err 4650592 ppb
66
67   Ty  Latest           Base             Span             Err
68   HF  00:00:29.937181  00:00:00.015666  00:00:29.921514
69   LF  00:00:30.468627  00:00:00.404937  00:00:30.063690  00:00:00.142176
70   RHF 00:00:29.937175                                   -00:00:00.000005
71   Skew 0.995271 ; err 4729151 ppb
72
73   Ty  Latest           Base             Span             Err
74   HF  00:00:39.917347  00:00:00.015666  00:00:39.901680
75   LF  00:00:40.495666  00:00:00.404937  00:00:40.090728  00:00:00.189048
76   RHF 00:00:39.917339                                   -00:00:00.000008
77   Skew 0.995284 ; err 4715502 ppb
78
79   Ty  Latest           Base             Span             Err
80   HF  00:00:49.899493  00:00:00.015666  00:00:49.883826
81   LF  00:00:50.522674  00:00:00.404937  00:00:50.117736  00:00:00.233910
82   RHF 00:00:49.899486                                   -00:00:00.000007
83   Skew 0.995333 ; err 4667222 ppb
84
85   Ty  Latest           Base             Span             Err
86   HF  00:00:59.878166  00:00:00.015666  00:00:59.862499
87   LF  00:01:00.549713  00:00:00.404937  00:01:00.144775  00:00:00.282276
88   RHF 00:00:59.878154                                   -00:00:00.000011
89   Skew 0.995307 ; err 4693269 ppb
90   ...
91   Ty  Latest           Base             Span             Err
92   HF  00:02:59.654855  00:00:00.015666  00:02:59.639188
93   LF  00:03:00.873901  00:00:00.404937  00:03:00.468963  00:00:00.829775
94   RHF 00:02:59.654857                                    00:00:00.000001
95   Skew 0.995402 ; err 4597902 ppb
96   ...
97   Ty  Latest           Base             Span             Err
98   HF  00:04:59.410593  00:00:00.015666  00:04:59.394926
99   LF  00:05:01.198181  00:00:00.404937  00:05:00.793243  00:00:01.398317
100   RHF 00:04:59.410594                                    00:00:00.000001
101   Skew 0.995351 ; err 4648745 ppb
102   ...
103   Ty  Latest           Base             Span             Err
104   HF  00:09:58.829511  00:00:00.015666  00:09:58.813845
105   LF  00:10:02.008911  00:00:00.404937  00:10:01.603973  00:00:02.790128
106   RHF 00:09:58.829509                                   -00:00:00.000002
107   Skew 0.995362 ; err 4637837 ppb
108   ...
109   Ty  Latest           Base             Span             Err
110   HF  00:29:56.607589  00:00:00.015666  00:29:56.591923
111   LF  00:30:05.250732  00:00:00.404937  00:30:04.845794  00:00:08.253871
112   RHF 00:29:56.607585                                   -00:00:00.000004
113   Skew 0.995427 ; err 4573166 ppb
114   ...
115   Ty  Latest           Base             Span             Err
116   HF  00:59:43.781443  00:00:00.015666  00:59:43.765776
117   LF  01:00:00.085113  00:00:00.404937  00:59:59.680175  00:00:15.914399
118   RHF 00:59:43.781535                                    00:00:00.000092
119   Skew 0.995579 ; err 4421055 ppb
120   ...
121   Ty  Latest           Base             Span             Err
122   HF  01:59:37.666395  00:00:00.015666  01:59:37.650728
123   LF  02:00:09.810913  00:00:00.404937  02:00:09.405975  00:00:31.755247
124   RHF 01:59:37.666057                                   -00:00:00.000338
125   Skew 0.995595 ; err 4404723 ppb
126   ...
127   Ty  Latest           Base             Span             Err
128   HF  05:58:33.905236  00:00:00.015666  05:58:33.889570
129   LF  06:00:08.604980  00:00:00.404937  06:00:08.200042  00:01:34.310472
130   RHF 05:58:33.904338                                   -00:00:00.000898
131   ..
132   Skew 0.995635 ; err 4364550 ppb
133   Ty  Latest           Base             Span             Err
134   HF  11:56:59.503922  00:00:00.015666  11:56:59.488255
135   LF  12:00:06.793182  00:00:00.404937  12:00:06.388244  00:03:06.899989
136   RHF 11:56:59.503948                                    00:00:00.000025
137   Skew 0.995674 ; err 4325747 ppb
138