Posted on
  • I'm using a capacitive sensor and would like to know more about the details of capsense. The nRF SDK only references it in softdevice 12, I don't see anything in the newer versions. There's also the confusion of charging versus the (supposedly non-working) frequency method.

    Any insights or documentation you'd point me to? I'm trying to tune the RC circuit. I'm assuming we're measuring the RC time constant, but a bit more detail will help me tune the RC for the timing and sampling rate I'm looking for. Clearly, it is measuring the time to charge, but to what levels? How are the comparator values chosen? How do we know when a conversion is done? Inquiring minds...


  • How exactly are you planning on doing capsense? UsingĀ­_capSense ?

    If so, that uses an extremely simple software-only approach (using a FOR loop to count up until the voltage hits a logical 1, then down until 0, and so on 100 times). The Puck itself uses a 1MOhm resistor, so I'd just start with that and see if it works ok for you.

    To use proper capsense using the hardware you'd have to use the library - but that should actually be pretty easy using the edge detection stuff there (you're effectively just using the inverter example as-is and adding a counter).

  • Thanks @Gordon! I have a capacitive sensor which ranges around 40-60 pF. I used the straight capsense using two pins with a 1M resistor and the sensor between them in series and it worked, but I wanted to understand/control its thresholds and resolution (prescaler) since the documentation is relatively meager for using it for anything other that qualitative finger presence.

    This is my simple test code (I run it into Adafruit's Bluefruit for graphing):

    // capsense trial...  082218
    setInterval(function() {
    //  console.log(Puck.capSense(D28, D29));
      Bluetooth.println(Puck.capSense(D28, D29));
    }, 100);

    So when you say it counts up/down 100 times between logic 1 and 0, at what frequency? And from your description, it is using the definition of logic high and logic low for thresholds, correct?

    I'll take a look at the NRF52LL reference. If I were to have my perfect solution, I'd be able to set thresholds so that I'm measuring proper time constants (say 2T at 86.5% or something similar). I'd also want to set the measurement/counting frequency to match the required timing/resolution.

    Any thoughts or example snippets would be extremely useful as always.

  • So when you say it counts up/down 100 times between logic 1 and 0, at what frequency?

    I haven't actually checked - at a guess I'd say around 8MHz. It's not entirely accurate because an IRQ could fire during it and knock it off - one of the reasons it's done 100 times.

    it is using the definition of logic high and logic low for thresholds, correct?


    I just gave this a try:

    var TX = D11;
    var RX = D12;
    var ll = require("NRF52LL");
    // set up pin states
    // Source of events
    var src = ll.gpiote(0, {type:"event",pin:RX,lo2hi:1,hi2lo:1});
    var dst = ll.gpiote(1, {type:"event",pin:TX,lo2hi:1,hi2lo:1});
    // Counter for crosses
    var ctr = ll.timer(3,{type:"counter"});
    // Set up and enable PPI
    ll.ppiEnable(0, src.eIn, ctr.tCount);
    ll.ppiEnable(1, src.eIn, dst.tOut);
    setInterval(function() {
      var v = peek32([0]);  
    }, 1000);

    And it does do something - but looking at it with a scope for some reason there's a massive delay in the oscillation (it's only 100 times a second), which makes it basically useless. It may be you can tweak it (for instance using the comparator) to make it work better though.

  • It seems that Puck.capSense() is the way to go. By the way, how do you access Puck.capSense(tx,rx) on MDBT42Q?

    The documentation says "Note: This is only available in NRF52 devices (like Puck.js, Pixl.js and MDBT42Q)", but when I try to call Puck.capSense on an MDBT42Q breakout, the IDE complains that "Puck" is not defined...

  • Ahh, sorry - all the things in the Puck class are only available on Puck.js. In this case the Puck has a 1 MOhm resistor on the default capSense lines.

    On the nRF52 boards you can use the NRF52LL code above though...

  • Were you originally planning to make the (tx,rx) version of that call available more broadly? (which would be handy, by the way). I'm just wondering how to interpret that note in the capSense API ref saying:

    "Note: This is only available in NRF52 devices (like Puck.js, Pixl.js and MDBT42Q)"...

  • I wasn't planning on making it more broad. The comment is there just because of the way the docs are created (and the use of an ifndef NRF52 that may have been left over from an old function). I've just updated that so the next doc release should be fixed

  • Post a reply
    • Bold
    • Italics
    • Link
    • Image
    • List
    • Quote
    • code
    • Preview


Posted by Avatar for billsalt @billsalt