<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="https://devzone.nordicsemi.com/cfs-file/__key/system/syndication/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>SAADC samples the same as ground value for LM35 sensor.</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/47594/saadc-samples-the-same-as-ground-value-for-lm35-sensor</link><description>Hi, I&amp;#39;m running the saddc_pca10056 peripheral example given in SDK v15.2.0. 
 The analogue pin A0 is connected to the signal line of an LM35 temperature sensor. When I measure the voltage of the pin it increases from 300mV to 320mV when touched. The noise</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Tue, 28 May 2019 08:54:20 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/47594/saadc-samples-the-same-as-ground-value-for-lm35-sensor" /><item><title>RE: SAADC samples the same as ground value for LM35 sensor.</title><link>https://devzone.nordicsemi.com/thread/189512?ContentTypeID=1</link><pubDate>Tue, 28 May 2019 08:54:20 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:094792fb-48f0-4e7a-9f9b-a65d1b6a6675</guid><dc:creator>haakonsh</dc:creator><description>&lt;p&gt;Then you&amp;#39;ve most likely blown the ESD diode on that pin since you&amp;#39;ve applied a voltage higher than VDD + 0.3V.&amp;nbsp;&lt;br /&gt;&lt;br /&gt;I suggest you try another analog input, this time you need to make sure that you&amp;#39;re&amp;nbsp;applying a voltage that&amp;#39;s within the specification of the device.&amp;nbsp;&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: SAADC samples the same as ground value for LM35 sensor.</title><link>https://devzone.nordicsemi.com/thread/189386?ContentTypeID=1</link><pubDate>Mon, 27 May 2019 14:45:30 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:6f6644d7-a196-4ef0-b4f9-552a82d7d10f</guid><dc:creator>TrebleStick</dc:creator><description>&lt;p&gt;It&amp;#39;s 3V&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: SAADC samples the same as ground value for LM35 sensor.</title><link>https://devzone.nordicsemi.com/thread/189384?ContentTypeID=1</link><pubDate>Mon, 27 May 2019 14:42:49 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:88565995-4bc0-4f3f-aa2a-457ebb8d390c</guid><dc:creator>haakonsh</dc:creator><description>&lt;p&gt;What voltage is VDD at?&lt;/p&gt;
