<?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 implementation for three pins to get data at the same time.</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/62793/saadc-implementation-for-three-pins-to-get-data-at-the-same-time</link><description>Hello, 
 I am working with nRF52DK, I am trying to implement grouped SAADC for three sensors, 
 I want to receive all three ADC outputs at the same time on development kit, 
 I have tried with individual implementation and it&amp;#39;s working fine but not getting</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Mon, 22 Jun 2020 08:50:09 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/62793/saadc-implementation-for-three-pins-to-get-data-at-the-same-time" /><item><title>RE: SAADC implementation for three pins to get data at the same time.</title><link>https://devzone.nordicsemi.com/thread/256128?ContentTypeID=1</link><pubDate>Mon, 22 Jun 2020 08:50:09 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:17280ea2-feb3-41bf-8b94-0d35a9f831f6</guid><dc:creator>Karl Ylvisaker</dc:creator><description>&lt;p&gt;Hello Jaydip,&lt;br /&gt;&lt;br /&gt;I am happy to hear that you were able to implement the functionality you had in mind.&lt;/p&gt;
[quote userid="91253" url="~/f/nordic-q-a/62793/saadc-implementation-for-three-pins-to-get-data-at-the-same-time/256032"]Again thanks for your time.[/quote][quote userid="91253" url="~/f/nordic-q-a/62793/saadc-implementation-for-three-pins-to-get-data-at-the-same-time/256032"]Thanks for your reply,[/quote]
&lt;p&gt;No problem at all, I am happy to help!&lt;br /&gt;&lt;br /&gt;Please do not hesitate to open a new ticket if you should encounter any issues or questions in the future.&lt;br /&gt;&lt;br /&gt;Good luck with your development!&lt;br /&gt;&lt;br /&gt;Best regards,&lt;br /&gt;Karl&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: SAADC implementation for three pins to get data at the same time.</title><link>https://devzone.nordicsemi.com/thread/256032?ContentTypeID=1</link><pubDate>Sat, 20 Jun 2020 13:15:58 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:f0938b8a-0363-4efd-8ace-1c20777131e2</guid><dc:creator>Jaydipsinh440</dc:creator><description>&lt;p&gt;Hello Karl,&lt;/p&gt;
&lt;p&gt;Thanks for your reply,&lt;/p&gt;
&lt;p&gt;I have changed the code that you&amp;#39;ve suggested, It was my mistake I have used wrong reference, This is working for me.&lt;/p&gt;
&lt;p&gt;Again thanks for your time.&lt;/p&gt;
&lt;p&gt;regards,&lt;/p&gt;
&lt;p&gt;Jaydip&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: SAADC implementation for three pins to get data at the same time.</title><link>https://devzone.nordicsemi.com/thread/255976?ContentTypeID=1</link><pubDate>Fri, 19 Jun 2020 12:58:02 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:e1234e8e-a891-46b5-aee9-e329d1723e89</guid><dc:creator>Karl Ylvisaker</dc:creator><description>&lt;p&gt;Hello Jaydip,&lt;/p&gt;
[quote user="Jaydipsinh440"]Thanks for your reply[/quote]
&lt;p&gt;&amp;nbsp;No problem at all, I am happy to help!&lt;/p&gt;
[quote user="Jaydipsinh440"]so here every time one channel is being sampled other uninitialized.[/quote][quote user="Jaydipsinh440"]please suggest what&amp;#39;s wrong with this implementations to&amp;nbsp;receive&amp;nbsp;SAADC measurements from three pins every time I conduct a sampling.[/quote]
&lt;p&gt;Why do you unit the channels? &lt;br /&gt;If I understood you correctly in your previous post, then this is not what you would like to do. Instead, you should during your saadc_init do nrf_drv_saadc_channel_init three times - one for each channel.&lt;br /&gt;Since only one channel is initialized at the time, there will only be samples available for that one channel each time it is sampled.&amp;nbsp;&lt;/p&gt;
[quote user="Jaydipsinh440"]I would like them to be sampled by using manual call[/quote]
&lt;p&gt;Then you will need to call the&amp;nbsp;&lt;a href="https://infocenter.nordicsemi.com/index.jsp?topic=%2Fsdk_nrf5_v16.0.0%2Fgroup__nrfx__saadc.html&amp;amp;anchor=gaf117e087540c455a6dfe05f258d118f0"&gt;nrfx_saadc_sample&lt;/a&gt;&amp;nbsp;function somewhere in your code. &lt;br /&gt;Bear in mind that sampling by function call will require CPU intervention at each sampling.&lt;/p&gt;
&lt;p&gt;Best regards,&lt;br /&gt;Karl&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: SAADC implementation for three pins to get data at the same time.</title><link>https://devzone.nordicsemi.com/thread/255966?ContentTypeID=1</link><pubDate>Fri, 19 Jun 2020 12:19:45 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:11f139a0-d9fd-462d-8d64-4b09c9b4f6c9</guid><dc:creator>Jaydipsinh440</dc:creator><description>&lt;p&gt;Hello Karl,&lt;/p&gt;
&lt;p&gt;Thanks for your reply, you understood correctly, I want to receive&amp;nbsp;&lt;span&gt;SAADC measurements from three pins every time I conduct a sampling.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;I have already implemented three channel configurations and initialization based on peripheral example and some references.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;I am attaching my implementation of SAADC here.&lt;pre class="ui-code" data-mode="c_cpp"&gt;#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;

