<?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>Cap sense using single pin per sensor</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/62681/cap-sense-using-single-pin-per-sensor</link><description>Hi, 
 I&amp;#39;m using the nRF52840 dev kit for a BLE-based application. I need to implement a capacitive touch button for detecting button presses and releases (no sliding). I only have 1 analog input pin connected to my sensor. I&amp;#39;ve looked at the nrf52-capsense</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Thu, 09 Jul 2020 17:17:00 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/62681/cap-sense-using-single-pin-per-sensor" /><item><title>RE: Cap sense using single pin per sensor</title><link>https://devzone.nordicsemi.com/thread/259275?ContentTypeID=1</link><pubDate>Thu, 09 Jul 2020 17:17:00 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:938c8d57-4b09-452b-bd0e-bc299801fa01</guid><dc:creator>Tim Kutscha</dc:creator><description>&lt;p&gt;I work with Brian at Simplexity and we were able to get the capacitive touch button working with a second GPIO that stimulates the pad through a 1M resistor.&amp;nbsp; This leverages the existing csense driver.&amp;nbsp; I&amp;#39;ve attached source code here, in case anyone else wants to leverage it.&lt;a href="https://devzone.nordicsemi.com/cfs-file/__key/communityserver-discussions-components-files/4/nrf_5F00_drv_5F00_csense.c.txt"&gt;devzone.nordicsemi.com/.../nrf_5F00_drv_5F00_csense.c.txt&lt;/a&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Cap sense using single pin per sensor</title><link>https://devzone.nordicsemi.com/thread/255616?ContentTypeID=1</link><pubDate>Wed, 17 Jun 2020 17:33:49 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:b53599e7-345a-40ba-af9b-2494249ae1db</guid><dc:creator>hmolesworth</dc:creator><description>&lt;p&gt;Yes, you can use a single pin for capacitive sensing. The trick is to first use the pin to charge (or discharge, depending on whether the capacitive sensor is between pin and Gnd or pin and Vcc). Then turn the pin around to an analogue input and measure the decaying falling (rising) voltage which will be at a rate controlled by capacitance and resistance. Something like this, in this case assuming a capacitor connected to Gnd and Vcc via a charging resistor:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;#define CAPSENSE_PIN 5
  // Number of samples depends on how accurate the rising CR curve should be measured
  int16_t CapCharge[50];

  // Get ready to discharge the cap
  nrf_gpio_pin_clear(CAPSENSE_PIN);
  // Discharge cap
  nrf_gpio_cfg(CAPSENSE_PIN, NRF_GPIO_PIN_DIR_OUTPUT, NRF_GPIO_PIN_INPUT_DISCONNECT, NRF_GPIO_PIN_NOPULL, NRF_GPIO_PIN_H0S1, NRF_GPIO_PIN_NOSENSE);
  // Wait long enough for cap to discharge
  nrf_delay_us(20);
  // Turn around to analogue input to read the charging voltage
  nrf_gpio_cfg(CAPSENSE_PIN, NRF_GPIO_PIN_DIR_INPUT, NRF_GPIO_PIN_INPUT_DISCONNECT, NRF_GPIO_PIN_NOPULL, NRF_GPIO_PIN_S0S1, NRF_GPIO_PIN_NOSENSE);
  for (uint32_t i = 0; i &amp;lt; sizeof(CapCharge) / sizeof(CapCharge[0]); i++)
  {
    CapCharge[i] = SAADC_Measure(CAPSENSE_PIN);
    // Experiment with number of samples and delay between each, depends on CFR
    nrf_delay_us(50);
  }&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;You can use SAADC pull-up (160k-ish) as a charging resistor if you want to save a component and use only a capacitor; accuracy in that case&amp;nbsp; is low but often good enough discrimination of movement. Values of C and R depend on sensitivity and response time; C is not a real capacitor in most cases, just a foil contact in the case of a touch sensor. Now that is what I&amp;#39;d call a zero component capacitive sensor, no C or R.&lt;/p&gt;
