<?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>nRF51 ADC example confusion</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/19004/nrf51-adc-example-confusion</link><description>I&amp;#39;m using the ble_app_hrs_adc_battery_measurement example ADC code in my project 
 However, I don&amp;#39;t understand what these lines do 
 github.com/.../main.c 
 As far as I can tell, the while loop seems to call nrf_drv_adc_sample() for the number of samples</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Wed, 18 Jan 2017 11:26:30 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/19004/nrf51-adc-example-confusion" /><item><title>RE: nRF51 ADC example confusion</title><link>https://devzone.nordicsemi.com/thread/73449?ContentTypeID=1</link><pubDate>Wed, 18 Jan 2017 11:26:30 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:74a30aa6-6131-41f7-b898-2b881bcdefff</guid><dc:creator>J&amp;#248;rgen Holmefjord</dc:creator><description>&lt;p&gt;From the documentation: &lt;em&gt;If more than one channel is enabled, the function emulates scanning, and a single START task will trigger conversion on all enabled channels. For example: If 3 channels are enabled and the user requests 6 samples, the completion event handler will be called after 2 START tasks.&lt;/em&gt; If you want the done event to be called for each sample, you should set the buffer to 1. The point of the buffer is to limit the number of times you have to handle the data.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nRF51 ADC example confusion</title><link>https://devzone.nordicsemi.com/thread/73452?ContentTypeID=1</link><pubDate>Tue, 17 Jan 2017 22:49:27 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:e12583f0-b23b-4a65-bbdb-09cc0c76b057</guid><dc:creator>Roger Clark</dc:creator><description>&lt;p&gt;Can you clarify.&lt;/p&gt;
&lt;p&gt;If ADC_BUFFER_SIZE = 6 and I do this (much code omitted)&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;nrf_drv_adc_init(&amp;amp;adc_config, adc_event_handler); //Initialize the ADC

nrf_drv_adc_buffer_convert(adc_buffer, ADC_BUFFER_SIZE);

nrf_drv_adc_sample(); 
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Does adc_event_handler get called when the ADC has finished sampling, or does
nrf_drv_adc_sample() need to be called for 6 times (in this case), before adc_event_handler gets called ?&lt;/p&gt;
&lt;p&gt;Looking at the example code, it looks like adc_event_handler does not get called until adc_buffer is full, which requires multiple calls to nrf_drv_adc_sample&lt;/p&gt;
&lt;p&gt;Thanks&lt;/p&gt;
&lt;p&gt;Roger&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nRF51 ADC example confusion</title><link>https://devzone.nordicsemi.com/thread/73451?ContentTypeID=1</link><pubDate>Tue, 17 Jan 2017 20:00:55 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:873fa1e0-5a6a-49f2-a42e-0d313e316257</guid><dc:creator>J&amp;#248;rgen Holmefjord</dc:creator><description>&lt;p&gt;You only need to check if the ADC is busy before calling nrf_drv_adc_sample(). The best solution depends on what you are using the ADC for. Often a combination of a timer and a PPI task triggering the sampling, as described in the &lt;a href="http://infocenter.nordicsemi.com/topic/com.nordic.infocenter.sdk5.v12.2.0/hardware_driver_adc.html?cp=4_0_1_2_0_1#hardware_driver_adc_using"&gt;ADC driver documentaion&lt;/a&gt; of the SDK, is a good solution.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nRF51 ADC example confusion</title><link>https://devzone.nordicsemi.com/thread/73450?ContentTypeID=1</link><pubDate>Mon, 16 Jan 2017 21:23:06 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:6feae985-a8de-486d-8b43-31c663fa6011</guid><dc:creator>Roger Clark</dc:creator><description>&lt;p&gt;Thanks Jørgen&lt;/p&gt;
&lt;p&gt;Are you saying that elsewhere in my code I would need to keep checking if the ADC is busy (from time to time)?&lt;/p&gt;
&lt;p&gt;Ideally, when each ADC conversion was complete, a callback would be called, and the callback could thencall nrf_drv_adc_sample().&lt;/p&gt;
&lt;p&gt;However, as far as I can tell, the call to nrf_drv_adc_buffer_convert(adc_buffer, ADC_BUFFER_SIZE); seems to change the mode of operation, so that the callback only occurs when the ADC has completely filled the buffer.&lt;/p&gt;
&lt;p&gt;Perhaps the more efficient way to do this, is set the buffer size to 1, so that perhaps the callback is called after each sample. Then in the callback, store the sample in a buffer and if the buffer is not full, then call nrf_drv_adc_sample() again.&lt;/p&gt;
&lt;p&gt;But I know that some ADC drv funcs can only be called from the main tread, so perhaps this is not possible.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nRF51 ADC example confusion</title><link>https://devzone.nordicsemi.com/thread/73448?ContentTypeID=1</link><pubDate>Mon, 16 Jan 2017 11:39:19 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:aec71374-7281-49f5-9948-0a51c83eb2d2</guid><dc:creator>J&amp;#248;rgen Holmefjord</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;It is not possible to start the sampling task if the ADC is busy. This loop is just added to not start the task until the ADC is available. In the implementation of &lt;code&gt;nrf_drv_adc_sample()&lt;/code&gt;, there is an assert that checks that the ADC is not busy before starting the task. The call to &lt;code&gt;nrf_drv_adc_sample()&lt;/code&gt; is not blocking in itself, but calling it while the ADC is busy will cause the assert to fire. You could remove this while loop to do other tasks while the sampling is performed, and start the next sample at a later stage. Notice that a check whether the ADC is busy would still be needed before calling &lt;code&gt;nrf_drv_adc_sample()&lt;/code&gt;, to avoid firing the assert.&lt;/p&gt;
&lt;p&gt;Best regards,&lt;/p&gt;
&lt;p&gt;Jørgen&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>