Adafruit is open and shipping! Let's build back better, together!
0

High impedance pin
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

High impedance pin

by flounder on Sat Nov 21, 2020 5:26 am

I want to charge a capacitor. Then I want to discharge it. I want to measure the voltage. Here's the schematic from the code comments

Code: Select all | TOGGLE FULL SIZE
/********************************************************
 * +V
 *  |                  10K ohm
 *  +--chargePin [S1] ---vvvvv-----*------------ voltPin
 *                         470 ohm |
 * +---resetPin [S2] ----vvvvv-----*
 * |                               |
 *GND                      10K     |
 * +---dischargePin [S3] --vvvvv---*
 * |                               |
 *GND                              |
 *                                === C1
 *                                ===
 *                                 |
 *                                GND
 ********************************************************/

Here's the scenario I want:
  • Closing switch S1 connected to +V charges the capacitor through the 10K resistor
  • Opening switch S1 stops the charge. The capacitor will discharge via internal leakage or via explicit discharge requests
  • Closing switch S2 to GND resets the capacitor to 0 (not really, see below)
  • Opening switch S2 removes the "short circuit"
  • Closing switch S3 to GND discharges the capacitor through a load resistor
  • Opening switch S2 stops discharging

Initially, all three pins are input pins. This should place them, or so I thought, in the high-impedance state and not have any voltage present.

  • To charge, I set pinMode(chargePin, OUTPUT); digitalWrite(chargePin, HIGH). This should apply a +3.3V signal to the capacitor through the resistor.
  • Once charged, I set pinMode(chargePin, INPUT)
  • To reset it, I essentially want to short it to ground, but to protect the output transistor, I have to put a 470 ohm resistor in series to limit the current. So what I do is pinMode(resetPin, OUTPUT); digitalWrite(resetPin, LOW); Also, since LOW is probably not 0.0, it does not discharge all the way. This is fine.
  • To discharge it in a controlled fashion, I do pinMode(dischargePin, OUTPUT); digitalWrite(dischargePin, LOW);
  • All these settings are selected by commands sent via the serial port, so the way to manipulate a switch is
    +n turn on switch n
    -n turn off switch n
    So I send the sequence (comments in [] are not part of the input, just explanation for this post)
    +2 [reset capacitor to nominal 0.0]
    -2 [turn off reset switch]
    +1 [start charging]
    -1 [stop charging]
    +3 [start controlled discharge]
    -3 [stop controlled discharge]
  • The problem is that the voltage level on the input pin appears to be +3.3
  • I The page https://www.adafruit.com/product/3800 says "Dual 1 MSPS 12 bit ADC" but the maximum value I see is 1023.
So the question is, what is going on here? Is there any way to put the output pin into a "high impedance" state? Or do I have to put a MOSFET outboard of the processor? Doing high-side switching is such a pain, I was trying to avoid that.

The goal of this is to use the serial plotter to show a capacitor charging and discharging as part of an introductory course.

flounder
 
Posts: 446
Joined: Wed Sep 18, 2013 9:10 pm
Location: Pittsburgh PA

Re: High impedance pin

by adafruit_support_bill on Sat Nov 21, 2020 7:45 am

The problem is that the voltage level on the input pin appears to be +3.3

What voltage are you expecting? Every pin, regardless of what mode it is in will be at some voltage potential relative to ground.

In high impedance mode, it will just not be able to source or sink any substantial amounts of current. If not connected to anything, it will 'float'. If connected to the circuit, it can be pulled one way or the other by whatever it is connected to.

adafruit_support_bill
 
Posts: 79340
Joined: Sat Feb 07, 2009 10:11 am

Re: High impedance pin

by flounder on Sat Nov 21, 2020 8:09 pm

In tri-state logic, a pin which is in high-impedance state neither sources nor sinks voltage. There is nothing driving it. So I would expect that a pin in INPUT mode would be in high-impedance state (note INPUT, not INPUT_PULLUP). It looks to me, reading the circuit diagrams in the documentation, that an input pin has no voltage applied.

A pin does not have to have a voltage. The whole point of pullup and pulldown resistors is to guarantee a known voltage on an input pin. Without the pullup or pulldown, the pin has no known voltage. Otherwise, we could not do a bus system like SPI or ISP, which critically depend on the fact that devices which have nothing to say impose no voltage on their pins.

flounder
 
Posts: 446
Joined: Wed Sep 18, 2013 9:10 pm
Location: Pittsburgh PA

Re: High impedance pin

by adafruit_support_bill on Sat Nov 21, 2020 11:15 pm

A pin does not have to have a voltage.

Voltage is simply a difference in electrical potential relative to some reference. Everything has an electrical potential. It may or may not be 0v relative to what you are using as a reference.

Without the pullup or pulldown, the pin has no known voltage.

Just because you don't know the voltage doesn't mean it doesn't exist.

adafruit_support_bill
 
Posts: 79340
Joined: Sat Feb 07, 2009 10:11 am

Please be positive and constructive with your questions and comments.