&lt;p&gt;I should add that you can just compare the voltage with a comparator instead of the SAADC, or even rely on the ill-defined logic high input level on an i/o pin in input mode feeding a timer if simple presence/absense is required, and not an more precise measurement. SAADC or comparator should be in ratiometric mode, if charging voltage is Vcc then reference should also be Vcc and not a fixed reference.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Cap sense using single pin per sensor</title><link>https://devzone.nordicsemi.com/thread/255562?ContentTypeID=1</link><pubDate>Wed, 17 Jun 2020 13:22:52 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:ab6ffb28-9cc6-4621-9fa7-7dee82136e5c</guid><dc:creator>Einar Thorsrud</dc:creator><description>&lt;p&gt;Hi Brian,&lt;/p&gt;
[quote user="bpeavey"] Is it possible to use the newer Capacitive Sensor library with a sensor only connected to one pin?[/quote]
&lt;p&gt;Yes, the capsense driver&amp;nbsp;supports both methods.&amp;nbsp;Please see &lt;a href="https://infocenter.nordicsemi.com/topic/sdk_nrf5_v16.0.0/lib_csense_lowlevel.html"&gt;this page&lt;/a&gt; for details.&lt;/p&gt;
[quote user="bpeavey"]Also, does the erratum 84 only apply to the nRF52832?&amp;nbsp; I&amp;#39;m using the nRF52840.&amp;nbsp;[/quote]
&lt;p&gt;In practice, erratum 84 applies to all nrF52 devices. Formally, it does not, since the nRF52840 does not have this support at all if you refer to the product specification. And that is because it uses the same implementation as nRF52832, which is non-functional (as you can see from erratum 84).&lt;/p&gt;
&lt;p&gt;Einar&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Cap sense using single pin per sensor</title><link>https://devzone.nordicsemi.com/thread/255555?ContentTypeID=1</link><pubDate>Wed, 17 Jun 2020 13:14:51 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:26bf1037-6868-429b-926a-0a383c3f8ee2</guid><dc:creator>Brian</dc:creator><description>&lt;p&gt;Hi Einar,&lt;/p&gt;
&lt;p&gt;&amp;nbsp; Thanks for the quick response!&amp;nbsp;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&amp;nbsp; I have looked at the capacitive sensor library in SDK16.&amp;nbsp; From what I could tell, my sensor needs to be hooked up to 2 pins to implement a capacitive sensor button.&amp;nbsp; My sensor is only connected to one pin (AIN3).&amp;nbsp; Is it possible to use the newer Capacitive Sensor library with a sensor only connected to one pin?&lt;/p&gt;
&lt;p&gt;&amp;nbsp; Also, does the erratum 84 only apply to the nRF52832?&amp;nbsp; I&amp;#39;m using the nRF52840.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Thanks...&lt;/p&gt;
&lt;p&gt;Brian&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: Cap sense using single pin per sensor</title><link>https://devzone.nordicsemi.com/thread/255521?ContentTypeID=1</link><pubDate>Wed, 17 Jun 2020 12:04:30 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:fdeed824-4f56-4235-afd2-84c3213f06ac</guid><dc:creator>Einar Thorsrud</dc:creator><description>&lt;p&gt;Hi Brian,&lt;/p&gt;
[quote user=""]Is this still the recommended method to follow when only a single pin is connected to the touch sensor?[/quote]
&lt;p&gt;No. A&amp;nbsp;very important point is that regardless of which SW implementation you use, this will only work as a demo, and is not suitable for production due to &lt;a href="https://infocenter.nordicsemi.com/topic/errata_nRF52832_Rev2/ERR/nRF52832/Rev2/latest/anomaly_832_84.html"&gt;nRF52832 erratum 84&lt;/a&gt;. This erratum does not exist for other nRF52 series devices, but that is not because the issue is fixed, but because the feature was removed from the product specification.&lt;/p&gt;
[quote user=""]Are there any issues using this method along with BLE (SoftDevice S140)?[/quote]
&lt;p&gt;It should be possible to make this work with a SoftDevice as measurements are done using PPI and SW is not time-critical. (I have not tested it, though.)&lt;/p&gt;
[quote user=""]&amp;nbsp; Is there any way to use the csense library in this configuration?[/quote]
&lt;p&gt;The example you refer to was written before the &lt;a href="https://infocenter.nordicsemi.com/topic/sdk_nrf5_v16.0.0/lib_csense.html"&gt;Capacitive Sensor library&lt;/a&gt;&amp;nbsp;was available, and I recomend you refer to that instead. That also supports using two pints to measure the discharge time of the sensor cap. You should note that the library is not particularly advanced though, and may not function well in a practical product which is used in an environment with varying air humidity, etc. So you should consider the SDK code as proof of concept more than anything else.&lt;/p&gt;
&lt;p&gt;Einar&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>