Beware that this post is related to an SDK in maintenance mode
More Info: Consider nRF Connect SDK for new designs

Using COMP to measure a capacitive sensor?

We have been using nRF52832 and nRF52840 processors in our board for a few years happily. Now we are evaluating a new type of sensor (confidential) that behaves like a variable capacitor. There are various solutions to measure a capacitor value, but all require external circuit. I'm trying to see if there is a way to use just the nRF52 (and a few passives) to do this. The PIC family of processors use a component called CTMU that can be used to accurately measure capacitors just using a known resistor.

In reading more, the CTMU is a current source and a comparator used to measure the capacitance. I was wondering if there's any way to use the COMP to measure a capacitance, using either a method similar to the CTMU or using it as an oscillator and measuring the frequency. But, while there are a lot of notes about capacitive sensing for buttons, I could not find anything on measuring capacitances.

Is this something that could be done? If so, any pointer to get started would be welcome (we are still using the nRF5 SDK, given our long codebase investment)

Parents Reply Children
  • It's possible; what is the full range of capacitance measurement and accuracy do you require? Often for accurate measurement using a reference known-value or (say) 1% capacitor and ratiometric measurement is simplest, assuming you don't want to manually calibrate.

  • The sensor range is roughly between 30pf to 40pf, and each device will be calibrated individually. So as long as precision (repeatability) is good, any circuit will work. Thanks for the help, really appreciated!

  • It's possible to PWM external capacitors and integrate the difference by using them as input transitions to an exclusive-or gate to provide a measurable voltage by summing the output (integration); quite a few components and port pins though. Just measuring the voltage difference between a reference capacitor and the sensor capacitance might be sufficient, only a single external reference capacitor required. Maybe have a look at this post: cap-meter-with-arduino-uno

    Edit: Is the sensor equivalent to a floating capacitor or a capacitor with one end to Gnd?

  • It's equivalent to a floating capacitor. Thanks for that link, I'll look into it ASAP

  • I like to do stuff like this for floating inputs, even when voltages on Csensor are outside rail-rail. Charge Cref, connect to  Csensor, connect to SAADC then measure voltage on Cref. Change of VCrefBeforeSample to VCrefAfterSample gives measurement. Repeat. Or if Csensor has a voltage and is not passive, discharge Cref, connect to Csensor then connect to SAADC and measure; this latter is useful for CCD or photodiodes (equivalent to capacitive sensors) which have a tiny signal voltage sitting on a large pedestal (aka offset) voltage.

    //                                       +--------------------------------------------------------------------+
    //                                       |                              nRF52832/nRF52840                     |
    //                      +------#---------0---< Switch o/p PWM or just toggle                                  |
    //                      |      |         |                                                                    |
    //                      |      |         |    VDD            VDD              VDD                             |
    //                      |      |         |   --#--          --#--            --#--                            |
    //                      |      |         |     |              |                |                              |
    //                      |      |         |     | Charge       |   Option       |   Option                     |
    //                      |      |         |     +-|   Drive    +-|   13k        +-|   160k                     |
    //                      |      |         |       |<- High       |<- Pullup       |<- High                     |
    //  Floating            |      |         |     +-|            +-|              +-|   Bias                     |
    //  Sensor              |      |         |     |              |                |                        SAADC |
    //     +--------/~/---0 | 0--------------O-----#--------------#----------------#------------#------#--> P0.nn |
    //     |               \'      |         |     | Discharge    |   Option       |   Option   |      |    Ref   |
    //     |                \      |         |     +-|   Drive    +-|   13k        +-|   160k  +++     |    Int   |
    //     |                0      |         |       |<- Low        |<- Pull         |<- Low   | |   -----        |
    //     |                |      |         |     +-|            +-|   Down       +-|   Bias  | |   -----        |
    //   -----            -----    |         |     |              |                |           +++     | 2.5pF    |
    //   -----            -----    |         |     |              |                |            |1M0   |          |
    //     | C              | Cref |         |   =====          =====            =====        =====  =====        |
    //     |                0      |         |    ===            ===              ===          ===    ===         |
    //     |                /      |         |     =              =                =            =      =          |
    //     |               /,      |         |                                                                    |
    //     +--------/~/---0 | 0--------------0-----+    <== Gnd or use 2nd SAADC Input                            |
    //                      |      |         |     |                                                              |
    //                      |      |         |   =====                                                            |
    //                      +------+         |    ===                                                             |
    //                                       |     =                                                              |
    //                                       +--------------------------------------------------------------------+
    // SPDT Switch, select one with single-supply and negative input voltage capability
    //  https://www.analog.com/media/en/technical-documentation/data-sheets/max4762-max4765.pdf
    

    Best to use SPDT Switch, select one with break-before-make, single-supply and negative input voltage or "outside rail-rail" capability
      eg max4762-max4765.pdf

    'nother edit: this link might be useful, I gave some more background an working with a capacitive sensor of a few pF slower-sampling-for-saadc

Related