&lt;p&gt;You&amp;#39;ve probably exceeded the maximum rated voltage for the gpio, and consequently blown an ESD fuse.&amp;nbsp;&lt;br /&gt;See I/O pin voltage in&amp;nbsp;&lt;a title="Absolute maximum ratings" href="https://infocenter.nordicsemi.com/topic/ps_nrf52840/abs_max_ratings.html?cp=3_0_0_8"&gt;Absolute maximum ratings&lt;/a&gt;.&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: SAADC samples the same as ground value for LM35 sensor.</title><link>https://devzone.nordicsemi.com/thread/189143?ContentTypeID=1</link><pubDate>Sun, 26 May 2019 12:13:16 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:424fb197-6684-483a-a6af-042df5531ba5</guid><dc:creator>TrebleStick</dc:creator><description>&lt;p&gt;Measuring a proper bench voltage source varying it from 0-5V produced some strange results. Regardless of the configuration of the SAADC channel, reading only changed when input voltage exceeded 3.65V. This either maxed out the reading or put it within a range (depending on the gain and reference voltage) that is usable to detect voltage change from 3.7V+. Any ideas why this might be the case? It sounds like a hardware issue to me.&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;I am using the development board so power is supplied by USB and taking the 0-5V rails to power the temperature sensor, it&amp;#39;s a very simple sensor and the measured signal from that on both volt meter and oscilloscope comes out as expected.&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: SAADC samples the same as ground value for LM35 sensor.</title><link>https://devzone.nordicsemi.com/thread/188837?ContentTypeID=1</link><pubDate>Thu, 23 May 2019 13:15:19 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:855783b8-a6ba-4ab0-8765-2696e740b954</guid><dc:creator>haakonsh</dc:creator><description>&lt;p&gt;I suggest you use the SAADC to measure a proper voltage source first. This will tell you if&amp;nbsp;there&amp;#39;s noise in the SAADC or if it&amp;#39;s in the temperature sensor&amp;#39;s signal.&amp;nbsp;&lt;br /&gt;&lt;br /&gt;You should also check your power supply and make sure that you adhere to the reference design of the nRF52 and the temperature sensor&amp;#39;s.&amp;nbsp;&lt;br /&gt;&lt;br /&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: SAADC samples the same as ground value for LM35 sensor.</title><link>https://devzone.nordicsemi.com/thread/188659?ContentTypeID=1</link><pubDate>Wed, 22 May 2019 19:57:36 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:2f8b4587-6206-4ba0-a0f8-944929956d5e</guid><dc:creator>TrebleStick</dc:creator><description>&lt;p&gt;Hi, thank you for the suggestions:&lt;/p&gt;
&lt;p&gt;1. I added the offset calibration to start up, the values coming through average at about 80 for the first reading and then return to the usual values around 1900. For calibrating every second degree Celsius change in temperature: Firstly&amp;nbsp;&lt;span style="font-family:inherit;"&gt;if the ADC can&amp;#39;t detect the temperature change &lt;/span&gt;because&lt;span style="font-family:inherit;"&gt;&amp;nbsp;of the noise how would you be able to trigger such an event? Secondly would this mean &lt;/span&gt;uninitialising&amp;nbsp;and reinitialising the ADC? Running calibration will not work unless the ADC is idle&lt;/p&gt;
&lt;p&gt;2. This was already implemented before, forgot to mention.&lt;/p&gt;
&lt;p&gt;3. I tried 16x oversampling onwards along side a resolution of 14-bits (as is suggested in the documentation) and there was no difference in results apart from the expected slow down as oversampling increased.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Thanks in advance :)&amp;nbsp;&lt;/p&gt;
&lt;p&gt;*EDIT* - code followed by debug prints below&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;/**
 * Copyright (c) 2014 - 2018, Nordic Semiconductor ASA
 *
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without modification,
 * are permitted provided that the following conditions are met:
 *
 * 1. Redistributions of source code must retain the above copyright notice, this
 *    list of conditions and the following disclaimer.
 *
 * 2. Redistributions in binary form, except as embedded into a Nordic
 *    Semiconductor ASA integrated circuit in a product or a software update for
 *    such product, must reproduce the above copyright notice, this list of
 *    conditions and the following disclaimer in the documentation and/or other
 *    materials provided with the distribution.
 *
 * 3. Neither the name of Nordic Semiconductor ASA nor the names of its
 *    contributors may be used to endorse or promote products derived from this
 *    software without specific prior written permission.
 *
 * 4. This software, with or without modification, must only be used with a
 *    Nordic Semiconductor ASA integrated circuit.
 *
 * 5. Any software provided in binary form under this license must not be reverse
 *    engineered, decompiled, modified and/or disassembled.
 *
 * THIS SOFTWARE IS PROVIDED BY NORDIC SEMICONDUCTOR ASA &amp;quot;AS IS&amp;quot; AND ANY EXPRESS
 * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
 * OF MERCHANTABILITY, NONINFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE ARE
 * DISCLAIMED. IN NO EVENT SHALL NORDIC SEMICONDUCTOR ASA OR CONTRIBUTORS BE
 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
 * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 *
 */
/** @file
 * @defgroup nrf_adc_example main.c
 * @{
 * @ingroup nrf_adc_example
 * @brief ADC Example Application main file.
 *
 * This file contains the source code for a sample application using ADC.
 *
 * @image html example_board_setup_a.jpg &amp;quot;Use board setup A for this example.&amp;quot;
 */

#include &amp;lt;stdbool.h&amp;gt;
#include &amp;lt;stdint.h&amp;gt;
#include &amp;lt;stdio.h&amp;gt;
#include &amp;lt;string.h&amp;gt;
#include &amp;quot;nrf.h&amp;quot;
#include &amp;quot;nrf_drv_saadc.h&amp;quot;
#include &amp;quot;nrf_drv_ppi.h&amp;quot;
#include &amp;quot;nrf_drv_timer.h&amp;quot;
#include &amp;quot;boards.h&amp;quot;
#include &amp;quot;app_error.h&amp;quot;
#include &amp;quot;nrf_delay.h&amp;quot;
#include &amp;quot;app_util_platform.h&amp;quot;
#include &amp;quot;nrf_pwr_mgmt.h&amp;quot;

