Go Down

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

omarshabrani

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 pm Last 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.
Per Arduino ad Astra

jremington


GolamMostafa

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
   input of the ADC.

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

5. The correct factor is 1023 and not 1024.

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
   input of the ADC.

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

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

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 pm Last 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
   reasoning to be corrected/adjusted.

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
   cost of loosing all the ADC value? The analogRead(x) will always read lower 10-bit.



   

jremington

#8
Mar 28, 2017, 02:24 am Last 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

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 am Last 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

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.
   (c) Perform Serial.println(analogRead(A0));.

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

Quote
5. The Monitor shows: 1023
...Which is what it would have showed had you connected a 1.2V source.
Your experiment proves nothing.
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

...Which is what it would have showed had you connected a 1.2V source.
Your experiment proves nothing.
Go check the datasheet's ADC section.
Quote
Your experiment proves nothing.
So, Vin = k*1023 is 'wrong'; Vin = k*1024 is 'right'.

AWOL

#14
Mar 28, 2017, 11:29 am Last 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