<?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>Using ADC/SAADC to read data in BLE app</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/69442/using-adc-saadc-to-read-data-in-ble-app</link><description>I am currently development an app based on the example from the experimental folder using a NRF DK52 as a relay between a central and multiple peripherals. 
 The app should now react on the press of a button from an external device. The device is built</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Tue, 05 Jan 2021 10:21:27 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/69442/using-adc-saadc-to-read-data-in-ble-app" /><item><title>RE: Using ADC/SAADC to read data in BLE app</title><link>https://devzone.nordicsemi.com/thread/287456?ContentTypeID=1</link><pubDate>Tue, 05 Jan 2021 10:21:27 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:66174ce4-7411-4e2a-b7fd-ab1a46c9affb</guid><dc:creator>daubsi</dc:creator><description>&lt;p&gt;Thank you Karl, for that in-depth explanation!&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Using ADC/SAADC to read data in BLE app</title><link>https://devzone.nordicsemi.com/thread/287241?ContentTypeID=1</link><pubDate>Mon, 04 Jan 2021 13:20:52 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:cd8eb57b-2896-41c5-a76e-7cee87593c26</guid><dc:creator>Karl Ylvisaker</dc:creator><description>&lt;p&gt;Hello,&lt;br /&gt;&lt;br /&gt;Sorry for my very late reply - I was out of office due to the recent national holiday season here in Norway.&lt;/p&gt;