static uint8_t                     m_adc_channel_enabled; 
static nrf_saadc_channel_config_t  channel_0_config;
static nrf_saadc_channel_config_t  channel_1_config;
static nrf_saadc_channel_config_t  channel_2_config;

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, NULL, timer_handler);
    APP_ERROR_CHECK(err_code);

    /* setup m_timer for compare event every 40ms */
    uint32_t ticks = nrf_drv_timer_ms_to_ticks(&amp;amp;m_timer, 40);
    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)
    {
        static ret_code_t err_code;
			
        if(m_adc_channel_enabled == 0)
	{
          err_code = nrf_drv_saadc_channel_uninit(0);
          APP_ERROR_CHECK(err_code);
          err_code = nrf_drv_saadc_channel_init(1, &amp;amp;channel_1_config);
          APP_ERROR_CHECK(err_code);
          m_adc_channel_enabled = 1;
	}
	else if(m_adc_channel_enabled == 1)
	{
          err_code = nrf_drv_saadc_channel_uninit(1);
          APP_ERROR_CHECK(err_code);
          err_code = nrf_drv_saadc_channel_init(2, &amp;amp;channel_2_config);
          APP_ERROR_CHECK(err_code);
          m_adc_channel_enabled = 2;
	}
	else if(m_adc_channel_enabled == 2)
	{
          err_code = nrf_drv_saadc_channel_uninit(2);
          APP_ERROR_CHECK(err_code);
          err_code = nrf_drv_saadc_channel_init(0, &amp;amp;channel_0_config);
          APP_ERROR_CHECK(err_code);
          m_adc_channel_enabled = 0;
	}
     
        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);
	NRF_LOG_INFO(&amp;quot;Channel %d value: %d\r\n&amp;quot;, m_adc_channel_enabled, p_event-&amp;gt;data.done.p_buffer[i]);
        m_adc_evt_counter++;
    }
}


