1
\$\begingroup\$

I made a circuit to use with my ESP32 to test 18650 battery capacity.

During tests I didn't notice that when I do dacWrite(dacpin, 0); the output on DAC pin becomes 0.1 V instead of zero

Those tiny voltages are a problem, because the LM358 op-amp is connected to the DAC pin in unity gain configuration which instead of shutting down keeps draining battery by 0.1 V which at 2.8 V (cutoff voltage) is 0.1A (or 100 mA).

Things I tried:

  • Connecting a 1 kΩ resistor from the DAC pin to ground, doesn't work
  • Disabling DAC by dac_output_disable(DAC_CHANNEL_1);; the output goes to 0 but things get complicated, the op-amp starts outputting randomly turning on the MOSFET.

Schematics: ESP32 Battery Capacity tester by Asim

Other than this problem, it works great paired with an ESP32 touch pin to start/reset, and has very good accuracy.

What can I do to make the DAC output zero?

I thought of connecting an NPN transistor from the LM358 output to ground that will be turned on/off by microcontroller but my previous failed attempts at designing circuits and my love for my ESP32 don't allow me to do this experiment.

If someone needs to view the code or build this project: Code

\$\endgroup\$
3
  • \$\begingroup\$ How am going to achieve controlled constant current drain then? it will simply drain battery through resistor? @blaber \$\endgroup\$
    – asim
    Commented Mar 6, 2021 at 22:04
  • \$\begingroup\$ Please read this analogictips.com/… @blaber \$\endgroup\$
    – asim
    Commented Mar 6, 2021 at 22:08
  • 1
    \$\begingroup\$ Tip: GND symbols should point to the ground, not the walls and not the sky. The symbol represents metal plates buried in the earth. \$\endgroup\$
    – Transistor
    Commented Mar 6, 2021 at 22:14

2 Answers 2

2
\$\begingroup\$

Do you have the pull-up enabled for the DAC output?

The DAC output pins on the ESP32 can be used either as a normal digital input/output with programmable pull-ups or pull-downs. If the pull-up is enabled it will put a small current into the output that will raise the minimum voltage slightly.

The DAC uses a resistor network and a activated pull-up will result in a small positive if it is enabled.

Also, even if the DAC outputs zero volts you cannot guarantee that the discharge current will be zero because of op-amp offset voltage.

The LM358 opamp has the possibility of having an offset voltage of up to 3mV depending upon the grade and manufacturer. It could be that you provide it with 0V but it interprets the voltage as being positive or negative up to 3mV.

One way to avoid this issue is to intentionally provide an offset of a few mV in the opposite direction that is larger than the possible offsets of the DAC and opamp. You can compensate for that offset in software although the amount of offset required will be only about 1 LSB of the DAC so will probably not be significant.

You can introduce this by adding a resistor of say 1kohm between the current sense resistor and the amplifier inverting input pin then add a resistor from the input pin to the +5V supply. 470k would inject about 10uA that would result in 10mV across the 1k resistor.

Then any input voltage less than 10mV from the DAC would give zero discharge current.

I would also put an attenuator on the DAC output (maybe after an opamp buffer) so the working voltage across the current sense resistor is say 0-1V rather than 0-3.3V as you have it. There would be less power in the sense resistor and it would work down to lower battery voltages and would provide better resolution at low currents.

\$\endgroup\$
7
  • \$\begingroup\$ not sure what pull-up enabled for the DAC means but great answer about providing an offset, many thanks \$\endgroup\$
    – asim
    Commented Mar 6, 2021 at 22:22
  • \$\begingroup\$ @asim Instead of a resistor you can also use a diode (preferably a schottky diode with low forward drop) to introduce the desired offset. Place it in series with the dac's load at the low side. \$\endgroup\$
    – Sim Son
    Commented Mar 7, 2021 at 7:29
  • \$\begingroup\$ You mean before R3? @SimSon \$\endgroup\$
    – asim
    Commented Mar 7, 2021 at 11:24
  • 1
    \$\begingroup\$ @SimSon - A resistor is better. You only need a few mV of offset. The offset from a diode will be less predictable and vary with temperature. \$\endgroup\$ Commented Mar 7, 2021 at 16:59
  • \$\begingroup\$ @KevinWhite I agree, now that I see the circuit \$\endgroup\$
    – Sim Son
    Commented Mar 7, 2021 at 18:03
0
\$\begingroup\$

I have the same 0.1 V but I discovered that if you power the board using the Vin pin the 0.1vV disappears or is going down to 0.07 V and is coming back when reconnecting the micro USB power kabel. I do not have the electrical drawing of the board, but the problem is in the USB power circuit.

ESP32 WROOM 4Mb Devkit V1

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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