G+_Chris O'Riley Posted February 5, 2019 Share Posted February 5, 2019 I have an op amp question for those who, unlike me, actually know how these things work! My goal is to check the voltage of a battery without draining it while the device is off/not active. I don't need to know the voltage at all times, only when it drops below a given level. Basically, I just want to have the device know when a lipo cell drops too low. So, in the attached schematic, the microcontroller (powered by a 5v boost regulator not shown) drives PB0 high, which would be 5 volts. That goes through a resistor divider to drop it to my cut-off voltage of, say, 3.5 volts. That, and the +v from the battery go to the inputs of an op amp. The output of the op amp is read by PB2. Once the battery voltage drops below the 3.5v from PB0, shouldn't the output of the op amp flip from + to - or vice versa? From what I've read, op amps draw virtually no current from the inputs vs. connecting the battery directly to a microcontroller input even through a high-ohm resistor. Ok, so what do I have totally wrong? ;) Or would the battery drain through, say, a megaohm resistor directly to a pin be so low as to not be worth the effort to try to improve on? Thanks in advance! Link to comment Share on other sites More sharing options...
G+_Black Merc Posted February 5, 2019 Share Posted February 5, 2019 How are you powering the opamp? The described circuit is a comparitor. A < B -> high A > B -> low Your understanding is correct. Link to comment Share on other sites More sharing options...
G+_Chris O'Riley Posted February 5, 2019 Author Share Posted February 5, 2019 I'd be powering the micro (and other things) from a 5 volt boost regulator from the same battery being measured. So it would always have a stable 5 volts from which to generate the 3.5 volt reference to compare with the voltage directly from the battery. I suppose I could connect the resistor divider directly to the +5 supply from the boost regulator vs. a pin on the micro. But so long as I choose an op amp with an appropriate voltage range, it sounds like you're saying this would work?!! I looked at analog comparators as well, and it seems they're basically this type of circuit. Almost all the op amp circuits I've seen use feedback from the output back into one of the inputs, but for what I'm looking to accomplish, it didn't seem like that was necessary. Thanks for the reply! Link to comment Share on other sites More sharing options...
G+_Paul Hutchinson Posted February 5, 2019 Share Posted February 5, 2019 The circuit performance will have extreme variations depending on the particular Op-Amp used. In particular the input leakage current can be anywhere from picoamps up to milliamps. Here's a good tutorial on Op-Amps, read sections 1 through 3 and then you can skip up to section 11 for comparator applications. electronics-tutorials.ws - Operational Amplifier Basics - Op-amp tutorial If you don't want to go that in depth on Op-Amps I suggest looking at one of the battery monitor IC's where the manufacturer has worked out all the analog issues for you. If on the other hand you want to learn a lot about Op-Amp applications I highly recommend The Op-Amp Cookbook by Walter Jung. Link to comment Share on other sites More sharing options...
G+_John Sullivan Posted February 5, 2019 Share Posted February 5, 2019 I would do it all in code on the microcontroller. I would have it read an input pin and then "map" that reading to a scale (say 0 to 10), and then if the value drops below your threshold voltage, do something (send a text, flash a warning LED, etc.) Set a delay so it only reads once every X minutes (hours?) Link to comment Share on other sites More sharing options...
G+_Black Merc Posted February 5, 2019 Share Posted February 5, 2019 Chris O'Riley the feedback circuit(depending on which input it goes back to) are often used in analog projects for amplifying the input signal. Link to comment Share on other sites More sharing options...
G+_Ben Reese Posted February 6, 2019 Share Posted February 6, 2019 Would a lipo battery alarm work for what you need? Apex RC Products 2 Pack Lipo Battery Voltage Checker Alarm LED 1-8 Cell 1655 https://smile.amazon.com/dp/B00XQ91ECA/ amazon.com - Amazon.com: Apex RC Products 2 Pack Lipo Battery Voltage Checker Alarm LED 1-8 Cell 1655: Toys & Games Link to comment Share on other sites More sharing options...
G+_Chris O'Riley Posted February 6, 2019 Author Share Posted February 6, 2019 Thanks for the comments and ideas everyone, I'm reading up more on op amps. I was under the impression there was very little input current leakage, which made me assume they could be used in this case without draining the battery. Ben, thanks for the link, I'm looking to build this into a very small PCB, so that wouldn't work as a separate component, but I'll definitely investigate how it works. For some more details, I've been checking battery voltage by reading directly with a pin on an ATtiny. The device I'm working on has a on/of switch, which I'm interested in eliminating. The on/off switch completely cut off the battery from the circuit, but now I'm hoping to use a momentary button for on/off by temporarily pulling up an enable pin on a boost regulator, which would then be held high by a pin on the micro. When it finished doing it's thing, the micro would pull the enable pin low, basically cutting it's own power and turning everything off. But that would mean the battery would be connected permanently, which means if I want to read the battery voltage, I have to do so in some way that won't continually drain it 24/7, or at lest slow enough that the drain would be negligible. Link to comment Share on other sites More sharing options...
G+_Black Merc Posted February 6, 2019 Share Posted February 6, 2019 Chris O'Riley I'd investigate mp3 players... Some have that very function. See how they did the works. It may be as simple as a i2c connection to a battery management chip. Link to comment Share on other sites More sharing options...
G+_Paul Hutchinson Posted February 6, 2019 Share Posted February 6, 2019 Chris O'Riley I haven't used one and haven't read about them in many years but, IIRC the A2D inputs on an ATtiny have very low current draw so unless you choose an Op-Amp with lower input bias current it won't help. Also I seem to remember that at least some of the parts in the ATtiny line have an analog comparator built-in that IIRC has even lower input bias current than the A2D inputs. Link to comment Share on other sites More sharing options...
G+_Chris O'Riley Posted February 7, 2019 Author Share Posted February 7, 2019 Thanks! I'll definitely look into that. I've been wanting to use an op amp for something, just to get more of a handle on how they work, but maybe it would just over complicate things for little if any benefit in this case. Still figuring all this out as I go! Link to comment Share on other sites More sharing options...
G+_John Sullivan Posted February 7, 2019 Share Posted February 7, 2019 Chris O'Riley Learning how OpAmps work is fine, but you might not want to use one for this project. The ATtiny can do what you want. Adding any other device (such as an OpAmp) will only draw more current and defeat your purpose. You'll need an ATtiny programming board, something like this: sparkfun.com - Tiny AVR Programmer - PGM-11801 - SparkFun Electronics and the free Arduino software. Plus you'll need to install the proper drivers into the Arduino software to recognize the ATtiny, but all that is easy enough. Link to comment Share on other sites More sharing options...
Recommended Posts