Newb type question - Reading voltage coming in.

Status
Not open for further replies.

Russ

Active member
I did some research and did not find a quick answer so I will ask.

Is there a way to read the voltage coming in. I found a write up for Arduino and it sounded like you could just bring your voltage in across to an analog pin and read it.

Can you do something similar on a Teensy 3? If so, is there a current limit?

Also, is there a fairly simple way to tell, from in a sketch, whether you are running from USB power versus external?

What I want to do is write a charger routine, basically a fuel gauage, that would kick in when you plug in usb power. It would read the voltage coming across the external source and do an led thermometer type routine to indicate how far along the charge was.

Thank you in advance for any input.
 
You can read the 3.3v supply voltage. Actually, you can read the internal reference voltage, using the 3.3v supply as a reference, and then do some math to work out what the supply voltage is, knowing the reference is always 1.2 volts.

However, the gives you the main 3.3v supply, not VIN. To read VIN, you would need to use a couple resistors to divide it down and feed it into one of the analog inputs.

Neither of those will likely give you a good "battery fuel gauge". Estimating battery charge is quite involved. I'm not an expert, but I do know it's tricky to do well. If you search for info, you'll probably find lots of info.... probably in the context of special chips to do the work.
 
Dedicated LiPo battery charger chips

I've been investigating making a battery charger/monitor board for the teensy3. I've been looking at dedicated chips for charging Lithium Polymer (LiPo) batteries, such as these very affordable bare cells from HobbyKing: 20C 1000mAh $2.50, 40C 5000mAh $12.04.

I would be careful to separate the two functions of "battery charger" and "fuel gauge." Charging LiPo cells is complex and involves both constant current and constant voltage phases. Charging NiMh batteries is more straightforward, but there are still intricacies. There are lots and lots of relatively inexpensive dedicated chips for this purpose. Fuel gauging usually refers to monitoring the discharge of the battery and predicting how much additional time it will deliver at the current discharge rate. There are also distinct chips that exclusively do this.

This blog post has links to an example circuit using the MCP 73831.

The real challenge is that there are just so dang many battery charger chips and sorting through their details is time consuming. I've spent some time doing this and the chips I'm most interested in are:

  • MCP73833-AMI/MF ($0.94) - Simple 2.75-6V 1S 1A Charger with temp.
  • MAX17048 ($2.85) - 1S Fuel Gauge.
  • MAX8934AETI+ ($5.33) 1.5 A charger and power selector with thermocouple and 3.3V 30mA LDO. This is a complete "power management" chip that can deal with completely discharged batteries, has both 3.3V and 5V outputs, but it's also a 28pin surface mount chip and probably over kill for most applications.

Note that these are all surface mount chips but they have relatively low pin count (except for that last one).

I have samples of these chips on hand I just haven't gotten a chance to work with them yet.

Best,

-c
 
Thanks for the replies.

Yeah, I have looked at separate fuel gauge boards and chips and such and knew they are out there. I was just looking for a simpler solution then adding another board to an already crowded mix here. I know that it would not be as accurate as a dedicated chip would be but I had found this: http://arduino.cc/en/Tutorial/ReadAnalogVoltage

The Arduino has a circuit inside called an analog-to-digital converter that reads this changing voltage and converts it to a number between 0 and 1023.

and I was just wondering if I could do something similar on the Teensy. (Sorry for not posting that reference yesterday.)

Cmason- I am already using a dedicated charger board on this. Just the basic LIPO charger from sparkfun, it seems to do the trick but it is very basic and does not report back, just charges.

Thanks again
 
Last edited:
The ATMega328 in the Arduino can run over a very wide range of voltages, anything from 1.8v to 5.5v, that's why you can run it without a regulator and monitor the battery voltage that way. The Teensy is a much more regulated chip, it needs 3.3v, just 3.3v, no more, no less, so it gets that from a regulator. If you want to see the actual battery voltage, you need voltage divider resistors into one of it's many analog pins.
 
Also remember if you want to compare against voltages other than the 3.3v reference, you can use the AREF pin, However I haven't looked at the datasheet to see what the maximums are though.
 
Thanks for the info Una. That actually made sense to this newbs brain ;p

So, I would knock down the voltage exponentially (say by a thousand) and could then read the voltage coming in from external and multiply it back up to get an approximate.

That said, what is a safe voltage range to apply to an analog pin? My power supply should always be in the range of 2.7v - 4.2v. That is the range on the batteries and the cutoff board should kill it above and below that. Dividing by 1000 (using a 10.2k ohm and 1.13k ohm resistor according to a calculator I found) would give a range between .27v and .42v. Is that ok or still too high.

Thanks again.
 
Also remember if you want to compare against voltages other than the 3.3v reference, you can use the AREF pin, However I haven't looked at the datasheet to see what the maximums are though.

Ok, now I will go research what the AREF pin is ;p

Thanks

edited in: Ok, just found this tutorial http://www.pjrc.com/teensy/tutorial4.html. It's amazing how much easier it is to find stuff once you know what terms you are looking for ;p

So, now I have something to play with.

Thanks again everybody. You have been very helpful.

Paul, your forum rocks !
 
Last edited:
The Teensy is a much more regulated chip, it needs 3.3v, just 3.3v

Actually, Teensy 2.0 can run from 5.5 to 2.7 volts, maybe even down to about 2.5 volts. Below 4.5 volts, slower clock speeds should be used. From Arduino, use Tools > CPU Speed.

Teensy 3.0 can run from 3.6 to 1.7 volts. It's rated for 48 MHz and probably works to 96 MHz (overclock) for this entire range.

Under 3 volts, the Teensy 3.0 SPI port is only specificed up to 12 Mbit/sec. At 3.3 volts, SPI is usable at 24 Mbit/sec. The AVR emulation for SPI only supports up to 8 MBit/sec, but if you're using Bill's SdFat library (or other code with native Teensy 3.0 SPI support), staying under 12 Mbit/sec is best if running at lower voltage. Of course, most SPI chips that can utilize those high speeds probably require 3.3 volts....

On all Teensy boards, the USB depends on having at least 3 volts to drive proper USB signals. If you run under 3 volts, the USB signal output will be weak... which might not work with all USB cables, hubs and computers.


Also, regarding the ATMega328 chip, the chip's range is indeed 1.8 to 5.5 volts, but that's not the whole story..... Just like Teensy 2.0, the maximum rated speed decreases at lower voltage. However, the Arduino Uno's core library does not support setting the speed from Tools > CPU Speed or any other convenient approach. The usual way involves soldering a different crystal. Even then, their code really only fully supports two speeds, 16 and 8 MHz... neither of which is slow enough to use the chip at the lower end of that voltage range.
 
Ok, now I will go research what the AREF pin is ;p

The AREF pin is an input for an external voltage source that can be used to compare voltages against instead of the 3.3v supply or the internal 1.2v reference. But like I said. I have no idea what voltage range it supports, or even how to change the compare source to use it instead of the 3.3v supply. I just know the pin exists, and what it's function is. I haven't actually tried to make use of it yet, or done anything that's needed it.
 
The AREF pin is an input for an external voltage source that can be used to compare voltages against instead of the 3.3v supply or the internal 1.2v reference. But like I said. I have no idea what voltage range it supports, or even how to change the compare source to use it instead of the 3.3v supply. I just know the pin exists, and what it's function is. I haven't actually tried to make use of it yet, or done anything that's needed it.

Thank you.
 
The K20 data sheet specs AREF to operate from 1.13 V to the 3.3 V supply of the IC. At lower voltages, you can expect some loss of accuracy because noise will be larger relative to the signal.
 
Status
Not open for further replies.
Back
Top