#include &amp;quot;nrf_log.h&amp;quot;
#include &amp;quot;nrf_log_ctrl.h&amp;quot;
#include &amp;quot;nrf_log_default_backends.h&amp;quot;

#define SAMPLES_IN_BUFFER 5
volatile uint8_t state = 1;

static const nrf_drv_timer_t m_timer = NRF_DRV_TIMER_INSTANCE(0);
static nrf_saadc_value_t     m_buffer_pool[2][SAMPLES_IN_BUFFER];
static nrf_ppi_channel_t     m_ppi_channel;
static uint32_t              m_adc_evt_counter;


void timer_handler(nrf_timer_event_t event_type, void * p_context)
{

}


void saadc_sampling_event_init(void)
{
    ret_code_t err_code;

    err_code = nrf_drv_ppi_init();
    APP_ERROR_CHECK(err_code);

    nrf_drv_timer_config_t timer_cfg = NRF_DRV_TIMER_DEFAULT_CONFIG;
    timer_cfg.bit_width = NRF_TIMER_BIT_WIDTH_32;
    err_code = nrf_drv_timer_init(&amp;amp;m_timer, &amp;amp;timer_cfg, timer_handler);
    APP_ERROR_CHECK(err_code);

    /* setup m_timer for compare event every 400ms */
    uint32_t ticks = nrf_drv_timer_ms_to_ticks(&amp;amp;m_timer, 400);
    nrf_drv_timer_extended_compare(&amp;amp;m_timer,
                                   NRF_TIMER_CC_CHANNEL0,
                                   ticks,
                                   NRF_TIMER_SHORT_COMPARE0_CLEAR_MASK,
                                   false);
    nrf_drv_timer_enable(&amp;amp;m_timer);

    uint32_t timer_compare_event_addr = nrf_drv_timer_compare_event_address_get(&amp;amp;m_timer,
                                                                                NRF_TIMER_CC_CHANNEL0);
    uint32_t saadc_sample_task_addr   = nrf_drv_saadc_sample_task_get();

    /* setup ppi channel so that timer compare event is triggering sample task in SAADC */
    err_code = nrf_drv_ppi_channel_alloc(&amp;amp;m_ppi_channel);
    APP_ERROR_CHECK(err_code);

    err_code = nrf_drv_ppi_channel_assign(m_ppi_channel,
                                          timer_compare_event_addr,
                                          saadc_sample_task_addr);
    APP_ERROR_CHECK(err_code);
}


void saadc_sampling_event_enable(void)
{
    ret_code_t err_code = nrf_drv_ppi_channel_enable(m_ppi_channel);

    APP_ERROR_CHECK(err_code);
}


void saadc_callback(nrf_drv_saadc_evt_t const * p_event)
{
    if (p_event-&amp;gt;type == NRF_DRV_SAADC_EVT_DONE)
    {
        ret_code_t err_code;

        err_code = nrf_drv_saadc_buffer_convert(p_event-&amp;gt;data.done.p_buffer, SAMPLES_IN_BUFFER);
        APP_ERROR_CHECK(err_code);

        int i;
        uint32_t data_average = 0;
        NRF_LOG_INFO(&amp;quot;ADC event number: %d&amp;quot;, (int)m_adc_evt_counter);
        SEGGER_RTT_printf(0, &amp;quot;ADC event: %d -&amp;gt; &amp;quot;, (int)m_adc_evt_counter); //swap for debug print

        for (i = 0; i &amp;lt; SAMPLES_IN_BUFFER; i++)
        {
            NRF_LOG_INFO(&amp;quot;%d&amp;quot;, p_event-&amp;gt;data.done.p_buffer[i]);
            SEGGER_RTT_printf(0,&amp;quot;%d:&amp;quot;, p_event-&amp;gt;data.done.p_buffer[i]); //swap for debug print
            data_average += p_event-&amp;gt;data.done.p_buffer[i];
        }
        //Produce average of the buffered data
        data_average = data_average/i+1;
        SEGGER_RTT_printf(0, &amp;quot; AVERAGE : %u\n&amp;quot;, data_average);
        
        m_adc_evt_counter++;
        
    }
}


