## How can I measure voltage in range 0 to 10 V with 0.1 volt accuracy in an ADC in a microcontroller for scaling?

14 posts / 0 new
Author
Message

Hi all.
i have been provided with a task and i need a solution to this. I am not sure if this is logical or not.

If not please pardon me ! and do correct me.

I have a voltage regulator ranging from 0 to 10 volts DC which must act as an analog input to a micro-controller (MC) to perform a specific task.

for example

consider a rage of 0  to 2 volts DC
at this range three digital out pins of a micro-controller must be reserved for a task.

*at 0 volts digital pins D0 D1 D2 must be all LOW

* at 1 volts digital pins D0 and D1 must be HIGH and D2 must be LOW

(This is basically the programming logic  )

at range 2 to 4 volts other set of digital pins D3 D4 D5 must be reserved.

I want to know how this voltage range of 0 to 10 volts  should be minimised in a set of [(0-2), (2-4),(4-6),(6-8),(8-10) volts] so that it can be fed to the MC for getting the desired output.

Last Edited: Fri. Feb 5, 2016 - 05:30 AM

Hello Elvis.

I am afraid that I have not understood all of your explanation. What I have understood is that 0 volts corresponds to 0 volts and at 1 volt D0 and D1 are both high (1) with the rest at low (0 volts). Summarised in quasi logic table this would look like this...

... meaning that each LSB is equivalent to one third of a volt.

Is that what you meant?

The rest I don't follow...

Cheers,

Ross

Ross McKenzie ValuSoft Melbourne Australia

Sounds like a school project.

Have you studied Ohm's Law and a simple voltage divider using two resistors yet?

If you are using a Mega for your micro, and powering it with Vcc = 5 Volts, then the MAXimum allowed on the ADC input pin is 5 V.

You must attenuate, or divide, the 10 V input voltage down to a lower maximum voltage.

You use a resistor divider to convert 0 to 10 V to 0 - 5 volts.

You feed the new, reduced, voltage into the ADC and read the value.

Your software then decides which range the input voltage is within, and it lights up the LEDs accordingly.

For example, 3 V input, through the attenuator would be 1.5 volts, (it is reduced by 1/2).

The ADC is 10-bits, to the output is 0 - 1023.

0 = 0 V input

1023 = 5 V input

307/1023 * 5 = 1.5 V

1.5 V * 2 = 3 V at the input.

ARef is set to the Internal Vcc (5 V) reference.

In practice you will probably want to connect a 10K pot between Vcc (5V) and Ground, and connect the wiper to the ADC input.

Connect an LCD to the micro to read the ADC count value.

Use a voltmeter to read the actual voltage on the pot going into the ADC.

Check your code and understanding to make sure the LCD is giving you the correct value for the input voltage.

Know, also, that you could make the input voltage divider any ratio you want, as long as the output is < = 5 V when the input is at its maximum, (10 V in your stated example).

It might be wiser to make the attenuation factor 1/3 instead of 1/2, then a little over voltage on the input won't damage the ADC input.

JC

Hi Ross

Thank you. But, that is not what i actually meant .
I want to convert the voltage range of 0 to 10 volts DC input to an equivalent scale of 0 to 5 volts with an accuracy of 0.1 volts so that it can be read by the Micro-controller.

Well then your...

* at 1 volts digital pins D0 and D1 must be HIGH and D2 must be LOW

(This is basically the programming logic  )

"specification" is cr*p information.

Why don't you simply copy your professor's assignment word for word instead of inaccurately paraphrasing it.

Ross McKenzie ValuSoft Melbourne Australia

And... in case your "teacher" has not introduced the terms yet... accuracy is not resolution. And you are mixing the two concepts in your texts above.

I'm out.

Ross McKenzie ValuSoft Melbourne Australia

valusoft wrote:
"specification" is cr*p information.

Not necessarily. The 0.1 Volts is the accuracy. The 0-2, 2-4... is about resolution.

elvis_hilo wrote:
want to convert the voltage range of 0 to 10 volts DC input to an equivalent scale of 0 to 5 volts

