Go Down

Topic: How to measure a supply voltage to arduino uno? (Read 4202 times)previous topic - next topic

omarshabrani

Mar 01, 2017, 03:03 pm
I have a project
that i should use 3.7 v battery and measure the batterie's voltage !
I just used the analogRead and analogreference but hasn't worked
If any one can help me I will be grateful

Groove

#1
Mar 01, 2017, 04:56 pmLast Edit: Mar 01, 2017, 04:57 pm by Groove
Use the band-gap reference and a voltage divider on the input.

Don't forget to credit me in your assignment write-up.

jremington

#2
Mar 03, 2017, 04:00 am
Or credit Scott at https://provideyourown.com/2012/secret-arduino-voltmeter-measure-battery-voltage/
But the factor of 1023 is wrong. It should be 1024.

GolamMostafa

#3
Mar 27, 2017, 11:53 am
Quote
But the factor of 1023 is wrong. It should be 1024.
1. Assume Vref to the ADC = 5V.

2. The Full Scale (FS) of the ADC is 5V.

3. FS ia 5V; it menas that the all 10 output bits will assume LH-states when 5V is applied to the

4. The decimal count of 11 1111 1111 = 1024-1 = 1023.

5. The correct factor is 1023 and not 1024.

AWOL

#4
Mar 27, 2017, 02:14 pmLast Edit: Mar 27, 2017, 02:21 pm by AWOL
1. Assume Vref to the ADC = 5V.

2. The Full Scale (FS) of the ADC is 5V.

3. FS ia 5V; it menas that the all 10 output bits will assume LH-states when 5V is applied to the

4. The decimal count of 11 1111 1111 = 1024-1 = 1023.

5. The correct factor is 1023 and not 1024.

The correct factor is 1024, your reasoning is incorrect.
Please refer to the data sheet.
"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.
I speak for myself, not Arduino.

jremington

#5
Mar 27, 2017, 05:13 pm
Quote
5. The correct factor is 1023 and not 1024.
This is a common misunderstanding and has been debated many times.

To help understand the error in your reasoning, pretend that the ADC has only two bits, with a reference of 1 V, and work out what voltages the individual ADC output values will represent, when using either 3 or 4 as the divisor.

AWOL

#6
Mar 27, 2017, 05:51 pm
Better still, go for the full reductio ad absurdum, and imagine a one bit ADC.
"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.
I speak for myself, not Arduino.

GolamMostafa

#7
Mar 27, 2017, 07:57 pmLast Edit: Mar 27, 2017, 08:06 pm by GolamMostafa
1. My reasoning has been seen as 'incorrect (@AOWL)' and not 'wrong'. It has left enough space for my

2. My reasoning has also been said to contain 'error (@jremington)'. There is also, as I see, room for
my reasoning to be compensated.

3. We (including many others) differ by only one count.
(a) http://www.microchip.com/forums/m589143.aspx
(b) -------------

4. Data sheets of ATmega328 says: ADC (output value) = (Vin/Vref) * 1024

The data sheet does not explain the rationality of the inclusion of the figure 1024, as it is not a
text/design book.

5. We may try to explore the theory of SAR type ADC to see the root cause of the difference of
1 count and then decide which one (1023 or 1024) is the reasonable figure.

Assume 10-Bit SAR type ADC; Vref = 5V; Vin = 5V

Bit Set (Internal DAC Input)    Clocking Pulse Injected      DAC Output         EOC
B9                                          512                                  2.5V (Vref/2)      inactive (0)
B8                                          256                                 +1.25V                0
B7                                          128                                 +0.625V               0
B6                                          64                                   +0.3125               0
B5                                          32                                   +0.15625V           0
B4                                          16                                   +0.07125V           0
B3                                          8                                    +0.0390625V        0
B2                                          4                                    +0.01953125V      0
B1                                          2                                    +0.009765625V     0
B0                                          1                                    +0.0048828125V   active (1)
------------------------------------------------------------------------------------------------------------
11 1111 1111                          1023                                4.9951171875V     Conversion done

