Skip to content

Commit 5e7da13

Browse files
committed
samples: adc: add power shield application
add power_shield sample for general_adc_platform power shiled, to record power/voltage/current Signed-off-by: Hake Huang <[email protected]>
1 parent 59e4087 commit 5e7da13

File tree

70 files changed

+1984
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

70 files changed

+1984
-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.20.0)
4+
5+
find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})
6+
project(ADC)
7+
8+
target_sources(app PRIVATE src/main.c)
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# Copyright (c) 2024 Centro de Inovacao EDGE.
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
config SEQUENCE_SAMPLES
5+
int "Number of samples to be made on the sequence for each channel."
6+
default 5
7+
8+
config SEQUENCE_RESOLUTION
9+
int "Set the resolution of the sequence readings."
10+
default 12
11+
12+
config SEQUENCE_32BITS_REGISTERS
13+
bool "ADC data sequences are on 32bits"
14+
default n
15+
16+
source "Kconfig.zephyr"
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
.. zephyr:code-sample:: adc_power_shield
2+
:name: Analog-to-Digital Converter (ADC) power shield sample
3+
:relevant-api: adc_interface
4+
5+
Read analog inputs from ADC channels, using a sequence.
6+
7+
Overview
8+
********
9+
10+
This sample is to enable general power shield for platfroms that have ADC support.
11+
12+
13+
Building and Running
14+
********************
15+
16+
Make sure that the ADC is enabled (``status = "okay";``) and has each channel as a
17+
child node, with your desired settings like gain, reference, or acquisition time and
18+
oversampling setting (if used). It is also needed to provide an alias ``adc0`` for the
19+
desired adc. See :zephyr_file:`boards/nrf52840dk_nrf52840.overlay
20+
<samples/drivers/adc/adc_dt/boards/nrf52840dk_nrf52840.overlay>` for an example of
21+
such setup.
22+
23+
Building and Running for Nordic nRF52840
24+
========================================
25+
26+
The sample can be built and executed for the
27+
:zephyr:board:`nrf52840dk` as follows:
28+
29+
.. zephyr-app-commands::
30+
:zephyr-app: samples/drivers/adc/adc_sequence
31+
:board: nrf52840dk/nrf52840
32+
:goals: build flash
33+
:compact:
34+
35+
To build for another board, change "nrf52840dk/nrf52840" above to that board's name
36+
and provide a corresponding devicetree overlay.
37+
38+
Sample output
39+
=============
40+
41+
the output as below, repeated every time you input any char in the console:
42+
43+
.. code-block:: console
44+
45+
ADC sequence reading [1]:
46+
- ADC_0, channel 0, 5 sequence samples:
47+
- - 36 = 65mV
48+
- - 35 = 63mV
49+
- - 36 = 65mV
50+
- - 35 = 63mV
51+
- - 36 = 65mV
52+
- ADC_0, channel 1, 5 sequence samples:
53+
- - 0 = 0mV
54+
- - 0 = 0mV
55+
- - 1 = 1mV
56+
- - 0 = 0mV
57+
- - 1 = 1mV
58+
59+
.. note:: If the ADC is not supported, the output will be an error message.
60+
61+
You should get similar output as below, if you input a return:
62+
63+
.. code-block:: console
64+
65+
==== start of adc features ===
66+
CHANNEL_COUNT: 4
67+
Resolution: 12
68+
channel_id 0 features:
69+
- is single mode
70+
- verf is 3300 mv
71+
channel_id 3 features:
72+
- is single mode
73+
- verf is 3300 mv
74+
channel_id 4 features:
75+
- is single mode
76+
- verf is 3300 mv
77+
channel_id 7 features:
78+
- is single mode
79+
- verf is 3300 mv
80+
==== end of adc features ===
81+
82+
..
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
/*
2+
* Copyright (c) 2024 Centro de Inovacao EDGE
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
/ {
8+
aliases {
9+
adc0 = &adc0;
10+
};
11+
};
12+
13+
&adc0 {
14+
#address-cells = <1>;
15+
#size-cells = <0>;
16+
status = "okay";
17+
18+
pinctrl-0 = <&adc0_default>;
19+
pinctrl-names = "default";
20+
21+
prescaler = <9>;
22+
startup-time = <64>;
23+
settling-time = <3>;
24+
tracking-time = <2>;
25+
26+
/* External ADC(+) */
27+
channel@6 { // Connector A1
28+
reg = <6>;
29+
zephyr,gain = "ADC_GAIN_1";
30+
zephyr,reference = "ADC_REF_EXTERNAL0";
31+
zephyr,acquisition-time = <ADC_ACQ_TIME_DEFAULT>;
32+
zephyr,input-positive = <6>;
33+
zephyr,vref-mv = <3300>;
34+
};
35+
channel@7 { // Connector A0
36+
reg = <7>;
37+
zephyr,gain = "ADC_GAIN_1";
38+
zephyr,reference = "ADC_REF_EXTERNAL0";
39+
zephyr,acquisition-time = <ADC_ACQ_TIME_DEFAULT>;
40+
zephyr,input-positive = <7>;
41+
zephyr,vref-mv = <3300>;
42+
};
43+
};
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
/*
2+
* SPDX-License-Identifier: Apache-2.0
3+
*
4+
* Copyright (c) 2024 Nordic Semiconductor ASA
5+
* Copyright (c) 2025 Ezurio LLC
6+
*/
7+
8+
/ {
9+
zephyr,user {
10+
io-channels = <&adc 0>, <&adc 1>, <&adc 2>, <&adc 7>;
11+
};
12+
};
13+
14+
/ {
15+
aliases {
16+
adc0 = &adc;
17+
};
18+
};
19+
20+
&adc {
21+
#address-cells = <1>;
22+
#size-cells = <0>;
23+
24+
channel@0 {
25+
reg = <0>;
26+
zephyr,gain = "ADC_GAIN_1";
27+
zephyr,reference = "ADC_REF_INTERNAL";
28+
zephyr,acquisition-time = <ADC_ACQ_TIME_DEFAULT>;
29+
zephyr,input-positive = <NRF_SAADC_AIN4>; /* P1.11 */
30+
zephyr,resolution = <10>;
31+
};
32+
33+
channel@1 {
34+
reg = <1>;
35+
zephyr,gain = "ADC_GAIN_1";
36+
zephyr,reference = "ADC_REF_INTERNAL";
37+
zephyr,acquisition-time = <ADC_ACQ_TIME_DEFAULT>;
38+
zephyr,input-positive = <NRF_SAADC_AIN2>; /* P1.06 */
39+
zephyr,resolution = <12>;
40+
zephyr,oversampling = <8>;
41+
};
42+
43+
channel@2 {
44+
reg = <2>;
45+
zephyr,gain = "ADC_GAIN_1";
46+
zephyr,reference = "ADC_REF_INTERNAL";
47+
zephyr,acquisition-time = <ADC_ACQ_TIME_DEFAULT>;
48+
zephyr,input-positive = <NRF_SAADC_DVDD>; /* 0.9 V internal */
49+
zephyr,resolution = <12>;
50+
zephyr,oversampling = <8>;
51+
};
52+
53+
channel@7 {
54+
reg = <7>;
55+
zephyr,gain = "ADC_GAIN_1";
56+
zephyr,reference = "ADC_REF_INTERNAL";
57+
zephyr,acquisition-time = <ADC_ACQ_TIME_DEFAULT>;
58+
zephyr,input-positive = <NRF_SAADC_AIN6>; /* P1.13 */
59+
zephyr,input-negative = <NRF_SAADC_AIN7>; /* P1.14 */
60+
zephyr,resolution = <12>;
61+
};
62+
};
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
/*
2+
* SPDX-License-Identifier: Apache-2.0
3+
*
4+
* Copyright (c) 2024 Nordic Semiconductor ASA
5+
* Copyright (c) 2025 Ezurio LLC
6+
*/
7+
8+
/ {
9+
zephyr,user {
10+
io-channels = <&adc 0>, <&adc 1>, <&adc 2>, <&adc 7>;
11+
};
12+
};
13+
14+
/ {
15+
aliases {
16+
adc0 = &adc;
17+
};
18+
};
19+
20+
&adc {
21+
#address-cells = <1>;
22+
#size-cells = <0>;
23+
24+
channel@0 {
25+
reg = <0>;
26+
zephyr,gain = "ADC_GAIN_1";
27+
zephyr,reference = "ADC_REF_INTERNAL";
28+
zephyr,acquisition-time = <ADC_ACQ_TIME_DEFAULT>;
29+
zephyr,input-positive = <NRF_SAADC_AIN4>; /* P1.11 */
30+
zephyr,resolution = <10>;
31+
};
32+
33+
channel@1 {
34+
reg = <1>;
35+
zephyr,gain = "ADC_GAIN_1";
36+
zephyr,reference = "ADC_REF_INTERNAL";
37+
zephyr,acquisition-time = <ADC_ACQ_TIME_DEFAULT>;
38+
zephyr,input-positive = <NRF_SAADC_AIN2>; /* P1.06 */
39+
zephyr,resolution = <12>;
40+
zephyr,oversampling = <8>;
41+
};
42+
43+
channel@2 {
44+
reg = <2>;
45+
zephyr,gain = "ADC_GAIN_1";
46+
zephyr,reference = "ADC_REF_INTERNAL";
47+
zephyr,acquisition-time = <ADC_ACQ_TIME_DEFAULT>;
48+
zephyr,input-positive = <NRF_SAADC_DVDD>; /* 0.9 V internal */
49+
zephyr,resolution = <12>;
50+
zephyr,oversampling = <8>;
51+
};
52+
53+
channel@7 {
54+
reg = <7>;
55+
zephyr,gain = "ADC_GAIN_1";
56+
zephyr,reference = "ADC_REF_INTERNAL";
57+
zephyr,acquisition-time = <ADC_ACQ_TIME_DEFAULT>;
58+
zephyr,input-positive = <NRF_SAADC_AIN6>; /* P1.13 */
59+
zephyr,input-negative = <NRF_SAADC_AIN7>; /* P1.14 */
60+
zephyr,resolution = <12>;
61+
};
62+
};
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
CONFIG_SEQUENCE_RESOLUTION=12
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/*
2+
* Copyright (c) 2024 Centro de Inovacao EDGE
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
#include <zephyr/dt-bindings/adc/adc.h>
8+
9+
/ {
10+
aliases {
11+
adc0 = &adc0;
12+
};
13+
};
14+
15+
&adc0 {
16+
status = "okay";
17+
#address-cells = <1>;
18+
#size-cells = <0>;
19+
20+
channel@0 {
21+
reg = <0>;
22+
zephyr,acquisition-time = <ADC_ACQ_TIME(ADC_ACQ_TIME_MICROSECONDS, 1)>;
23+
zephyr,gain = "ADC_GAIN_1";
24+
zephyr,reference = "ADC_REF_INTERNAL";
25+
zephyr,input-positive = <0>; /* P10.0 */
26+
};
27+
28+
channel@1 {
29+
reg = <1>;
30+
zephyr,acquisition-time = <ADC_ACQ_TIME(ADC_ACQ_TIME_MICROSECONDS, 1)>;
31+
zephyr,gain = "ADC_GAIN_1";
32+
zephyr,reference = "ADC_REF_INTERNAL";
33+
zephyr,input-positive = <1>; /* P10.1 */
34+
};
35+
};
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
CONFIG_SEQUENCE_RESOLUTION=12
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/*
2+
* Copyright (c) 2024 Centro de Inovacao EDGE
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
#include <zephyr/dt-bindings/adc/adc.h>
8+
9+
/ {
10+
aliases {
11+
adc0 = &adc0;
12+
};
13+
};
14+
15+
&adc0 {
16+
status = "okay";
17+
#address-cells = <1>;
18+
#size-cells = <0>;
19+
20+
channel@0 {
21+
reg = <0>;
22+
zephyr,acquisition-time = <ADC_ACQ_TIME(ADC_ACQ_TIME_MICROSECONDS, 1)>;
23+
zephyr,gain = "ADC_GAIN_1";
24+
zephyr,reference = "ADC_REF_INTERNAL";
25+
zephyr,input-positive = <2>; /* P10.2 */
26+
};
27+
28+
channel@1 {
29+
reg = <1>;
30+
zephyr,acquisition-time = <ADC_ACQ_TIME(ADC_ACQ_TIME_MICROSECONDS, 1)>;
31+
zephyr,gain = "ADC_GAIN_1";
32+
zephyr,reference = "ADC_REF_INTERNAL";
33+
zephyr,input-positive = <3>; /* P10.3 */
34+
};
35+
};

0 commit comments

Comments
 (0)