Convert ADC Value

Go To Last Post
11 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hy all!

I had a problem.
I use AT90S8535 .
I made an ADC conversion, and I need to calculate for examlpe to Voltage.
For example in 10 bit.

5V = 1024
ADC 230 bin = V?
I know the formula Value in bin x5V
----------------------- =? V
1024

I want to show in LCD the measured Value. But this often 0.xxxx
How I could do this?

Thanks a lot by Nber....

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Don't know if I truly understand you're question, but if you're looking for the general ADC formula, it is: D = Vin*(2^n-1) / Vref
Where D is the binary result of you're conversion, n are you're number of bit resolution, and Vref is you're reference voltage. Using a 10-bit converter, you have 1024 (2^10) steps, you're highest binary number (representing 5V and above) are therefore 1023. When Vref=5V, the input voltage that corresponds to the binary number 230 is; Vin = (230*5 )/1023 = 1.12V

omella

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Ok my problem is the follow.
I get an ADC value example 512 bin
the following formula : Value*5 /1024
512*5 = 2560
So the result is 2560/1024 16 bit divide
2 and the remainder 512 dec
I need to divide this one .
So i think I check if the Div smaller then the Divisor. Then multiple 10 and check again.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Ok the simply question how could i do a DVM with Atmel.
This is the finall question.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

How about:

V = (Vin / 1023) * Vscale, for the 10 bit AVR ADC.

Then,

V = (Vin / 65535) * Vscale, for a 16 bit ADC.

Vin / 1023 forms a fraction, which is then multiplied by the scale factor that you will be measuring.

Obviously, this won't work to well for integer math. But the numerator (Vin) can be multiplied by 2^n to to acheive the desired resolution.

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

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Take your formula:
Value*5/1024

If you want to have two digits behind the decimal point, compute:
100*Value*5/1024 or Value*500/1024 or Value*125/256
instead.

unsigned int Result;
Result=(unsigned int)((unsigned long)Value*125)>>8);

For an ADC value of 512, you get a result of 250. Convert this to a string and insert a '.' at the correct position.

Jörg.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I got a couple of servos at skycraft for $2 ea. they have a 3 pin connector... 2 pins and 1 pin || | Which pin is which I wonder?

Imagecraft compiler user

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hey Bob there are only 3 pins. You can burn only 3!=6 servos in the worst case! :lol:
Kostas

It's better to keep your mouth shut and think you a fool, than open it and move out the doubts!

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Ok let' see the JBecker answer.

If i had a n ADC Value for example 1000 bin.
To Calculate a Value to display on the LCD

(Value* 5) /1024 = V

JBecker sad 100* 1000 /1024 the problem is 100*1000 = 100000 this bigger 65535 so I can't calculate because I had a 16 Bit registers.
But this look be the easiest way.
I made a Flow Diagram How I could calculate the correct value.
First ADC Value * 5
Then Divide with 1024 .
The only problem is to check everytime the Remainder and than Multiply with 10 then Divide again.
I'm afraid this will take too long time.
The reason why I make a topic to find the best way to Calculate an ADC input to Voltage

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Quote:

JBecker sad 100* 1000 /1024 the problem is 100*1000 = 100000 this bigger 65535 so I can't calculate because I had a 16 Bit registers.

Use two of them, then you have 32 bits 8)
Don't you use a C compiler? Did you understand my code snippet?
Quote:

I'm afraid this will take too long time.

'Waiting' for your LCD to get ready (!busy) will take much longer. How many refreshs per second do you want to do? 3 to 4 per second is ok for a textual display. Would be different if you use an LED bar graph.

Trying to avoid adding lengthy library code as printf, I sometimes use the following routine:

void PrintVal(unsigned int usVal, unsigned char ucDigits, unsigned char ucComma )
{  unsigned int n;

   if (ucComma)                      // decimal point to be printed?
   {
     if (ucComma=ucDigits-ucComma)   //
        ucDigits++;                  // add one digit for '.'
     else
        ucComma = 99;               // print leading zeros (e.g. 007)
   }
   usPrintstring[ucDigits]=0;       // null-terminate string in advance
   while (ucDigits--)
   {
      if(ucComma || usVal)          // if something is left for printing
         n = (usVal%10)+'0';
      else
         n = ' ';                  // leading spaces
      if (ucComma)
      {
         if (ucDigits==ucComma)
         {
            usPrintstring[ucDigits]='.';
            ucDigits--;
            ucComma = 0;
         }
      }
      usVal = usVal/10;
      usPrintstring[ucDigits]=n;
   }
}

It puts the result into a null-terminated string, which can then be send to an LCD or RS232 ...

Try to find out, how the parameters work. There should be some work left for you, too. :)

Jörg.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Thanks for your help.

I try to understand the C sample because I jus only programming in assemby.

By Nber...