16 bit ADC with SX/B

TCTC Posts: 1,019
edited 2010-12-04 - 15:14:32 in Microcontrollers
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.

Comments

  • ZootZoot Posts: 2,227
    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
    
  • TCTC 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.
  • ZootZoot Posts: 2,227
    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.
Sign In or Register to comment.