Shop OBEX P1 Docs P2 Docs Learn Events
8 bit ADC problem — Parallax Forums

8 bit ADC problem

Eric GEric G Posts: 2
edited 2005-10-11 23:39 in General Discussion
I am trying to use the Example Project "8bit adc" that is included in version 3.10 of the IDE to read the state of a 10 k pot. I have the circut hooked up exactly as shown in the example (one 10k resistor going from rb.2 and 1 10 k resistor from rb.3 to a common terminal hooked to a 0.01uF cap going to ground. with rb.1 going to the "wiper" pole of the pot and the fixed ends of the pot going to vcc and ground). the converter reads fine from 0 to 2.5 volts but from 2.5 volts to 5 volts it won't read any higher than decimal 170, even if rb.1 is tied directly to vcc. I've attached the sx/b file that i'm using. the only change i've made to it is changing the name of a variable from temp2 to temp3 since temp2 allready existed and the subroutine required a varible named temp3.

what am I doing wrong?

UPDATE

After downloading and examining the the projects folder in the SX/b 1.42 Update, an updated version of the project is there that works as advertised


old subroutine:

' Use: aVar = GET_ADC
' -- returns 8-bit value of voltage on RB.1

GET_ADC:
temp1 = 0 ' reset result
temp2 = 128 ' bias to middle
DO
temp1 = temp1 + temp2 ' create test value
PWM AdcChrg, temp1, 1 ' charge RC
CMP_B = temp3 ' compare inputs
IF temp3.0 = 1 THEN ' if unknown lower
temp1 = temp1 - temp2 ' reduce test value
ENDIF
temp2 = temp2 >> 2 ' divide bias
LOOP UNTIL temp2 = 0
RETURN temp1


new subroutine:

' Use: aVar = GET_ADC
' -- returns 8-bit value of voltage on RB.1

GET_ADC:
FOR temp1 = 0 TO 255 ' loop through values
PWM AdcChrg, temp1, 1 ' charge RC
CMP_B = temp2 ' compare inputs
IF temp2.0 = 1 THEN EXIT ' exit at input level
NEXT
RETURN temp1

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
_________________________________________________

Post Edited (Eric G) : 10/10/2005 10:46:53 PM GMT

Comments

  • Jon WilliamsJon Williams Posts: 6,491
    edited 2005-10-11 00:23
    Sorry that's my fault for "editing" a working program after I stick it into the help file.· Aside from the change of the second "temp2" to "temp3", here's the corrected (high-speed; takes just eight loop iterations to find voltage input) subroutine.· It works -- I just copied this out of my editor.· The next release of the help file will include this fix.

    ' Use: aVar = GET_ADC
    ' -- returns 8-bit value of voltage on RB.1

    GET_ADC:
    · temp1 = 0···································· ' reset result
    · temp2 = 128·································· ' bias to middle
    · DO
    ··· temp1 = temp1 + temp2······················ ' create test value
    ··· PWM AdcChrg, temp1,·1······················ ' charge RC
    ··· CMP_B = temp3······························ ' compare inputs
    ··· IF temp3.0 = 1 THEN························ ' if unknown lower
    ····· temp1 = temp1 - temp2···················· '·· reduce test value
    ··· ENDIF
    ··· temp2 = temp2 >> 1························· ' divide bias
    · LOOP UNTIL temp2 = 0
    · RETURN temp1

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax

    Post Edited (Jon Williams (Parallax)) : 10/11/2005 12:26:59 AM GMT
  • Eric GEric G Posts: 2
    edited 2005-10-11 03:44
    Thanks, that works a whole lot better, and it's faster than what I was using.

    -eric

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    _________________________________________________
  • John CoutureJohn Couture Posts: 370
    edited 2005-10-11 14:36
    Jon,

    How would you read Amperage on an ADC?

    I was thinking of a cute little project whereby an SX reads the voltage and current draw on my master power supply and displays it on an LCD.

    Say something like 0 to 1 amp?

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    John J. Couture

    San Diego Miramar College
  • Guenther DaubachGuenther Daubach Posts: 1,321
    edited 2005-10-11 16:05
    John,

    do you want to measure AC or DC ?

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Greetings from Germany,

    G
  • PaulPaul Posts: 263
    edited 2005-10-11 16:51
    John,
    You can read DC Amps by using a 'shunt' resistor. This is usually a 3-10 watt resistor with a value of .1 to .005 ohms. The ADC just reads the voltage drop across the resistor and calculates the current. Too much resistance will degrade your output voltage.
    AC Amps is a whole different animal. Current transformers and precision rectifiers..shudders.

    Paul
  • John CoutureJohn Couture Posts: 370
    edited 2005-10-11 23:39
    Great! Thank you! With that information I was able to google shunt resistors and came up with an interesting tutorial on Ammeter design. Thank you again.

    http://www.allaboutcircuits.com/vol_1/chpt_8/4.html

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    John J. Couture

    San Diego Miramar College
Sign In or Register to comment.