Electronic – ESP32 DAC cannot output zero volts

dacmicrocontroller

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); output on DAC pin gets 0.1V 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.1V which at 2.8V (cutoff voltage) is 0.1A (or 100mA.)

Things I tried:

  • Connecting a 1k resistor from DAC pin to ground, doesn't work
  • Disabling DAC by dac_output_disable(DAC_CHANNEL_1);, output goes 0 but things get complicated, 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 very good accuracy.

What can I do to make 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 because of my previous failed attempts at designing circuits and my love for my ESP32 didn't allow me to do this experiment.

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

Best Answer

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.

Related Topic