void saadc_init(void)
{
    ret_code_t err_code;
		//set configuration for saadc channel 0
		channel_0_config.resistor_p = NRF_SAADC_RESISTOR_DISABLED;
    channel_0_config.resistor_n = NRF_SAADC_RESISTOR_DISABLED;
    channel_0_config.gain       = NRF_SAADC_GAIN1_6;
    channel_0_config.reference  = NRF_SAADC_REFERENCE_INTERNAL;
    channel_0_config.acq_time   = NRF_SAADC_ACQTIME_20US;
    channel_0_config.mode       = NRF_SAADC_MODE_SINGLE_ENDED;
    channel_0_config.pin_p      = (nrf_saadc_input_t)(NRF_SAADC_INPUT_AIN0);
    channel_0_config.pin_n      = NRF_SAADC_INPUT_DISABLED;
		
		//set configuration for saadc channel 1
		channel_1_config.resistor_p = NRF_SAADC_RESISTOR_DISABLED;
    channel_1_config.resistor_n = NRF_SAADC_RESISTOR_DISABLED;
    channel_1_config.gain       = NRF_SAADC_GAIN1_6;
    channel_1_config.reference  = NRF_SAADC_REFERENCE_INTERNAL;
    channel_1_config.acq_time   = NRF_SAADC_ACQTIME_20US;
    channel_1_config.mode       = NRF_SAADC_MODE_SINGLE_ENDED;
    channel_1_config.pin_p      = (nrf_saadc_input_t)(NRF_SAADC_INPUT_AIN1);
    channel_1_config.pin_n      = NRF_SAADC_INPUT_DISABLED;

		//set configuration for saadc channel 2
		channel_2_config.resistor_p = NRF_SAADC_RESISTOR_DISABLED;
    channel_2_config.resistor_n = NRF_SAADC_RESISTOR_DISABLED;
    channel_2_config.gain       = NRF_SAADC_GAIN1_6;
    channel_2_config.reference  = NRF_SAADC_REFERENCE_INTERNAL;
    channel_2_config.acq_time   = NRF_SAADC_ACQTIME_20US;
    channel_2_config.mode       = NRF_SAADC_MODE_SINGLE_ENDED;
    channel_2_config.pin_p      = (nrf_saadc_input_t)(NRF_SAADC_INPUT_AIN2);
    channel_2_config.pin_n      = NRF_SAADC_INPUT_DISABLED;

    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_0_config);
    APP_ERROR_CHECK(err_code);
    m_adc_channel_enabled = 0;

    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);

    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();
    }
}
&lt;/pre&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;I would like them to be sampled by using manual call, currently it&amp;#39;s being sampled periodically with 40ms period.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;so here every time one channel is being sampled other uninitialized.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;please suggest what&amp;#39;s wrong with this implementations to&amp;nbsp;receive&amp;nbsp;SAADC measurements from three pins every time I conduct a sampling.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Thanks and regards,&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Jaydip&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: SAADC implementation for three pins to get data at the same time.</title><link>https://devzone.nordicsemi.com/thread/255920?ContentTypeID=1</link><pubDate>Fri, 19 Jun 2020 09:17:50 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:8b6248e2-1d23-45cb-ba1f-73c726f1114d</guid><dc:creator>Karl Ylvisaker</dc:creator><description>&lt;p&gt;Hello Jaydip,&lt;br /&gt;&lt;br /&gt;Just to make sure I understand you correctly, you would like to receive SAADC measurements from three pins every time you conduct a sampling - is this correct?&amp;nbsp;&lt;br /&gt;In this case, you could need to use the &lt;a href="https://infocenter.nordicsemi.com/index.jsp?topic=%2Fcom.nordic.infocenter.nrf52832.ps.v1.1%2Fsaadc.html&amp;amp;anchor=saadc_frontpage"&gt;SAADC in scan mode&lt;/a&gt;&amp;nbsp;- to do this you would have to configure 3 SAADC channels in your saadc init.&lt;br /&gt;For example, if you take a look at the&amp;nbsp;&lt;a href="https://infocenter.nordicsemi.com/topic/sdk_nrf5_v16.0.0/nrf_dev_saadc_example.html"&gt;SAADC peripheral example&lt;/a&gt;&amp;nbsp;you will need to duplicate the channel configuration and initialization, to sample more channels at once.&lt;br /&gt;&lt;br /&gt;Could you tell me how often you intend for them to be sampled - will it be a periodic sampling, or one based on an interrupt, or a manual call to the sampling function somewhere in your code?&lt;br /&gt;&lt;br /&gt;&lt;/p&gt;
[quote userid="91253" url="~/f/nordic-q-a/62793/saadc-implementation-for-three-pins-to-get-data-at-the-same-time"]I have tried with individual implementation and it&amp;#39;s working fine but not getting outputs on ADC channels at the same time.[/quote]
&lt;p&gt;Please elaborate on what you mean when you say that it is working fine, but you are not receiving any ADC samples.&lt;br /&gt;&lt;br /&gt;Best regards,&lt;br /&gt;Karl&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>