<?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>How to identify adc value from its adc channel?</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/59017/how-to-identify-adc-value-from-its-adc-channel</link><description>I use nRF52840 and SDK16 with S140 softdevice. I need 3 ADC ports. The initial code as follows. 
 static void adc_configure(void) { ret_code_t err_code = nrf_drv_saadc_init(NULL, saadc_event_handler); APP_ERROR_CHECK(err_code); nrf_saadc_channel_config_t</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Mon, 16 Mar 2020 01:26:34 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/59017/how-to-identify-adc-value-from-its-adc-channel" /><item><title>RE: How to identify adc value from its adc channel?</title><link>https://devzone.nordicsemi.com/thread/239857?ContentTypeID=1</link><pubDate>Mon, 16 Mar 2020 01:26:34 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:8c74cf4c-f9c6-4961-b02f-1cb6b07e862f</guid><dc:creator>Ted</dc:creator><description>&lt;p&gt;&lt;a href="https://devzone.nordicsemi.com/members/edvin-holmseth"&gt;Edvin&lt;/a&gt; Thank you very much.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to identify adc value from its adc channel?</title><link>https://devzone.nordicsemi.com/thread/239684?ContentTypeID=1</link><pubDate>Fri, 13 Mar 2020 10:35:33 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:499f6798-8f0d-4a40-b89c-d06a5bb7f4fe</guid><dc:creator>Edvin</dc:creator><description>&lt;p&gt;That is not possible with the ADC. You must then sample all 3 every 50µs.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;That is at least almost true. You can uninit and init the AIN1 only when you want to sample it, but I don&amp;#39;t think that is any more power efficient than just sampling AIN1, and discard it later, than doing changes to it all the time. Also, you would have to be very careful, what buffer item belongs to what channel when you add and remove AIN1.&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to identify adc value from its adc channel?</title><link>https://devzone.nordicsemi.com/thread/239622?ContentTypeID=1</link><pubDate>Fri, 13 Mar 2020 01:49:58 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:71ee1aaa-8abf-4a8e-9460-a5941f7bcbe2</guid><dc:creator>Ted</dc:creator><description>&lt;p&gt;&lt;a href="https://devzone.nordicsemi.com/members/edvin-holmseth"&gt;Edvin&lt;/a&gt;Thank you very much. Another question.&amp;nbsp;How to sample&amp;nbsp;ADC at different times? For example, I want to sample ADC at&amp;nbsp;&lt;span&gt;NRF_SAADC_INPUT_AIN1 once 2 seconds.&amp;nbsp;sample ADC at&amp;nbsp;NRF_SAADC_INPUT_AIN0 and&amp;nbsp;NRF_SAADC_INPUT_AIN4&amp;nbsp; once 50us.&amp;nbsp;&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to identify adc value from its adc channel?</title><link>https://devzone.nordicsemi.com/thread/239560?ContentTypeID=1</link><pubDate>Thu, 12 Mar 2020 14:17:25 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:a558d395-6b21-400d-bb1c-359d93ebbb33</guid><dc:creator>Edvin</dc:creator><description>&lt;p&gt;Hello,&lt;/p&gt;
&lt;p&gt;I see that you print using the p_event-&amp;gt;data.limit.channel, but I suspect that this is not a limit event. You can check this like this:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;void saadc_callback(nrf_drv_saadc_evt_t const * p_event)
{
    if (p_event-&amp;gt;type == NRF_DRV_SAADC_EVT_LIMIT)
    {
        NRF_LOG_INFO(&amp;quot;reached limit on channel %d&amp;quot;, p_evt-&amp;gt;data.limit.channel);
        return;
    }
    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;
        NRF_LOG_INFO(&amp;quot;ADC event number: %d&amp;quot;, (int)m_adc_evt_counter);

        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]);
        }
        m_adc_evt_counter++;
    }
}&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;You can&amp;#39;t use the p_evt-&amp;gt;data.limit. ... pointer if the event is not a NRFX_SAADC_EVT_LIMIT event, but a&amp;nbsp;NRFX_SAADC_EVT_DONE event. In that case, the data in this pointer is not what you think it is.&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;So in the &amp;quot;normal&amp;quot; event callbacks, you don&amp;#39;t have a field saying what channel the measurements come from. But they will always come in the order of the channels. This is why you should have&amp;nbsp;SAMPLES_IN_BUFFER = n*number of channels. Let us say you have 3 channels, and n=1, then SAMPLES_IN_BUFFER should be 3.&lt;/p&gt;
&lt;p&gt;If so, then p_buffer[0] will always belong to channel 0, buffer[1] to channel 1 and buffer[2] to channel 2.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;If you set SAMPLES_IN_BUFFER = 4, then in the first event:&lt;/p&gt;
&lt;p&gt;buffer[0] belongs to channel 0,&lt;br /&gt;buffer[1] belongs to channel 1,&lt;br /&gt;buffer[2] belongs to channel 2,&lt;br /&gt;buffer[3] belongs to channel 0&lt;/p&gt;
&lt;p&gt;But in the next event, this will be shifted by one:&lt;/p&gt;
&lt;p&gt;&lt;span&gt;buffer[0] belongs to channel 1,&lt;br /&gt;buffer[1] belongs to channel 2,&lt;br /&gt;buffer[2] belongs to channel 0,&lt;br /&gt;buffer[3] belongs to channel 1,&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;This is because the channels are sampled in the order of the channels, but the buffer isn&amp;#39;t aware of how many channels that are in use.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Best regards,&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Edvin&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>