A voltage divider has already been mentioned.

elvis_hilo wrote:
with an accuracy of 0.1 volts so that it can be read by the Micro-controller

The voltage divider is an analogue arrangement so (virtually) no accuracy will be lost.

You then are left with the task of using the ADC to sample and convert the 0-5 Volt signal. This should be with a corresponding resolution of 0.1 Volts at the 0-10 Volts scale, and thus a resolution of 0.05 Volts resolution at the 0-5 Volts scale. That is 100 discrete values well within the range of the AVRs ADC. It has a resolution of 10 bits (i.e. 1024 discrete values), giving you a resolution of roughly 0.005 Volts.

As of January 15, 2018, Site fix-up work has begun! Now do your part and report any bugs or deficiencies here

No guarantees, but if we don't report problems they won't get much of  a chance to be fixed! Details/discussions at link given just above.

"Some questions have no answers."[C Baird] "There comes a point where the spoon-feeding has to stop and the independent thinking has to start." [C Lawson] "There are always ways to disagree, without being disagreeable."[E Weddington] "Words represent concepts. Use the wrong words, communicate the wrong concept." [J Morin] "Persistence only goes so far if you set yourself up for failure." [Kartman]

Johan,

The 0.1 volts "information" was added to the title AFTER my first post. As I said a cr*p specification.

I am still out.

Ross

Ross McKenzie ValuSoft Melbourne Australia

I'm not really "in".. I'm willing to wrestle with the OP, but you know my position (as an old teacher): School assignments should be solved by the student.

As of January 15, 2018, Site fix-up work has begun! Now do your part and report any bugs or deficiencies here

No guarantees, but if we don't report problems they won't get much of  a chance to be fixed! Details/discussions at link given just above.

"Some questions have no answers."[C Baird] "There comes a point where the spoon-feeding has to stop and the independent thinking has to start." [C Lawson] "There are always ways to disagree, without being disagreeable."[E Weddington] "Words represent concepts. Use the wrong words, communicate the wrong concept." [J Morin] "Persistence only goes so far if you set yourself up for failure." [Kartman]

My business slogan is "Solutions through understanding" for a good reason. If this guy is incapable of describing what he has to do, there is no chance of a solution evolving except through random chance.

Ross McKenzie ValuSoft Melbourne Australia

My personal favorites for solving a problem like this are:

```Y - mX+b
Where:
Y = the magnitude of the vertical axis
m = the slope of the line of the graph
X = the magnitude of the horizontal axis
b = the offset in the vertical axis
Y2 - Y1
m = -------
X2 - X1```

and:

```                    ViR2
Vo = Vi * (R2/R1) = ----
R1```

I routinely solve voltage translation problems using these two equations and a bit of basic algebra.

In my opinion, these two equations and some basic algebra are some of the most useful tools available to electronics technicians who are dealing with basic analog circuits and their application in the micro-controller field.  As a production technician in a fast pace PCB assembly house, I use these two equations almost daily, in some form or another.

I have attached a "Cheat Sheet" shows the use of these equations for just such a problem as you describe.

The information presented here should give you the tools to solve your problem on your own, provided you take the time and make the effort.

## Attachment(s):

You can avoid reality, for a while.  But you can't avoid the consequences of reality! - C.W. Livingston

It seems the original post has been edited, but this looks like a super simple problem that can be solved with 2 identical resistors and less than 20 lines of code to me. I'm siding with the Swedish contingent on this one and am going to sit this one out. Note also, I am a former teacher as well and I am not siding with the Australians because of the Marmite and Fosters thing. And the drop bears.

Actually, Ross posted this: " If this guy is incapable of describing what he has to do, there is no chance of a solution evolving except through random chance." so I have to agree with him as well.

Last Edited: Sun. Feb 7, 2016 - 12:15 PM

Surely Marmite is British. Do you mean Vegemite and Fosters? Sounds like a foul-tasting combination.

I did have a jar of Guinness Marmite a few years back, though, so I may be wrong.

I am a big fan of yeast.

Four legs good, two legs bad, three legs stable.