samples: shields: lmp90100_evb: add rtd sample
Add sample for reading the temperature of a 3-wire PT100 sensor using the Texas Instruments LMP90100 Sensor Analog Frontend (AFE) Evaluation Board (EVB) shield. Signed-off-by: Henrik Brix Andersen <hebad@vestas.com>
This commit is contained in:
parent
ade6bb24e8
commit
105dc72dff
7 changed files with 194 additions and 0 deletions
10
samples/shields/lmp90100_evb/lmp90100_evb.rst
Normal file
10
samples/shields/lmp90100_evb/lmp90100_evb.rst
Normal file
|
@ -0,0 +1,10 @@
|
|||
.. _shields-lmp90100_evb-samples:
|
||||
|
||||
LMP90100 Sensor AFE Evaluation Board Shield Samples
|
||||
###################################################
|
||||
|
||||
.. toctree::
|
||||
:maxdepth: 1
|
||||
:glob:
|
||||
|
||||
**/*
|
12
samples/shields/lmp90100_evb/rtd/CMakeLists.txt
Normal file
12
samples/shields/lmp90100_evb/rtd/CMakeLists.txt
Normal file
|
@ -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})
|
53
samples/shields/lmp90100_evb/rtd/README.rst
Normal file
53
samples/shields/lmp90100_evb/rtd/README.rst
Normal file
|
@ -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
|
9
samples/shields/lmp90100_evb/rtd/app.overlay
Normal file
9
samples/shields/lmp90100_evb/rtd/app.overlay
Normal file
|
@ -0,0 +1,9 @@
|
|||
/*
|
||||
* Copyright (c) 2019 Vestas Wind Systems A/S
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
&lmp90100 {
|
||||
rtd-current = <1000>;
|
||||
};
|
2
samples/shields/lmp90100_evb/rtd/prj.conf
Normal file
2
samples/shields/lmp90100_evb/rtd/prj.conf
Normal file
|
@ -0,0 +1,2 @@
|
|||
CONFIG_LOG=y
|
||||
CONFIG_ADC=y
|
9
samples/shields/lmp90100_evb/rtd/sample.yaml
Normal file
9
samples/shields/lmp90100_evb/rtd/sample.yaml
Normal file
|
@ -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
|
99
samples/shields/lmp90100_evb/rtd/src/main.c
Normal file
99
samples/shields/lmp90100_evb/rtd/src/main.c
Normal file
|
@ -0,0 +1,99 @@
|
|||
/*
|
||||
* Copyright (c) 2019 Vestas Wind Systems A/S
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#include <zephyr.h>
|
||||
#include <device.h>
|
||||
#include <drivers/adc.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#define LOG_LEVEL CONFIG_LOG_DEFAULT_LEVEL
|
||||
#include <logging/log.h>
|
||||
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);
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue