Skip to content

Commit 954caa6

Browse files
committed
WIP samples: drivers: nrf_timer: assess drift with 1pps signal
Track time using the system timer, SysTick, and a TIMER peripheral, capturing at external 1pps signals and estimating error. When HFCLK is on the timer and systick errors are less than 1 ppm. In that case synth is the highest accuracy LFCLK source, with XTAL then RC in decreasing accuracy. When HFCLK is off the timer and systick errors are the same and are generally between 3000 and 4000 ppm. Using the synth clock LFCLK tracks the HFCLK error; RC reduces to between -30 and -60 ppm (30 ppm resolution); XTAL between 0 and 30 ppm (longer samples show 25 ppm). Signed-off-by: Peter Bigot <peter.bigot@nordicsemi.no>
1 parent f7dbf6c commit 954caa6

File tree

9 files changed

+473
-0
lines changed

9 files changed

+473
-0
lines changed
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# SPDX-License-Identifier: Apache-2.0
2+
3+
cmake_minimum_required(VERSION 3.13.1)
4+
find_package(Zephyr HINTS $ENV{ZEPHYR_BASE})
5+
project(NONE)
6+
7+
FILE(GLOB app_sources src/*.c)
8+
target_sources(app PRIVATE ${app_sources})

samples/drivers/nrf_timer/Kconfig

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# Copyright (c) 2019 Peter Bigot Consulting, LLC
2+
#
3+
# SPDX-License-Identifier: Apache-2.0
4+
#
5+
6+
config APP_SET_ALIGNED_CLOCK
7+
bool "Option to align RTC with time-since-boot"
8+
help
9+
If enabled this reads the RTC then sets it so that uptime
10+
shows as being relative to the start of the next hour.
11+
12+
source "Kconfig"
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
/*
2+
* Copyright (c) 2019 Peter Bigot Consulting, LLC
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
&i2c0 { /* SDA 30, SCL 7 */
8+
status = "okay";
9+
ds3231: ds3231@68 {
10+
compatible = "maxim,ds3231";
11+
reg = <0x68>;
12+
label = "DS3231";
13+
isw-gpios = <&gpio0 0 (GPIO_PULL_UP | GPIO_ACTIVE_LOW)>;
14+
};
15+
};
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
/*
2+
* Copyright (c) 2019 Peter Bigot Consulting, LLC
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
&i2c0 { /* SDA P0.26, SCL P0.27 */
8+
status = "okay";
9+
ds3231: ds3231@68 {
10+
compatible = "maxim,ds3231";
11+
reg = <0x68>;
12+
label = "DS3231";
13+
isw-gpios = <&gpio0 0 (GPIO_PULL_UP | GPIO_ACTIVE_LOW)>;
14+
};
15+
};
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/*
2+
* Copyright (c) 2019 Peter Bigot Consulting, LLC
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
&i2c0 { /* SDA P0.26, SCL P0.27, ISW P1.1, 32K P1.2 */
8+
status = "okay";
9+
ds3231: ds3231@68 {
10+
compatible = "maxim,ds3231";
11+
reg = <0x68>;
12+
label = "DS3231";
13+
isw-gpios = <&gpio1 1 (GPIO_PULL_UP | GPIO_ACTIVE_LOW)>;
14+
32k-gpios = <&gpio1 2 (GPIO_PULL_UP | GPIO_ACTIVE_LOW)>;
15+
};
16+
};
17+
18+
/ {
19+
test-config {
20+
compatible = "test,nrf-timer";
21+
status = "okay";
22+
tick-rtc = <&rtc1>;
23+
hf-timer = <&timer0>;
24+
int-gpios = <&gpio1 1 (GPIO_PULL_UP | GPIO_ACTIVE_LOW)>;
25+
lf-gpios = <&gpio1 2 (GPIO_PULL_UP | GPIO_ACTIVE_LOW)>;
26+
hf-gpios = <&gpio1 8 (GPIO_PULL_UP | GPIO_ACTIVE_LOW)>;
27+
};
28+
};
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
#
2+
# Copyright (c) 2020 Nordic Semiconductor ASA
3+
#
4+
# SPDX-License-Identifier: Apache-2.0
5+
#
6+
7+
description: |
8+
This binding provides resources required to build and run the
9+
samples/drivers/nrf_timer test.
10+
11+
compatible: "test,nrf-timer"
12+
13+
properties:
14+
tick-rtc:
15+
type: phandle
16+
required: false
17+
description: |
18+
Reference to the RTC peripheral used as the system tick timer.
19+
If absent uses NRF_RTC1 which is hard-coded as the tick timer.
20+
CC[0] is by the tick timer for alarms; CC[1] is used by this
21+
application for triggered capture.
22+
23+
hf-timer:
24+
type: phandle
25+
required: true
26+
description: |
27+
Reference to the TIMER peripheral used as the high-frequency
28+
clock. This timer must support 32-bit mode. In this
29+
application CC[0] is used to read the timer; CC[1] is used for
30+
triggered capture.
31+
32+
int-gpios:
33+
type: phandle-array
34+
required: true
35+
description: |
36+
Identity of a GPIO that will be connected to the 1pps signal
37+
and serve as the trigger for an interrupt in which the ticks
38+
counter will be captured.
39+
40+
hf-gpios:
41+
type: phandle-array
42+
required: true
43+
description: |
44+
Identity of a GPIO that will be connected to the 1pps signal
45+
and serve as the trigger for a GPIOTE input event connected to
46+
an TIMER capture task.
47+
48+
lf-gpios:
49+
type: phandle-array
50+
required: true
51+
description: |
52+
Identity of a GPIO that will be connected to the 1pps signal
53+
and serve as the trigger for a GPIOTE input event connected to
54+
an RTC capture task.

samples/drivers/nrf_timer/prj.conf

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
CONFIG_PRINTK=y
2+
3+
CONFIG_I2C=y
4+
CONFIG_COUNTER=y
5+
CONFIG_COUNTER_DS3231=y
6+
7+
CONFIG_HWINFO=y
8+
CONFIG_CLOCK_CONTROL_NRF_K32SRC_XTAL=y
9+
CONFIG_CLOCK_CONTROL_NRF_K32SRC_RC=n
10+
CONFIG_CLOCK_CONTROL_NRF_K32SRC_SYNTH=n
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
sample:
2+
description: DS3231 sample program
3+
name: rtc_ds3231
4+
tests:
5+
sample.driver.rtc_ds3231:
6+
build_only: true
7+
platform_whitelist: efr32mg_sltb004a frdm_k64f nrf51_pca10028 nucleo_l476rg particle_xenon

0 commit comments

Comments
 (0)