-
• #2
How exactly are you planning on doing capsense? Using http://www.espruino.com/Reference#l_Puck_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 http://www.espruino.com/NRF52LL 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).
-
• #3
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.
-
• #4
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?
Yes.
I just gave this a try:
var TX = D11; var RX = D12; var ll = require("NRF52LL"); // set up pin states digitalWrite(TX,0); pinMode(RX,"input"); // 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() { poke32(ctr.tCapture[0],1); poke32(ctr.tClear,1); var v = peek32(ctr.cc[0]); print(v); }, 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.
-
• #5
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...
-
• #6
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...
-
• #7
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)"...
-
• #8
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
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...
Thanks!