Skip to content

Commit c00c2aa

Browse files
committed
samples: drivers: opamp: Add output_measure exmaple
Add output_measure exmaple, enabled on frdm_mcxa156, frdm_mcxa166, frdm_mcxa276, frdm_mcxn947_mcxn947_cpu0, lpcxpresso55s36. Signed-off-by: Zhaoxiang Jin <Zhaoxiang.Jin_1@nxp.com>
1 parent b9a7fe7 commit c00c2aa

File tree

12 files changed

+514
-0
lines changed

12 files changed

+514
-0
lines changed
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# Copyright 2025 NXP
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
cmake_minimum_required(VERSION 3.20.0)
5+
6+
find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})
7+
project(output_measure)
8+
9+
FILE(GLOB app_sources src/*.c)
10+
target_sources(app PRIVATE ${app_sources})
Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
.. zephyr:code-sample:: opamp
2+
:name: Operational Amplifier (OPAMP)
3+
:relevant-api: opamp_interface
4+
5+
Amplify the input of the OPAMP and sample it using the ADC.
6+
7+
Overview
8+
********
9+
10+
This sample demonstrates how to use the :ref:`OPAMP driver API <opamp_api>`.
11+
12+
Building and Running
13+
********************
14+
15+
To build and run this example, users need to configure the following:
16+
1. Configure one channel of the ADC to measure the output of the OPAMP.
17+
2. Specify the inverting and non-inverting gain in
18+
:zephyr_file:`samples/drivers/opamp/output_measure/src/main.h`. Note
19+
that any gain value should not cause the output of the OPAMP to be
20+
less than the theoretical minimum or greater than the theoretical maximum.
21+
22+
Building and Running for NXP FRDM-MCXA156
23+
=========================================
24+
Build the application for the :zephyr:board:`frdm_mcxa156` board.
25+
26+
.. zephyr-app-commands::
27+
:zephyr-app: samples/drivers/opamp/output_measure
28+
:board: frdm_mcxa156
29+
:goals: build flash
30+
:compact:
31+
32+
Hardware connection:
33+
1. Positive input channel J2-12 (OPAMP0_INP) connects to a voltage source.
34+
2. Negative input channel R60-3 (OPAMP0_INN) connects to a voltage source.
35+
3. Vout = Vref + (Vinp - Vinn) * Ngain.
36+
37+
Building and Running for NXP FRDM-MCXA166
38+
=========================================
39+
Build the application for the :zephyr:board:`frdm_mcxa166` board.
40+
41+
.. zephyr-app-commands::
42+
:zephyr-app: samples/drivers/opamp/output_measure
43+
:board: frdm_mcxa166
44+
:goals: build flash
45+
:compact:
46+
47+
Hardware connection:
48+
1. Positive input channel J4-1 (OPAMP0_INP) connects to GND.
49+
2. Negative input channel J4-3 (OPAMP0_INN) connects to a voltage source.
50+
3. Vout = Vref - Vinn * Ngain.
51+
52+
Building and Running for NXP FRDM-MCXA276
53+
=========================================
54+
Build the application for the :zephyr:board:`frdm_mcxa276` board.
55+
56+
.. zephyr-app-commands::
57+
:zephyr-app: samples/drivers/opamp/output_measure
58+
:board: frdm_mcxa276
59+
:goals: build flash
60+
:compact:
61+
62+
Hardware connection:
63+
1. Positive input channel J4-1 (OPAMP0_INP) connects to GND.
64+
2. Negative input channel J4-3 (OPAMP0_INN) connects to a voltage source.
65+
3. Vout = Vref - Vinn * Ngain.
66+
67+
Building and Running for NXP FRDM-MCXN947
68+
=========================================
69+
Build the application for the :zephyr:board:`frdm_mcxn947` board.
70+
71+
.. zephyr-app-commands::
72+
:zephyr-app: samples/drivers/opamp/output_measure
73+
:board: frdm_mcxn947/mcxn947/cpu0
74+
:goals: build flash
75+
:compact:
76+
77+
Hardware connection:
78+
1. Positive input channel J4-1 (OPAMP0_INP) connects to a voltage source.
79+
2. Negative input channel J4_3 (OPAMP0_INN) connects to a voltage source.
80+
3. Vout = Vref + (Vinp - Vinn) * Ngain.
81+
82+
Building and Running for NXP LPCXpresso55S36
83+
============================================
84+
The sample can be built and executed for the :zephyr:board:`lpcxpresso55s36` as
85+
follows:
86+
87+
.. zephyr-app-commands::
88+
:zephyr-app: samples/drivers/opamp/output_measure
89+
:board: lpcxpresso55s36
90+
:goals: build flash
91+
:compact:
92+
93+
Hardware connection:
94+
1. DNP on-board R913, R194.
95+
2. Positive input channel J13-5 (OPAMP0_INP) connect to GND.
96+
3. Negative input channel J13-3 (OPAMP0_INN) connect to a voltage source.
97+
4. Vout = Vref - Ngain * Vinn.
98+
99+
Sample output
100+
=============
101+
102+
You will see the inverting and non-inverting gain and the output of the opamp
103+
in the terminal. Users can calculate the theoretical output value of the opamp
104+
according to the formula and compare it with the ADC measurement value.
105+
106+
The following output is printed:
107+
108+
.. code-block:: console
109+
*** Booting Zephyr OS build v4.2.0-1004-g26c31c638c9b ***
110+
Set opamp inverting gain to: 1
111+
Set opamp non-inverting gain to: 1
112+
OPAMP output is: 1124(mv)
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/*
2+
* Copyright 2025 NXP
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
#include <zephyr/dt-bindings/adc/adc.h>
8+
#include <zephyr/dt-bindings/adc/mcux-lpadc.h>
9+
10+
/ {
11+
resources: resources {
12+
compatible = "opamp-output-measure";
13+
opamp = <&opamp0>;
14+
io-channels = <&lpadc0 0>;
15+
adc-read-delay-ms = <1>;
16+
};
17+
};
18+
19+
&opamp0 {
20+
functional-mode = "pga";
21+
non-inverting-reference-source = "Input1"; /* VREFH/2 */
22+
enable-measure-output;
23+
};
24+
25+
&lpadc0 {
26+
#address-cells = <1>;
27+
#size-cells = <0>;
28+
29+
channel@0 {
30+
reg = <0>;
31+
zephyr,gain = "ADC_GAIN_1";
32+
zephyr,reference = "ADC_REF_EXTERNAL0";
33+
zephyr,vref-mv = <3300>;
34+
zephyr,acquisition-time = <ADC_ACQ_TIME_DEFAULT>;
35+
zephyr,resolution = <16>;
36+
/* LPADC0 CH3A is internally connected to the operational amplifier output. */
37+
zephyr,input-positive = <MCUX_LPADC_CH3A>;
38+
};
39+
};
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
/*
2+
* Copyright 2025 NXP
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
#include <zephyr/dt-bindings/adc/adc.h>
8+
#include <zephyr/dt-bindings/adc/mcux-lpadc.h>
9+
10+
/ {
11+
resources: resources {
12+
compatible = "opamp-output-measure";
13+
opamp = <&opamp1>;
14+
io-channels = <&lpadc1 0>;
15+
adc-read-delay-ms = <1>;
16+
};
17+
};
18+
19+
/* OPAMP is in follower mode, and its output is Vref of OPAMP1/2/3. */
20+
&opamp0 {
21+
functional-mode = "follower";
22+
is-reference-source;
23+
};
24+
25+
&opamp1 {
26+
functional-mode = "inverting";
27+
};
28+
29+
&lpadc1 {
30+
#address-cells = <1>;
31+
#size-cells = <0>;
32+
33+
channel@0 {
34+
reg = <0>;
35+
zephyr,gain = "ADC_GAIN_1";
36+
zephyr,reference = "ADC_REF_EXTERNAL0";
37+
zephyr,vref-mv = <3300>;
38+
zephyr,acquisition-time = <ADC_ACQ_TIME_DEFAULT>;
39+
zephyr,resolution = <16>;
40+
/* LPADC1 CH2A is internally connected to the operational amplifier instance1 output. */
41+
zephyr,input-positive = <MCUX_LPADC_CH2A>;
42+
};
43+
};
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
/*
2+
* Copyright 2025 NXP
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
#include <zephyr/dt-bindings/adc/adc.h>
8+
#include <zephyr/dt-bindings/adc/mcux-lpadc.h>
9+
10+
/ {
11+
resources: resources {
12+
compatible = "opamp-output-measure";
13+
opamp = <&opamp1>;
14+
io-channels = <&lpadc1 0>;
15+
adc-read-delay-ms = <1>;
16+
};
17+
};
18+
19+
/* OPAMP is in follower mode, and its output is Vref of OPAMP1/2/3 */
20+
&opamp0 {
21+
functional-mode = "follower";
22+
is-reference-source;
23+
};
24+
25+
&opamp1 {
26+
functional-mode = "inverting";
27+
};
28+
29+
&lpadc1 {
30+
#address-cells = <1>;
31+
#size-cells = <0>;
32+
33+
channel@0 {
34+
reg = <0>;
35+
zephyr,gain = "ADC_GAIN_1";
36+
zephyr,reference = "ADC_REF_EXTERNAL0";
37+
zephyr,vref-mv = <3300>;
38+
zephyr,acquisition-time = <ADC_ACQ_TIME_DEFAULT>;
39+
zephyr,resolution = <16>;
40+
/* LPADC1 CH2A is internally connected to the operational amplifier instance1 output. */
41+
zephyr,input-positive = <MCUX_LPADC_CH2A>;
42+
};
43+
};
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
/*
2+
* Copyright 2025 NXP
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
#include <zephyr/dt-bindings/adc/adc.h>
8+
#include <zephyr/dt-bindings/adc/mcux-lpadc.h>
9+
10+
/ {
11+
resources: resources {
12+
compatible = "opamp-output-measure";
13+
opamp = <&opamp0>;
14+
io-channels = <&lpadc0 0>;
15+
adc-read-delay-ms = <1>;
16+
};
17+
};
18+
19+
&opamp0 {
20+
functional-mode = "pga";
21+
non-inverting-reference-source = "Input1"; /* VDD_ANA/2 */
22+
enable-measure-output;
23+
};
24+
25+
&lpadc0 {
26+
#address-cells = <1>;
27+
#size-cells = <0>;
28+
29+
voltage-ref= <0>;
30+
31+
channel@0 {
32+
reg = <0>;
33+
zephyr,gain = "ADC_GAIN_1";
34+
zephyr,reference = "ADC_REF_EXTERNAL0";
35+
zephyr,vref-mv = <3300>;
36+
zephyr,acquisition-time = <ADC_ACQ_TIME_DEFAULT>;
37+
zephyr,resolution = <16>;
38+
/* LPADC0 CH1A is internally connected to the operational amplifier output. */
39+
zephyr,input-positive = <MCUX_LPADC_CH1A>;
40+
};
41+
};
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
/*
2+
* Copyright 2025 NXP
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
#include <zephyr/dt-bindings/adc/adc.h>
8+
#include <zephyr/dt-bindings/adc/mcux-lpadc.h>
9+
10+
/ {
11+
resources: resources {
12+
compatible = "opamp-output-measure";
13+
opamp = <&opamp0>;
14+
io-channels = <&adc0 0>;
15+
adc-read-delay-ms = <1>;
16+
};
17+
};
18+
19+
&opamp0 {
20+
functional-mode = "inverting";
21+
non-inverting-reference-source = "Input1"; /* VDDA */
22+
enable-measure-output;
23+
};
24+
25+
&adc0 {
26+
#address-cells = <1>;
27+
#size-cells = <0>;
28+
29+
voltage-ref= <0>;
30+
31+
channel@0 {
32+
reg = <0>;
33+
zephyr,gain = "ADC_GAIN_1";
34+
zephyr,reference = "ADC_REF_EXTERNAL0";
35+
zephyr,vref-mv = <3300>;
36+
zephyr,acquisition-time = <ADC_ACQ_TIME_DEFAULT>;
37+
zephyr,resolution = <12>;
38+
/* LPADC0 CH0A is internally connected to the operational amplifier output. */
39+
zephyr,input-positive = <MCUX_LPADC_CH0A>;
40+
};
41+
};
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# Copyright 2025 NXP
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
description: |
5+
This binding provides resources required to build and run the
6+
samples/drivers/opamp/output_measure in Zephyr.
7+
8+
compatible: "opamp-output-measure"
9+
10+
properties:
11+
opamp:
12+
type: phandles
13+
required: true
14+
description: |
15+
Indicates opamp to be tested.
16+
17+
io-channels:
18+
type: phandle-array
19+
required: true
20+
description: |
21+
Indicates ADC channels to be used.
22+
23+
adc-read-delay-ms:
24+
type: int
25+
default: 0
26+
description: |
27+
Indicates delay (in ms) between voltage set and ADC read.
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Copyright 2025 NXP
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
CONFIG_ADC=y
5+
CONFIG_OPAMP=y
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# Copyright 2025 NXP
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
sample:
5+
name: OPAMP output measurement sample
6+
tests:
7+
sample.drivers.opamp.output_measure:
8+
tags: opamp
9+
depends_on: opamp
10+
harness: console
11+
harness_config:
12+
type: multi_line
13+
regex:
14+
- "Set opamp inverting gain to: -?\\d+"
15+
- "Set opamp non-inverting gain to: -?\\d+"
16+
- "OPAMP output is: -?\\d+(mv)"
17+
platform_allow:
18+
- frdm_mcxa156
19+
- frdm_mcxa166
20+
- frdm_mcxa276
21+
- frdm_mcxn947/mcxn947/cpu0
22+
- lpcxpresso55s36

0 commit comments

Comments
 (0)