void saadc_init(void)
{
    ret_code_t err_code;
    nrf_saadc_channel_config_t channel_config =
        NRF_DRV_SAADC_DEFAULT_CHANNEL_CONFIG_SE(NRF_SAADC_INPUT_AIN0);

    err_code = nrf_drv_saadc_init(NULL, saadc_callback);
    APP_ERROR_CHECK(err_code);

    err_code = nrf_drv_saadc_channel_init(0, &amp;amp;channel_config);
    APP_ERROR_CHECK(err_code);

    err_code = nrf_drv_saadc_buffer_convert(m_buffer_pool[0], SAMPLES_IN_BUFFER);
    APP_ERROR_CHECK(err_code);

    err_code = nrf_drv_saadc_buffer_convert(m_buffer_pool[1], SAMPLES_IN_BUFFER);
    APP_ERROR_CHECK(err_code);

}


/**
 * @brief Function for main application entry.
 */
int main(void)
{
    uint32_t err_code = NRF_LOG_INIT(NULL);
    APP_ERROR_CHECK(err_code);

    NRF_LOG_DEFAULT_BACKENDS_INIT();

    ret_code_t ret_code = nrf_pwr_mgmt_init();
    APP_ERROR_CHECK(ret_code);

    //calibrate on start up
    err_code = nrfx_saadc_calibrate_offset();
    SEGGER_RTT_printf(0, &amp;quot;Calibration Error Code %x\n&amp;quot;, err_code);
    APP_ERROR_CHECK(err_code);

    saadc_init();
    saadc_sampling_event_init();
    saadc_sampling_event_enable();
    NRF_LOG_INFO(&amp;quot;SAADC HAL simple example started.&amp;quot;);
    
    while (1)
    {
        nrf_pwr_mgmt_run();
        NRF_LOG_FLUSH();
    }
}


/** @} */







//----------debug print out from above main----------------//
Calibration Error Code 0
ADC event: 0 -&amp;gt; -69:319:130:33:-8: AVERAGE : 82
ADC event: 1 -&amp;gt; 16:1849:1847:1845:1848: AVERAGE : 1482
ADC event: 2 -&amp;gt; 1836:1858:1851:1852:1858: AVERAGE : 1852
ADC event: 3 -&amp;gt; 1852:1842:1843:1840:1841: AVERAGE : 1844
ADC event: 4 -&amp;gt; 1853:1849:1852:1841:1843: AVERAGE : 1848
ADC event: 5 -&amp;gt; 1846:1852:1837:1845:1845: AVERAGE : 1846
ADC event: 6 -&amp;gt; 1838:1845:1842:1847:1845: AVERAGE : 1844
ADC event: 7 -&amp;gt; 1853:1839:1836:1848:1850: AVERAGE : 1846
ADC event: 8 -&amp;gt; 1846:1838:1844:1852:1857: AVERAGE : 1848
ADC event: 9 -&amp;gt; 1856:1850:1859:1855:1854: AVERAGE : 1855
ADC event: 10 -&amp;gt; 1867:1860:1858:1854:1857: AVERAGE : 1860
ADC event: 11 -&amp;gt; 1849:1858:1861:1845:1842: AVERAGE : 1852&lt;/pre&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: SAADC samples the same as ground value for LM35 sensor.</title><link>https://devzone.nordicsemi.com/thread/188433?ContentTypeID=1</link><pubDate>Wed, 22 May 2019 07:43:00 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:645e156d-4243-485e-9475-4a6af5ea17c6</guid><dc:creator>haakonsh</dc:creator><description>&lt;p&gt;You should do three things:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Run offset calibration on start-up, and every second degree Celsius change in temperature.&lt;br /&gt;&lt;br /&gt;&lt;/li&gt;
&lt;li&gt;Ensure that you&amp;#39;ve configured the SAADC to sample in the correct operating range of your signal. I suggest you try a gain of 1, and use the internal 0.6V reference.&amp;nbsp;&lt;br /&gt;&lt;br /&gt;&lt;/li&gt;
&lt;li&gt;Enable oversampling of your measurement, at least 10X.&amp;nbsp;&amp;nbsp;&lt;/li&gt;
&lt;/ol&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>