Connect an output pin of an external IC to an input pin of an Arduino/ESP32

Hi,

I have been prototyping with a “powerpath controller” in the below configuration (datasheet is here; https://www.analog.com/media/en/technical-documentation/data-sheets/4412fb.pdf).

This is for use as a power supply switching circuit, when mains power fails.

How this configuration works is that when the wall adapter input is higher than the battery cells, the Auxiliary P-channel mosfet turns on, and the wall adapter powers the load. This mosfet is driven by the STAT pin, which is an open drain output (either ground or disconnected). The mosfet is pulled-up by the 470K resistor. The stat pin has a sink current of about 10 micro-amp max.

When the Wall adapter input is lost (i.e. battery voltage becomes higher than mains voltage), the primary P-channel mosfet turns on and the battery powers the load. This is driven with the gate pin.

This circuit works as expected, but what I now need is for there to be a signal sent to a microcontroller (3.3v ESP32), which indicates that the power source has changed from Wall adapter to Battery Cells (and vice versa).

The datasheet says a signal can be sent via the STAT pin to a microcontroller, but it doesn’t go into detail on how to do this when the STAT pin is also powering a mosfet.

I have attempted to achieve this with the following diagram, but it didn’t work. I had the STAT pin powering an additional P-channel mosfet (Q2), which acts as a high-side switch. This was supposed to send +3.3v to the ESP32 input pin, to switch the input HIGH when the wall adapter is connected. The input would pull to low (through 10K resistor) when the wall adapter is lost.

The gate of the mosfet (Q2) is pulled-up with the same 470k resistor.

I thought this would work, because the GATE of Q2 would switch from 12v (wall adapter voltage) to ground (0v) and the SOURCE pin would be receiving 3.3v, which would make VGS ≈ -3.3V, which is enough to turn on a logic-level mosfet, but I may be getting confused.

Can someone explain what I’m doing wrong and/or a proper approach to doing this?

I was also thinking maybe a level shifter circuit might work (using N-channel mosfets), with the voltage at the STAT pin connected to the high side (HV) and the voltage at the ESP-32 connected to the low side (LV). like this one https://www.sparkfun.com/products/12009. Could that work?

Thanks a lot!

Can you not connect the STAT pin direct to an esp input pin and use INPUT_PULLUP?

That was my initial thought, and this can be used for a different configuration for the LTC4412 (figure 1 in datasheet), however, the input pin would be receiving a high voltage through the 470K pull-up resistor (higher than 3.3v), which I assume is bad?

Hmm not really sure why you are not getting a correct result, what is the measured voltage on the GPIO pin in both 'states'
A normal method would be to actually slightly inverted on the GPIO input pin, where you use a pull up (normally internal) and you use some kind of mosfet / transistor to pull it low when the signal is HIGH, but as i said, this circuit should also work. (sorry correction) when using a pull down instead of a pullup, the pulldown resistor influences the bias. Try with a pullup !!

Ah, yes, true. Maybe add a small signal diode to block that higher voltage.

Ohhh, I think that might work with a 2 diode configuration. thanks.

????

I will explain with an updated schematic soon. thanks.

This is what I meant. There will be +12V (maximum) coming out of the 470K resistor, but that is blocked from going into the input pin of the 3.3V micro-controller with D2.

D1 prevents +3.3V (from internal pull-up of MCU) from flowing into the rest of the circuit. Not sure if it's needed.

Does that sound right?

Why are there two resistors called "R?" :face_with_symbols_over_mouth:
You asked for it, so lets call one R?banana and the other R?LOAD.

You can remove R?banana and D1. The gate of Q1 might have a charge. I prefer a resistor from source to gate.
What is left is just the diode to block the higher gate voltage, that is what PaulRB was talking about.

May I go a step back ?
Why not using two diodes instead of the chip ? If you use the chip, then what is so important to have the "Lowest Loss" ? I doubt if a diode from the adapter will be bad, so you can use the most common circuit for the chip:

afbeelding

The R?banana of 470k is only in the circuit to keep the STAT high when not activated. I suggest a lower value, 47k or 10k or use the internal pullup.

[UPDATE]
After looking at the circuit for the "Lowest Loss" for a while, the 470k to keep the gate of Q1 closed is to get the lowest possible current loss. However, the circuit is no longer flexible and it depends on the mosfets and input voltages if it will work properly. Therefor I don't like the "Lowest Loss" circuit.

Sorry for the typo's. I'm tired.

Ok, I will remove D1. Thanks.

Yes, I'm aware of other circuits without using the chip (like ORing diodes), I just find these highly efficient circuits interesting.

I have updated the schematic to include just 1 diode. However, it still doesn't work.

TLDR: the STAT pin is an open drain output, which is supposed to sink current only when the wall adapter is present. STAT pin is disconnected (stops sinking current) when Wall adapter is lost and the battery supply takes over.

I am trying to send a signal to an ESP32, that the state of the STAT pin has changed. This is done through connecting the STAT pin to an input pullup pin of the ESP32. The diode (D1) is used to ensure that high voltage doesn't enter the esp32 gpio pin (through R1).

Any idea what could be going wrong?

Also note that the STAT pin has a max sink current of around 10 microamps max. Could that be a problem?

Here is the code I am using to test everything. I am using a usb cable with +5v removed to communicate. I've also ensured that all grounds are connected. The state of the input pin should be low when the wall adapter is present. I am only receiving a HIGH signal (disconnected).

thanks.

void setup() {

  pinMode(27, INPUT_PULLUP);
  Serial.begin(9600);

}

void loop() {

  if (digitalRead(27) == LOW) {
    Serial.println("wall connected");
  }
  else {
    Serial.println("wall disconnected");
  }
  delay(2000);
}

Does it do that, yes i guess or the gate of the mosfet won't open, but can you verify with a multimeter that the pin actually goes LOW by measuring it's voltage ? The figure with the auxiliary P-channel mosfet actually states that the stat pin 'drops' but does not go completely low as is stated in figure 3 of the datasheet.
So how about do something similar to the original combined with the latter approach ? Connect second auxiliary P-channel to the wall socket (not the 3.3v !) connect another pulldown to the drain and connect the diode to the drain as well. (with the cathode and the anode to the GPIO pin) Now put a significantly bigger pullup on the GPIO pin (if the mosfet is closed the gpio should go low)
Or maybe more efficient, measure the voltage between the drain and GND using a voltage divider, removing the need for the diode and it's voltage drop.

1 Like

I stuck a multimeter between the STAT pin and ground and it read roughly +5V on both mains connection and mains disconnection,

so I think you may be correct!

I'll have to try and draw that one out to understand it. give me a few hours!

Ok, we're getting somewhere!

I can confirm a 2nd auxiliary mosfet is switching an LED on and off if the source is connected to the load side of the circuit (instead of 3.3v), like so;

LED goes on when wall adapter connected, and off when battery connected.

However, I think I've gotten confused by this suggestion. Is this what you meant? I don't know how a circuit like that would function.

no not like that. Sorry i messed up the mosfet pin names again...
basically just have 2x a Pchannel mosfet in parallel, where the 2nd one has a voltage divider i'd suggest AOD4185 - 1M - 220K - GND, rather than trying something with a diode to prevent over voltage.

1 Like

That's all good. I've actually got it working now by having the high-side P-channel switch powering a low-side N-channel switch, like so;

I also attempted to just have a single N-channel mosfet connected to the STAT pin, and have it pull the input pullup pin LOW, but that didn't work.

Yep that would work.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.