[quote user="daubsi"]got the LIMIT stuff working last night in a quick rush. Seems this might be what I actually need.[/quote]
&lt;p&gt;Great, I am happy to hear that!&lt;/p&gt;
[quote user="daubsi"]I modified the nRF provided SAADC example. Still not sure how to do the final version but I think I have everything on my hand.[/quote]
&lt;p&gt;As suggested by snoopy you might want to take a look at using the COMP peripheral for your limits, if it is applicable to your application needs, as this should reduce your power consumption and reaction time somewhat.&lt;br /&gt;As mentioned, there is no COMP example, but now that you are familiar with the SAADC peripheral it should be a lot easier to familiarize with &lt;a href="https://infocenter.nordicsemi.com/topic/sdk_nrf5_v17.0.2/group__nrfx__comp.html"&gt;the COMP API Reference&lt;/a&gt;.&lt;/p&gt;
[quote user="daubsi"]Also used VDD/4 as the reference instead of internal 0.6V and used the GAIN of 4 as described in the SDKs documentation.[/quote]
&lt;p&gt;This is fine since you are not measuring the battery. It is recommended to use the internal 0.6V reference when measuring the battery, since the level of the battery will skew the reference of the SAADC if you use the VDD/4 reference.&lt;/p&gt;
[quote user="daubsi"]I overlooked that big chapter on the SAADC as I just saw the library and HAL stuff but didn&amp;#39;t see the actual technical description how it is all working at all.&amp;nbsp;[/quote][quote user="daubsi"]Thanks again![/quote]
&lt;p&gt;No worries at all - It is a lot to take in when you first start working with the nRF series and the SDK.&lt;br /&gt;Please do not hesitate to ask if you should encounter any other issues or questions!&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: Using ADC/SAADC to read data in BLE app</title><link>https://devzone.nordicsemi.com/thread/285588?ContentTypeID=1</link><pubDate>Thu, 17 Dec 2020 11:21:56 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:39c1eabb-6f17-480e-b9a1-cd7e42a0ee1a</guid><dc:creator>daubsi</dc:creator><description>&lt;p&gt;Hi Karl,&lt;/p&gt;
&lt;p&gt;got the LIMIT stuff working last night in a quick rush. Seems this might be what I actually need. I modified the nRF provided SAADC example. Still not sure how to do the final version but I think I have everything on my hand. Still need to evaluate if there are any issues with my BLE app as like priority stuff etc. Also used VDD/4 as the reference instead of internal 0.6V and used the GAIN of 4 as described in the SDKs documentation. Connecting the input pin to VDD now gives me 1023 as expected and I can play with my limit values in order to find the proper thresholds, before connecting it to my actual circuit where I want to measure stuff.&lt;/p&gt;
&lt;p&gt;I overlooked that big chapter on the SAADC as I just saw the library and HAL stuff but didn&amp;#39;t see the actual technical description how it is all working at all.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;The first example I did was with a circuit of 2x1.5 AA batteries where I measures and sampled the values. I think it was there where I got 831 as the maximum reading. Seems this is then consistent.&lt;/p&gt;
&lt;p&gt;Thanks again!&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Using ADC/SAADC to read data in BLE app</title><link>https://devzone.nordicsemi.com/thread/285565?ContentTypeID=1</link><pubDate>Thu, 17 Dec 2020 10:05:31 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:23b29b5e-561e-4667-b387-4e3995715d75</guid><dc:creator>Karl Ylvisaker</dc:creator><description>[quote user="daubsi"]Dear Karl, thanks for the explanation.[/quote]
&lt;p&gt;No problem at all, I am happy to help!&lt;/p&gt;
[quote user="daubsi"]I think I understand what you&amp;#39;re saying (as said above I&amp;#39;ve little experience with the peripherals yet). [/quote]
&lt;p&gt;Great! Please do not hesitate to ask if you should encounter any issues or questions in your development! :)&amp;nbsp;&lt;/p&gt;
[quote user="daubsi"]The SAADC priority would be a setting in the sdk_config.h then?&amp;nbsp;[/quote]
&lt;p&gt;If you do not explicitly configure the SAADC IRQ priority when you initialize it, it will instead use the default IRQ priority specified in the sdk_config, correct.&lt;/p&gt;
[quote user="daubsi"]I&amp;#39;ll have a look at the LIMIT stuff. Indeed, as I am only interested in the crossing of my threshold I would not need to react/handle any other sampling value. [/quote]
&lt;p&gt;Great!&lt;br /&gt;It is also an option to use the comparators directly, as suggested by Snoopy20. You may read more about &lt;a href="https://infocenter.nordicsemi.com/index.jsp?topic=%2Fcom.nordic.infocenter.nrf52832.ps.v1.1%2Fcomp.html&amp;amp;anchor=topic"&gt;the COMP peripheral here&lt;/a&gt;.&amp;nbsp;&lt;/p&gt;
[quote user="daubsi"]There isn&amp;#39;t an example for that in the SDK, right?[/quote]
&lt;p&gt;Unfortunately, there is no LIMIT event examples in the SDK, no. However, as long as you have enabled the LIMITs you will have the event passed to your SAADC event handler - same as with the DONE event in the SAADC peripheral example.&lt;br /&gt;So, if you are to use the SAADC for this, you could start out by modifying the SAADC example to generate LIMIT events.&lt;/p&gt;
[quote user="daubsi"]Still struggling a little bit with the setup of the SAADC, e.g. the GAIN settings seem to deliver &amp;quot;830&amp;quot; at the maximum voltage of 3.3V I ran the DK with (at least I think I do? ;-) Powered via USB) instead of the expected 1023.[/quote]
&lt;p&gt;When the nRF52 DK is powered through USB the 5 V supply is regulated down to 3.3 V.&lt;br /&gt;The input range of the default SAADC is 0 - 3.6V as explained in &lt;a href="https://infocenter.nordicsemi.com/index.jsp?topic=%2Fcom.nordic.infocenter.nrf52832.ps.v1.1%2Fsaadc.html&amp;amp;anchor=concept_kxz_4pp_qr"&gt;these formulas from the SAADC Documentation&lt;/a&gt;.&lt;br /&gt;However, your measurements of 830 indicate 3 V.. Could you confirm for me that you are using an nRF52 DK ( nRF52832 SoC ), and if so, could you detail what you did exactly when measuring the 830 values?&amp;nbsp;&lt;/p&gt;
[quote user="daubsi"]I read in another thread that I need to adjust the gain level accordingly as it accounts for voltages up to 3.6V.&amp;nbsp;[/quote]
&lt;p&gt;This is correct - you could see how to do so in the link I referenced above.&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: Using ADC/SAADC to read data in BLE app</title><link>https://devzone.nordicsemi.com/thread/285426?ContentTypeID=1</link><pubDate>Wed, 16 Dec 2020 16:04:23 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:742a105a-9894-4c0d-a458-357cb9388754</guid><dc:creator>snoopy20</dc:creator><description>&lt;p&gt;The NRF52832 has two comparators, the 810 has one. A comparator continuously &amp;#39;samples&amp;#39; a voltage and triggers an event when it goes above or below a threshold level (which you can define). It should be your first choice. The ADC with the LIMIT feature is doing the same thing basically, just it&amp;#39;s slower and uses more power (if you&amp;#39;re bothered).&lt;br /&gt;&lt;br /&gt;No code here but it&amp;#39;s easy to follow the direct documentation. I only use the SDK for BLE, all other peripherals I control direct as I find the SDK is bloated and an unnecessary abstraction. If I wanted that I&amp;#39;d use Arduino.&lt;/p&gt;
&lt;p&gt;&lt;a href="https://infocenter.nordicsemi.com/index.jsp?topic=%2Fug_getting_started%2FUG%2Fgs%2Fdevelop_sw.html&amp;amp;cp=1_0_2"&gt;infocenter.nordicsemi.com/index.jsp&lt;/a&gt;&lt;/p&gt;
&lt;p class="shortdesc"&gt;The comparator (COMP) compares an input voltage (VIN+) against a second input voltage (VIN-). VIN+ can be derived from an analog input pin (AIN0-AIN7). VIN- can be derived from multiple sources depending on the operation mode of the comparator.&lt;/p&gt;
&lt;p class="p"&gt;Main features of the comparator are:&lt;/p&gt;
&lt;ul class="ul" id="topic__ul_a4b_24r_hs"&gt;
&lt;li class="li"&gt;Input range from 0 V to VDD&lt;/li&gt;
&lt;li class="li"&gt;Single-ended mode
&lt;ul class="ul" id="topic__ul_wrb_kpr_hs"&gt;
&lt;li class="li"&gt;Fully flexible hysteresis using a 64-level reference ladder&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li class="li"&gt;Differential mode
&lt;ul class="ul" id="topic__ul_syq_bqr_hs"&gt;
&lt;li class="li"&gt;Configurable 50 mV hysteresis&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li class="li"&gt;Reference inputs (VREF):
&lt;ul class="ul" id="topic__ul_u51_z4r_hs"&gt;
&lt;li class="li"&gt;VDD&lt;/li&gt;
&lt;li class="li"&gt;External reference from AIN0 to AIN7 (between 0 V and VDD)&lt;/li&gt;
&lt;li class="li"&gt;Internal references 1.2 V, 1.8 V and 2.4 V&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li class="li"&gt;Three speed/power consumption modes: low-power, normal and high-speed&lt;/li&gt;
&lt;li class="li"&gt;Single-pin capacitive sensor support&lt;/li&gt;
&lt;li class="li"&gt;Event generation on output changes
&lt;ul class="ul" id="topic__ul_ncl_dqr_hs"&gt;
&lt;li class="li"&gt;UP event on VIN- &amp;gt; VIN+&lt;/li&gt;
&lt;li class="li"&gt;DOWN event on VIN- &amp;lt; VIN+&lt;/li&gt;
&lt;li class="li"&gt;CROSS event on VIN+ and VIN- crossing&lt;/li&gt;
&lt;li class="li"&gt;READY event on core and internal reference (if used) ready&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;&lt;/li&gt;
&lt;/ul&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Using ADC/SAADC to read data in BLE app</title><link>https://devzone.nordicsemi.com/thread/285365?ContentTypeID=1</link><pubDate>Wed, 16 Dec 2020 14:09:27 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:f8345b7e-ac2a-40d7-b8fa-5d55d0ad8cda</guid><dc:creator>daubsi</dc:creator><description>&lt;p&gt;Dear Karl, thanks for the explanation. I think I understand what you&amp;#39;re saying (as said above I&amp;#39;ve little experience with the peripherals yet). The SAADC priority would be a setting in the sdk_config.h then?&amp;nbsp;&lt;/p&gt;
&lt;p&gt;I&amp;#39;ll have a look at the LIMIT stuff. Indeed, as I am only interested in the crossing of my threshold I would not need to react/handle any other sampling value. There isn&amp;#39;t an example for that in the SDK, right? Still struggling a little bit with the setup of the SAADC, e.g. the GAIN settings seem to deliver &amp;quot;830&amp;quot; at the maximum voltage of 3.3V I ran the DK with (at least I think I do? ;-) Powered via USB) instead of the expected 1023. I read in another thread that I need to adjust the gain level accordingly as it accounts for voltages up to 3.6V.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Using ADC/SAADC to read data in BLE app</title><link>https://devzone.nordicsemi.com/thread/285360?ContentTypeID=1</link><pubDate>Wed, 16 Dec 2020 14:02:43 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:146a0e97-d6fd-46ba-93a0-c04476e2b0ac</guid><dc:creator>daubsi</dc:creator><description>&lt;p&gt;Thanks @snoopy20. What do you mean by &amp;quot;you have the AC comparator available&amp;quot;? Any chance you have a small sample code to illustrate your idea? I&amp;#39;m still learning the SDK and focused on the BLE stuff with yet little experience on the peripherals themselves. A diode might actually be helpful... good idea! I&amp;#39;ll check it out!&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Using ADC/SAADC to read data in BLE app</title><link>https://devzone.nordicsemi.com/thread/285351?ContentTypeID=1</link><pubDate>Wed, 16 Dec 2020 13:51:39 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:765fdfbb-ba0f-46bd-b7c0-ba21a5bf42dc</guid><dc:creator>Karl Ylvisaker</dc:creator><description>&lt;p&gt;Hello,&lt;br /&gt;&lt;br /&gt;Thank you for your patience.&lt;/p&gt;
[quote user=""]I was looking at the peripheral/saadc example and it worked quite well so far. But then I read that it is not recommended to perform SAADC measurements while BLE RF is happening at the same time. Also SAADC measurements seem to be delayed&amp;nbsp;or in general slower when BLE is active?[/quote]
&lt;p&gt;This depends on how you are initiating the sampling.&lt;br /&gt;If you are using the CPU to call the _sample function, then you will miss out on all samples that should have happened in the time the CPU is busy with higher-priority tasks - such as BLE communication. This is a very unreliable way to perform sampling, if you need them to be periodic and predictable.&lt;br /&gt;Instead, you may then connect the TASKS_START or TASKS_SAMPLE of the SAADC to a timer event that triggers periodically - like demonstrated in the SAADC peripheral example that you referenced.&amp;nbsp;This is the recommended way to trigger sampling, since it does not requires CPU intervention each sample, and thus can continue even though the CPU is unavailable.&lt;br /&gt;&lt;br /&gt;Regardless of how you initiate sampling the event handling will not happen until the CPU is available again. So, in the case that you have a lot of higher-priority events happening, or a lot of BLE communication is going on, you may see that your SAADC event handling is delayed. To alleviate this you can increase the priority of the SAADC to the appropriate level for your application.&lt;/p&gt;
[quote user=""]What is your recommendation to perform that task? Should I use plain ADC or SAADC? I believe in order to recognize the button press accurately my sampling interval should not be much slower than every 100ms? Whats the best practice here?&amp;nbsp;[/quote]
&lt;p&gt;The task you describe sounds like a use-case for the&amp;nbsp;&lt;a href="https://infocenter.nordicsemi.com/index.jsp?topic=%2Fcom.nordic.infocenter.nrf52832.ps.v1.1%2Fsaadc.html&amp;amp;anchor=saadc_limits"&gt;LIMIT events of the SAADC&lt;/a&gt;.&lt;br /&gt;This way, a LIMIT event will be generated when a set threshold is exceeded, which you then may use to handle the button-press.&lt;br /&gt;Could using the limits events be a possibility for you?&lt;br /&gt;&lt;br /&gt;Best practice for button-press duration is hard to say exactly, it depends on what kind of button it is being pressed, and the use-case of the button, but I would say that it is typically in the 50-300 ms range.&lt;br /&gt;&lt;br /&gt;Please do not hesitate to ask if any part of my reply is unclear, or if you have any other questions.&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: Using ADC/SAADC to read data in BLE app</title><link>https://devzone.nordicsemi.com/thread/284668?ContentTypeID=1</link><pubDate>Sun, 13 Dec 2020 23:31:15 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:a50f33f7-6fef-4f3c-acc7-47025639ec0b</guid><dc:creator>snoopy20</dc:creator><description>&lt;p&gt;If you are using the ADC interrupt then you can&amp;#39;t run it that fast or it&amp;#39;&amp;#39;ll eat into processing time available for other matters. The best way is to use the ADC Window mode and fire an event only when it falls/rises above the threshold.&lt;br /&gt;&lt;br /&gt;Since you&amp;#39;&amp;#39;re using the ADC chances are you have the AC comparator available? That is the most appropriate tool for the job.&lt;br /&gt;&lt;br /&gt;BTW you may get away with a diode, a 0.7v will bring you down to 0.5v. The problem then is 2v may not be registered &amp;#39;high&amp;#39;, but check the specification for GPIO to be sure.&lt;br /&gt;&lt;br /&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>