(a) The ADC logic has found active 'conversion done' status after pumping 1023 clocking pulses
though the voltage produced by the internal DAC is less than the actual Vin by 0.0048828125V.

(b) The ADC logic could make the DAC's output equal to the actual Vin by pumping another clocking
pulse; but, at the cost of making 0s for B9-B0. Thanks to the smart ADC that it does not do it.

6. Should we accept 1023 at the accommodation of the error of only 0.0048828125V or 1024 at the

jremington

#8
Mar 28, 2017, 02:24 amLast Edit: Mar 28, 2017, 02:25 am by jremington
The correct value to use is the number of steps in the interval, 1024. That is simple mathematics, and has nothing to do with the data sheet.

Granted, the difference between 1023 and 1024 is not large. However, if you investigate the two-bit and one-bit ADC examples that we suggested in previous posts, you should then understand the point.

GolamMostafa

#9
Mar 28, 2017, 04:39 am
The correct value to use is the number of steps in the interval, 1024. That is simple mathematics, and has nothing to do with the data sheet.

Granted, the difference between 1023 and 1024 is not large. However, if you investigate the two-bit and one-bit ADC examples that we suggested in previous posts, you should then understand the point.
1. Most of the times, the ground-level fact remains encapsulated by our apparent perceptions. It is
hard to understand through cognitive process unless clear (theoretical and practical) examples are
demonstrated.

2. We clearly see that the opinions are in divided between 1023 and 1024.

3. If we taks FS as 4.9951171875V, the factor is certainly 1024; otherwise (for 5V FS), the factor is
1023 with error of 1 LSB.

jremington

#10
Mar 28, 2017, 05:39 amLast Edit: Mar 28, 2017, 05:40 am by jremington
Quote
It is hard to understand through cognitive process unless clear (theoretical and practical) examples are demonstrated.
Indeed. You haven't done the thought experiments we suggested.

Good luck with your efforts to grapple with these very challenging concepts!

GolamMostafa

#11
Mar 28, 2017, 10:25 am
Indeed. You haven't done the thought experiments we suggested.

Good luck with your efforts to grapple with these very challenging concepts!
Indeed. You haven't done the thought experiments we suggested.

Good luck with your efforts to grapple with these very challenging concepts!
Quote
grapple
1. Something that does not work in theory will never work in practice.

2. Something that works in theory may not work in practice.

3. In many cases, we fine tune theory based on the scientific (repetitions of the same
task under identical setup produce the same outcomes) observation.

3. To agree whether the factor will be 1023 or 1024, it is not enough to wish good luck; but, to
providing support with proper tools.

4. We can perform the following experiment using ArduinoUNO:
(a) Set the Vref at: 1.1V (internal).
(b) Connect AREF-pin to A0-pin.

5. The Monitor shows: 1023

6. If I am asked to calculate an unknown voltage (0<=Vin <=1.1V)fed at Pin-A0, I will certainly use
the factor (1023) of Step-5.

AWOL

#12
Mar 28, 2017, 10:45 am
Quote
5. The Monitor shows: 1023
...Which is what it would have showed had you connected a 1.2V source.
Go check the datasheet's ADC section.
"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.
I speak for myself, not Arduino.

GolamMostafa

#13
Mar 28, 2017, 11:19 am
...Which is what it would have showed had you connected a 1.2V source.
Go check the datasheet's ADC section.
Quote
So, Vin = k*1023 is 'wrong'; Vin = k*1024 is 'right'.

AWOL

#14
Mar 28, 2017, 11:29 amLast Edit: Mar 28, 2017, 05:09 pm by AWOL
Ok, here comes the half-fat reductio ad absurdum (because I'm posting on my phone).
You have a one bit successive approximation ADC.
It has a reference voltage of 1 volt (to keep the arithmetic simple).
It can return only two readings - zero or one.
What does the reading of one represent?
One volt?
Wrong.
It represents half a volt or greater.

"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.
I speak for myself, not Arduino.

Go Up