8

I am currently using the PIC24FJ128GA010 and I am planning to use Input/Output port to connect my 4.2 V LiPo battery and to check if the voltage value doesn't go below 3.7 V.

I am thinking to connect it to any of my input/output pin but I am wondering two questions:

  1. Is it the correct pin?
  2. Should I do a specific montage with resistor?
stevenvh
  • 145,145
  • 21
  • 455
  • 667
Mattew
  • 163
  • 1
  • 2
  • 7
  • When you ask if it is the correct pin do you mean a standard I/O pin? – Bruno Ferreira Sep 03 '12 at 15:06
  • Yes, should I use Analog or Digital ? – Mattew Sep 03 '12 at 15:18
  • You should avoid digital. You have two options, use an ADC or use an Analog comparator. The last on one should be preferable if you only need to check if the voltage dropped bellow your threshold. – Bruno Ferreira Sep 03 '12 at 15:22
  • @Mattew: Why 3.7V ? If you stop at 3.7V on the discharge curve, you'd be stopping after having used less than 50% of a LiPo's capacity (depending on your current draw). See [discharge curves for a Sanyo Li-ion battery](http://img.directindustry.com/pdf/repository_di/15432/li-polymer-76482_3b.jpg) – boardbite Sep 03 '12 at 19:05
  • Possible duplicate of [How to measure battery voltage from a microcontroller](https://electronics.stackexchange.com/questions/35033/how-to-measure-battery-voltage-from-a-microcontroller) – JYelton Jan 18 '19 at 20:38

2 Answers2

9

The PIC24F etc. is a 3.3 V device, so you can't apply the LiPo's voltage directly to an input pin.

You can use an ADC (Analog-to-Digital Converter) channel, or a built-in comparator. The ADC will give you the actual voltage at any time, the comparator only good/no good.

Like I said you can't apply the battery's voltage directly: it's too high. Use a resistor divider to scale the 4.2 V down to 3.3 V. A 10 kΩ resistor in series with a 33 kΩ will do fine. The divider will draw a constant current of 100 µA, which isn't much, but you don't want this 24/7. You can use a logic level gate P-MOSFET as a high-side switch to enable or disable the divider, like the Si2303.

Oli Glaser
  • 54,990
  • 3
  • 76
  • 147
stevenvh
  • 145,145
  • 21
  • 455
  • 667
  • I think the ADC is a good idea, I am looking for a really small solution (not enough space). If I use ADC, do I still need to use the resistor divider/P-MOSFET? – Mattew Sep 03 '12 at 15:42
  • @Mattew - The FET only takes a few mm\$^2\$, 0402 resistors even less. You need the divider; the inputs are 5 V tolerant, but according to the datasheet that's only for the digital inputs. A higher than 3.3 V on the analog inputs may damage them. You can drop the FET, but them the resistor divider will (slowly) drain the battery. – stevenvh Sep 03 '12 at 15:54
5

(Credit for much of this goes to @stevenvh's suggestion... For sake of more visual readers, I'm just providing a rough schematic of my circuit based on the suggestion!)

EDIT: Schematic further refined with a suggestion made by @Nick and @stevenvh:

enter image description here
More in this thread.

boardbite
  • 4,892
  • 11
  • 47
  • 73