0
\$\begingroup\$

I'm currently designing a PCB at which I have an lithium ion battery (4.3V max) attached. The battery is charged via USB (5V).

The charging controller is enabled by a microcontroller which should detect when USB is attached. Due to power saving and money saving design considerations the plus-pole of the battery and the 5V-USB pole are connected to each other (diode is there for direct-charging-protection).

Anyway, before I had these design re-considerations I had a simple voltage divider at the 5V-USB (150k/100k) to detect a connected USB charging cable directly by the microcontroller via a simple GPIO interrupt.

Now I have to detect without an ADC (already used) if the voltage on the line is sourced by USB (5V) or by the lithium ion battery (4.3V). Is the microcontroller's analog comparator (ACMP, using SiLabs, EFM32G222 microcontroller) an option to use? Then I could just compare if the signal is below or above 4.3 V (or let's say 4.4 V to add some safety space)? I would use a voltage divider to scale down the 4.3 V/4.4 V to the voltage are of the microcontroller (2.1 V).

Is this a reasonable idea?

Many thanks in advance for your help!

EFM32G Reference Manual: https://www.silabs.com/documents/public/reference-manuals/EFM32G-RM.pdf

Used Specific MCU Datasheet: http://www.farnell.com/datasheets/2170296.pdf

\$\endgroup\$
  • \$\begingroup\$ Thanks for the tip! I've added the links to the datasheets. \$\endgroup\$ – Philipp Doublehammer Apr 19 '18 at 10:55
  • 4
    \$\begingroup\$ PCB=printed circuit board. PCB board= printed circuit board board. The message brought to you by the department of redundancies department. \$\endgroup\$ – JRE Apr 19 '18 at 11:13
  • 2
    \$\begingroup\$ Ah, the good old DRD department. \$\endgroup\$ – Colin Apr 19 '18 at 11:20
  • \$\begingroup\$ Both links point to the same manual. I would suggest deleting the second one. \$\endgroup\$ – Caleb Reister Sep 30 at 0:49
0
\$\begingroup\$

Short Answer: Yes, you can use the comparator with a voltage divider. Just make sure you choose an appropriate reference voltage and hysteresis level. However, it may be better to use an appropriate charge controller.

  • You should not use a GPIO input in place of a comparator. Not only is there no way to determine the exact threshold voltage, it will draw an excessive amount of current (typically on the order of 2-3mA). Take a look at this answer for more information.
  • Many charge controllers have the ability to switch between battery and external power (USB in your case). This will likely result in lower power consumption and increased reliability (no power issues due to software bugs).
  • You need to set a reference voltage for the comparator. I would recommend using 1.25V internal bandgap reference.
  • You will probably need a significant amount of hysteresis (at least ±25mV) to prevent load changes from switching the comparator when the voltage is near the threshold.
\$\endgroup\$
0
\$\begingroup\$

I would simply treat the 5V line as GPIO. Connect it via a divider so it does not go above MCU Vcc.

The "bottom" resistor will make sure that GPIO reads as zero when there is no voltage.

GPIO reads low = you're on battery power

GPIO reads high = you're on USB power

\$\endgroup\$
  • \$\begingroup\$ As described in my post, this is how it was before +5V (USB) and 4.3 V (battery) line were shorted. \$\endgroup\$ – Philipp Doublehammer Apr 20 '18 at 13:56

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.