diff --git a/samples/shields/lmp90100_evb/lmp90100_evb.rst b/samples/shields/lmp90100_evb/lmp90100_evb.rst new file mode 100644 index 00000000000..6435a055ef4 --- /dev/null +++ b/samples/shields/lmp90100_evb/lmp90100_evb.rst @@ -0,0 +1,10 @@ +.. _shields-lmp90100_evb-samples: + +LMP90100 Sensor AFE Evaluation Board Shield Samples +################################################### + +.. toctree:: + :maxdepth: 1 + :glob: + + **/* diff --git a/samples/shields/lmp90100_evb/rtd/CMakeLists.txt b/samples/shields/lmp90100_evb/rtd/CMakeLists.txt new file mode 100644 index 00000000000..21549f74215 --- /dev/null +++ b/samples/shields/lmp90100_evb/rtd/CMakeLists.txt @@ -0,0 +1,12 @@ +# SPDX-License-Identifier: Apache-2.0 + +cmake_minimum_required(VERSION 3.13.1) + +# This sample is specific to lmp90100_evb shield. Enforce -DSHIELD option +set(SHIELD lmp90100_evb) + +include($ENV{ZEPHYR_BASE}/cmake/app/boilerplate.cmake NO_POLICY_SCOPE) +project(lmp90100_evb_rtd) + +FILE(GLOB app_sources src/*.c) +target_sources(app PRIVATE ${app_sources}) diff --git a/samples/shields/lmp90100_evb/rtd/README.rst b/samples/shields/lmp90100_evb/rtd/README.rst new file mode 100644 index 00000000000..26186beda44 --- /dev/null +++ b/samples/shields/lmp90100_evb/rtd/README.rst @@ -0,0 +1,53 @@ +.. _lmp90100_evb_rtd_sample: + +LMP90100 Sensor AFE Evaluation Board: RTD Sample +################################################ + +Overview +******** + +This sample is provided as an example of how to read the temperature +of a Resistance Temperature Detector (RTD) sensor using the LMP90100 +Sensor AFE Evaluation Board shield. The sample is designed for use +with a 3-wire PT100 sensor. + +Please refer to :ref:`lmp90100_evb_shield` for more information on +this shield. + +Requirements +************ + +Prior to running the sample application, the LMP90100 EVB must be +connected to the development board according to Example #3 ("3-wire +RTD Application") in the `LMP90100 Sensor AFE Evaluation Board User's +Guide`_. + +Building and Running +******************** + +This sample runs with the LMP90100 EVB connected to any development +board with a matching Arduino connector. For this example, we use a +:ref:`frdm_k64f` board. + +.. zephyr-app-commands:: + :zephyr-app: samples/shields/lmp90100_evb/rtd + :board: frdm_k64f + :goals: build + :compact: + +Sample Output +============= + + .. code-block:: console + + R: 111.15 ohm + T: 28.66 degC + R: 111.14 ohm + T: 28.64 degC + R: 111.14 ohm + T: 28.63 degC + R: 111.13 ohm + T: 28.61 degC + +.. _LMP90100 Sensor AFE Evaluation Board User's Guide: + http://www.ti.com/lit/pdf/snau028 diff --git a/samples/shields/lmp90100_evb/rtd/app.overlay b/samples/shields/lmp90100_evb/rtd/app.overlay new file mode 100644 index 00000000000..4d55dc3672c --- /dev/null +++ b/samples/shields/lmp90100_evb/rtd/app.overlay @@ -0,0 +1,9 @@ +/* + * Copyright (c) 2019 Vestas Wind Systems A/S + * + * SPDX-License-Identifier: Apache-2.0 + */ + +&lmp90100 { + rtd-current = <1000>; +}; diff --git a/samples/shields/lmp90100_evb/rtd/prj.conf b/samples/shields/lmp90100_evb/rtd/prj.conf new file mode 100644 index 00000000000..86530923e81 --- /dev/null +++ b/samples/shields/lmp90100_evb/rtd/prj.conf @@ -0,0 +1,2 @@ +CONFIG_LOG=y +CONFIG_ADC=y diff --git a/samples/shields/lmp90100_evb/rtd/sample.yaml b/samples/shields/lmp90100_evb/rtd/sample.yaml new file mode 100644 index 00000000000..b9ba32cf7d2 --- /dev/null +++ b/samples/shields/lmp90100_evb/rtd/sample.yaml @@ -0,0 +1,9 @@ +sample: + description: Demonstration of the LMP90100 EVB with RTD sensor + name: LMP90100 EVB RTD +tests: + sample.shields.lmp90100_evb.rtd: + platform_whitelist: frdm_k64f + harness: shield + tags: shield + depends_on: arduino_spi diff --git a/samples/shields/lmp90100_evb/rtd/src/main.c b/samples/shields/lmp90100_evb/rtd/src/main.c new file mode 100644 index 00000000000..6b5d297971b --- /dev/null +++ b/samples/shields/lmp90100_evb/rtd/src/main.c @@ -0,0 +1,99 @@ +/* + * Copyright (c) 2019 Vestas Wind Systems A/S + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#include +#include +#include +#include + +#define LOG_LEVEL CONFIG_LOG_DEFAULT_LEVEL +#include +LOG_MODULE_REGISTER(main); + +#define RTD_NOMINAL_RESISTANCE 100 + +static double sqrt(double value) +{ + double sqrt = value / 3; + int i; + + if (value <= 0) { + return 0; + } + + for (i = 0; i < 6; i++) { + sqrt = (sqrt + value / sqrt) / 2; + } + + return sqrt; +} + +static double rtd_temperature(int nom, double resistance) +{ + double a0 = 3.90802E-3; + double b0 = -0.58020E-6; + double temp; + + temp = -nom * a0; + temp += sqrt((nom * nom) * (a0 * a0) - 4.0 * nom * b0 * + (nom - resistance)); + temp /= 2.0 * nom * b0; + + return temp; +} + +void main(void) +{ + struct device *lmp90100; + double resistance; + s32_t buffer; + int err; + const struct adc_channel_cfg ch_cfg = { + .channel_id = 0, + .differential = 1, + .input_positive = 0, + .input_negative = 1, + .reference = ADC_REF_EXTERNAL1, + .gain = ADC_GAIN_1, + .acquisition_time = ADC_ACQ_TIME(ADC_ACQ_TIME_TICKS, 0) + }; + const struct adc_sequence seq = { + .options = NULL, + .channels = BIT(0), + .buffer = &buffer, + .buffer_size = sizeof(buffer), + .resolution = 24, + .oversampling = 0, + .calibrate = 0 + }; + + lmp90100 = device_get_binding(DT_INST_0_TI_LMP90100_LABEL); + if (!lmp90100) { + LOG_ERR("LMP90100 device not found"); + return; + } + + err = adc_channel_setup(lmp90100, &ch_cfg); + if (err) { + LOG_ERR("failed to setup ADC channel (err %d)", err); + return; + } + + while (true) { + err = adc_read(lmp90100, &seq); + if (err) { + LOG_ERR("failed to read ADC (err %d)", err); + return; + } + + resistance = (buffer / 8388608.0) * 2000; + printf("R: %.02f ohm\n", resistance); + printf("T: %.02f degC\n", + rtd_temperature(RTD_NOMINAL_RESISTANCE, resistance)); + + k_sleep(1000); + } +}