• Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

Storing Decimal Binary - ADC

Status
Not open for further replies.

devonsc

New Member
Hi, would like to ask how do we store a converted value from the ADC module which has decimal point?

For instance, if I feed the ADC module with 1.25V, then I intend to store the converted binary value. Does it mean that I have to break it up into two? As in something like =>

"00000000.00000000" by having those bits before the decimal point store in one register and bits after decimal point being store in another register? If yes, how do I do it? Sorry again if this is nonsense....Thanks :oops:
 

Nigel Goodwin

Super Moderator
Most Helpful Member
There's no need to store it as decimal at all, store it as binary instead (assuming you need to store it at all?) and only convert it when you need to display it as decimal.

Likewise, there IS no decimal point (or there shouldn't be!), floating point maths is long, complicated, slow, and inaccurate - stick to integers instead.

If you check my analogue tutorials you'll see what I mean!.

My analogue tutorial board is set to give an input range of 0-10.23V, with the A2D giving out 0-3FF. To display it I use a 16 bit binary to decimal conversion routine - this returns each digit in a register, named Units, Tens, Hundreds, and so on.

As the input value is 10 bit (maximum 1023) we can ignore the Tenthousands register, and just use the bottom four. We know that 1023 actually represents 10.23V, so we simply display the Thousands register, the Hundreds register, display a decimal point, then the Tens register, followed by the Units register.

Dead easy, no messing about with decimal points, we already know EXACTLY where it should be placed, and insert it accordingly.
 

bmcculla

New Member
There is something called fixed point notation that is much easier to deal with than floating point because you can use integer operations.

1011binary = 1*2^3 + 0*2^2 + 1*2^1 + 1*2^0 = 11decimal

10.11bin = 1*2^1 + 0*2^0 + 1*2^-1 + 1*2^-2 = 2.75dec

The big equasion just uses the mathematical representation of the number to show how you detirmine the decimal value. It's the same with decimal - 32.4 = 3*10^1 + 2*10^0 + 4*10^-1

You just have to remember that "bits are bits". The bits are the same - both 1011 - but how you treat them is different. With fixed point you can use all the integer operations you just have to keep track of where the decimal point is and use that to display the number correctly in decimal.
 
Status
Not open for further replies.

Latest threads

EE World Online Articles

Loading
Top