Jump to content

Battery voltage in a byte with 10mV resoution

Recommended Posts

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.



- 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


To get this into your 8bit scale with 1 step per 0.01V, subtract ADC18 from your actual reading and divide by two:

byteout = (ADC - ADC18) / 2

Link to post
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

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...