Welcome to the Parallax Discussion Forums, sign-up to participate.

# 16 bit ADC with SX/B

Posts: 1,019
edited 2010-12-04 - 15:14:32
I am wondering how to take a 16 bit value from an ADC and convert it to a value I can display on a LCD? I am looking for a resolution .001V. There are only 3 voltages I will be reading 3.3V, 5V, and 12V. I will appreciate any help.
"CONFIDENCE"
The Feeling you get before you truely understand the situation.

• Posts: 2,226
edited 2010-12-03 - 12:18:37
This is not efficient, but it should be clear and should work.

If you want to convert your Word value to "volts" with decimal, you'd need to supply more info (like what range of values is your ADC giving you)
```chars VAR Byte(5)
val VAR Word
idx VAR Byte

chars(4) = val/10000 ' ten thousands
chars(3) = val//10000
chars(3) = chars(3)/1000  ' thousands
chars(2) = val//1000
chars(2) = chars(2)/100 ' hundreds
chars(1) = val//100
chars(1) = chars(1)/10  ' tens
chars(0) = val//10 ' ones

FOR idx = 0 TO 4
chars(idx) = chars(idx) + "0" ' convert to ascii char
ENDIF

' now if you dump chars(0)...char(4) to an LCD, you'll have a 5 digit number that shows val
```
When the going gets weird, the weird turn pro. -- HST

my site: 1uffakind.com
create bitmap data tool: 1uffakind.com/robots/povBitMapBuilder.php
convert images to ascii art: 1uffakind.com/apptoys/convtoascii/
MC6808/Hero-1 assembler: 1uffakind.com/apptoys/onlinecompilers/MC6800/
• Posts: 1,019
edited 2010-12-03 - 13:04:13
I am so new at this; I am used to using PBASIC. Thank you ZOOT for the info I completely forgot that I can use a WORD modifier. I am also trying to learn ASM, and that is where I got confused. I thank you for your time.
"CONFIDENCE"
The Feeling you get before you truely understand the situation.
• Posts: 2,226
edited 2010-12-04 - 15:14:32
The sample I put up is pretty "Pbasic-ish". As I said, it is not very efficient, either cycle-wise or codespace-wise. At the least, division and modulus should really be wrapped inside functions to save space.
When the going gets weird, the weird turn pro. -- HST

my site: 1uffakind.com
create bitmap data tool: 1uffakind.com/robots/povBitMapBuilder.php