43oh

# Battery voltage in a byte with 10mV resoution

## Recommended Posts

##### Share on other sites

I don't think the internal reference will provide 2.5V when VDD drops below that value. You will probably have to go with 1.5V as reference.

##### Share on other sites

As for the map function, I would approach it like this:

Simplify (and avoid divisions) by choosing a divider that converts a voltage like 5.12 to VREF.

E.g.

- with VREF 1.5V, the voltage divider would require a factor of approximately 3.4 (5.12V / 1.5V), this represents an ADC10 reading of 1024

- for 3.6V you'll get an ADC10 reading of approx. 723. ADC36 = (1024 / 1.5V) * (3.6V / 3.4)

- for 1.8V you'll get an ADC10 reading of approx. 361. ADC18 = (1024 / 1.5V) * (1.8V / 3.4)

- conveniently, ADC36-ADC18 is 362, which is close enough to 2 * 180 for our purpose

##### Share on other sites

the MSP430 minimal voltage supply is 1.8v. Most power supplies are +/- 10% over temperature and needs to be taken into account. If the voltage drops below 1.8v you might see unexpected behavior.

##### Share on other sites

According to the msp430g2553's data sheet, it needs 2.2v for the 1.5v reference and 2.9v for the 2.5v reference. The minimum Vcc for the ADC is also 2.2v, so to accurately measure voltage below 2.2v you will need an external ADC. If you are happy to measure in the range of 2.2v to 3.6v, ADC channel 11 is Vcc/2, so you can get the voltage with analogRead(11). Set your reference voltage to 1.5v first and do a read. If the result is 1023 (2^10 - 1), you know Vcc is above 3v so the 2.5v reference is valid. Set the reference to 2.5v and read it again.

For 10mV per bit and 8 bit output, we simply choose an offset, let's say 2v since we can only measure down to 2.2v, then use map. If we used the 1.5v reference, 2v Vcc would give us a reading of 683 (1/1.5*1024), if we could read that low. A 3v reading would yield 1023, and we would want an output of 100 meaning 2v + 1v, so we would use map(reading,683,1023,0,100). If we took our reading from the 2.5v reference our physically impossible but theoretical reading for 2v would be 409 (1/2.5*1024), 3.6v would yield 737 (1.8v/2.5v * 1024), and we would want a value of 160 to represent 3.6v, so our map function would be map(reading,409, 737,0,160).

Sent from my iPad using Tapatalk

##### Share on other sites

G'day,

Thanks for the detailed feedback. As I'm using a LFePO4 battery (3.2v), in reality only need a  maximum range of one volt. So will give Graham's solution a shot today.

Grant.

## Join the conversation

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

×   Pasted as rich text.   Paste as plain text instead

Only 75 emoji are allowed.

×   Your previous content has been restored.   Clear editor

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

×
×
• Blog

• #### Activity

×
• Create New...