8 bit ADC problem
Eric G
Posts: 2
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
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
' 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
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
_________________________________________________
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
do you want to measure AC or DC ?
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Greetings from Germany,
G
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
http://www.allaboutcircuits.com/vol_1/chpt_8/4.html
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
John J. Couture
San Diego Miramar College