1
\$\begingroup\$

I've come up with an RC circuit, which is using the output pins of a NodeMCU board to create an AC current for measuring conductivity of a liquid.

What I'm actually measuring is the discharge time of the capacitor, and that's what this question is about. At low frequencies (1-2 kHz) the measured time is exactly as expected based on the capacitance of 47 nF, knowing that the input pin flips when the voltage reaches 50%. That's the time I'm measuring: from fully charged to 50%.

Now at higher frequencies (by lowering the value of the load resistor) the capacitor appears to go up in size, at 120R I'm getting discharge times of around 7200 nanoseconds, that gives me a capacitance of about 120 nF.

How could this be possible?

Other possibly relevant information: the capacitor appears to be a film type (it's a rectangular block); the whole setup is operating on a solderless breadboard (I know there may be stray capacitance in there but that doesn't matter here - I don't care as much about the actual value of the cap as I care about it being constant).

J1 is three GPIO pins of the NodeMCU. The EC probe I replaced by resistors of various value just to measure the response, which I expect to be linear. C1 is first fully charged by the pins 1 and 2 (it gets 100 microseconds for that, RC is just over 15 microseconds), then discharged over pin 3 while pin 1 measures the voltage, flipping when the voltage drops below 50%. All in all a very basic RC circuit. I expect that lowering the value of the resistor over J2 decreases the time linearly - but it doesn't.

At 33k discharge time about 800 us, R/t/0.5 = 48 nF.

At 10k discharge time about 235 us, R/t/0.5 = 47 nF.

At 330R discharge time about 12 us, R/t/0.5 = 73 nF.

At 120R discharge time about 7 us, R/t/0.5 = 120 nF.

My timing is in the 12.5 ns resolution (80 MHz clock speed) so that's not the problem. Being a few ticks off doesn't explain this.

enter image description here

\$\endgroup\$
  • 2
    \$\begingroup\$ "knowing that the input pin flips when the voltage reaches 50%". I/O pins on an MCU does not behave like that. This is only true if you have an analog comparator. \$\endgroup\$ – pipe Mar 26 '17 at 18:59
  • \$\begingroup\$ NodeMCU is not an Arduino clone; it's an alternative firmware for ESP8266 wifi SOCs. They are very different from Arduino's in both hard- and software. \$\endgroup\$ – marcelm Mar 26 '17 at 19:25
  • \$\begingroup\$ I've done some actual measurements and found it's really close to that 50% level that the pin flips in my test boards. I thought it'd be 1/3 or 2/3 Vcc but it's more like 1/2. Using that 50% level in calculations also works very well. The actual level is not important, really, as long as it's constant. The calibration factor takes care of all that. \$\endgroup\$ – Wouter Mar 26 '17 at 19:26
  • \$\begingroup\$ Edited the arduino part. \$\endgroup\$ – Wouter Mar 26 '17 at 19:27
2
\$\begingroup\$

Now at higher frequencies (by lowering the value of the load resistor) the capacitor appears to go up in size.

Your IO pin that drives the resistor isn't capable of supplying tens of mA current whilst maintaining an output voltage at Vcc. Basically, it's output resistance is in series with R1 hence, the lower you make R1 the more of a problem it becomes.

\$\endgroup\$
2
\$\begingroup\$

It always feels a bit silly if I can answer my own question minutes after I posted it.

The problem is completely within the software. I completely forgot to correct for software overhead. It turns out that by simply deducting 4400 ns from the measured time, everything falls in place!

@Andy aka: the current is not the problem. NodeMCU can source 12 mA (the R1 limits it to 10 mA peak) and sink 20 mA, a limit which is reached when the EC probe drops under 150R. This means I should indeed add an extra resistor to protect my NodeMCU from short circuits or really high ECs.

\$\endgroup\$
  • \$\begingroup\$ By the time you know enough to ask a question, you usually know more than enough to answer it. I find that all the time. \$\endgroup\$ – StainlessSteelRat Mar 26 '17 at 19:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.