Jump to content

Multi-battery Voltmeter

Recommended Posts

Hey guys, thought I'd post something I made this month to learn about interrupts and state machine coding. This project just measures up to four sub-1.5V batteries and shuts down after four seconds. I chose to not have the project run off the batteries it tests. I had a ton of 18650 lithium cells, and used one. I had a little trouble thinking of a way to power the LCD as it really needed more than 3.6V to read any characters on it. Using a lithium cell is convenient as the screen is nice and legible throughout a big portion of the cell's working voltage. As of right now, the whole circuit consumes 8mA when displaying a measurement, and around 5mA when the screen is off. I'm pretty sure I can cut down more by switching the 595 and the LCD's power with a transistor when the G2231 enters LPM, at the expense of a slow (50ms) turn on time when taking a measurement.
I ended up not using LPM in the delay and ADC measurement code, as that stuff happens in bursts.


Do you guys suggest any other small improvements I can add to this? 

And finally is there a decent way to safeguard against negative voltages on the ADC inputs? The only components I have on each input are pulldown resistors to remove floating ADC inputs.


Code posted here:

Version 2.c

Link to post
Share on other sites
  • 2 weeks later...

Nice setup. Did you use the pins for the 32Khz crystal for anything or have any plans to? Had you considered a 5v switching regulator for the display(I had similar issues with the display not showing up very well on lower voltages). I think the transistor idea for the LCD panel enable/disable would be useful. If you don't use the pins for the crystal, you could also use those pins for for button actions(start/stop) or other things.

Link to post
Share on other sites

To protect the inputs I'd change them as follows:


This provides protection against both over voltage and negative voltage. The resistor values are not critical. If you use a lower value for the input resistor, it increases the maximum current that can flow, hence reducing the voltage range that it can safely shunt. The tie down resistor has been increased to reduce the voltage divider effect. With a 1:1000 ratio the error from the voltage divider is negligible. Over voltage is clamped at 3.6v while negative voltage is clamped to approx -0.6v. With the 100 ohm input resistor, a typical 400mW Zener can protect against an over voltage of approx 15V. Dropping the input resistor to 50 ohm reduces the over-voltage tolerance to about 9V.



Sent from my iPad using Tapatalk

Link to post
Share on other sites
  • 2 weeks later...

@@voodoofish, I setup P2.6 & P2.7 as button inputs. I forgot to edit that picture, but I didn't use an LM317 as a regulator. I used a regulator from Texas Instruments, something in 5-pin sot package.


@@grahamf72, thanks for the sample circuit. I looked at the protection diodes built into the microcontroller, and they can drop something like 0.3V but only handle 2-3mA safely. I think I can get away with a 1k/100K divider like your circuit, but ditch the zener that way. Is the mux resistance of the ADC taken into account when processing the result? Does it load the newly created voltage divider?


Sorry I haven't checked the forums in a couple weeks :(

Link to post
Share on other sites

I figured that I can get away without using some form of over voltage protection, as I planned on a line of battery slots that could only fit AA and AAA sized batteries. The only time a voltage outside of the range of +/-1.5V is if the user found a lithium battery for that size, and the worst case is that battery is 4.2V. That would be the only case of over-voltage, but let's look at how the circuit would handle such cases.

There are a few assumptions for the circuit: 
Supply Voltage is 3.6V
Series Resistor is 1K ohm
Built-in diode drop is 0.3V

Those diodes would consume (4.2 - 3.6 - 0.3V) / 1000 = 0.3mA  and that's pretty convenient.
But let's look at the circuit when that same battery is flipped turned upside down.


Diode current is now (4.2 - 0.3V) / 1000 = 3.9mA! Too much for those diodes!
Using a 2.2K resistor drops that down to 1.77mA, which just barely handles the current.

Now one thing to consider is the addition of a pull-down resistor on each ADC input to eliminate floating measurements. A 100K value reduces current consumption for the measured battery, so it could be forgotten in the meter, and not drain. It also makes a voltage divider that wouldn't seriously alter the measurement, for the average joe consumer who wouldn't bat an eye between 1.22V and 1.19V (example measurements).


Now in this particular situation the user would be covered against their stupidity, and for most cases where a AA alkaline battery was upside down, those diodes could handle it easily.


Also is the minimum time to sample the ADC and get a decent reading. The User Guide gives the following formula: Tsample > (Rsource + Rmux)*ln(2^11)*27pF
Using a 2.2K resistor, the formula now becomes (2200 + 1000)*ln(2^11)*27pF = 659ns

659ns is fast, so pretty much any prescaler settings with the G2231 running at 1MHz will give an accurate result.

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...