Frustration with ADC (was TLC1549)
Archiver
Posts: 46,084
Thanks to those who helped with my problems with the tlc1549 10bit
adc. I am now getting legit data, and the problem was simply that
there was overflow to my variables giving me wierd numbers.
New problem though. I have the adc hooked up to a multiplexing IC
that I switch with the stamp between different sensors. What is
happening though is that it seems the adc is caching the result from
the previous sample, and then sending it out on the next request.
In other words if I have: (this is just the theory not the real
code!)
Start loop:
switch to sensor 1
take reading
output sensor 1 reading
switch to sensor 2
take reading
output sensor 2 reading
goto loop
... then I see the sensor 1 reading on the sensor 2 output and the
sensor 2 reading on the sensor 1 output! Similarly, if I have 3
sensors in the loop, sensor1 reading has sensor3 value, sensor2
reading has sensor 1 value, and sensor 3 reading has sensor 2 value.
I am 1000% sure that my hookups are correct, and that the input
states for the demux are correct, and that the programming is cool.
There is something going on with the adc.
If I call the "getCurrentVoltage" 2 times in a row before putting
the value into a variable, it works. (You can see the commented out
calls in the code below.) I have tried cycling CS high and low
several times before retrieving data, but that doesn't seem to reset
the reading. I can't find anything in the Tech sheet about
buffering results, or whatever is going on. Any ideas? Help!
'{$STAMP BS2}
adcbits var word
CS CON 11
CLK CON 12
DO CON 13
s1Reading var word
s2Reading var word
adcResolution CON 1023
'''''''''''''''''''''''''''''''''''''''''''''''''''
' ****** PROGRAM BODY ******
'''''''''''''''''''''''''''''''''''''''''''''''''''
debug cls
GOSUB MAIN
MAIN:
'debug cls
high 8 'setup pin1 on multiplex for sensor1
low 9
low 10
pause 10
GOSUB getCurrentVoltage
'GOSUB getCurrentVoltage
s1Reading = 2 * ((10 * ((10 *
adcBits)/2))/adcResolution)
debug home
debug CR, "BIN ADCBITS at sensor 1 :", bin10 adcbits
debug CR, "INT ADCBITS at sensor 1 :", dec4 adcbits
debug CR, "s1Per:", dec3 s1Reading
'pause 5000
low 8 'setup pin2 on multiplex
high 9
low 10
pause 10
GOSUB getCurrentVoltage
'GOSUB getCurrentVoltage
s2Reading = 2 * ((10 * ((10 *
adcBits)/2))/adcResolution)
debug CR, "BIN ADCBITS at sensor 2 :", bin10 adcbits
debug CR, "ADCBITS at sensor 2 :", dec4 adcbits
debug CR, "s1Per:", dec3 s2Reading
'pause 5000
goto MAIN
''''''''''''''''''''''''''''''''''''''''''''
' getcurrentVoltage takes in the current
' voltage reading via serial data, and inputs
' it into adcbits
''''''''''''''''''''''''''''''''''''''''''''
getCurrentVoltage:
high CS
low CS 'go low on the CS pin.. ADC now primed for
transmission
low CLK
pulsout CLK,210
shiftin DO,CLK,msbpost,[noparse][[/noparse]adcbits\10] 'current
binary reading is put into adcbits
RETURN
adc. I am now getting legit data, and the problem was simply that
there was overflow to my variables giving me wierd numbers.
New problem though. I have the adc hooked up to a multiplexing IC
that I switch with the stamp between different sensors. What is
happening though is that it seems the adc is caching the result from
the previous sample, and then sending it out on the next request.
In other words if I have: (this is just the theory not the real
code!)
Start loop:
switch to sensor 1
take reading
output sensor 1 reading
switch to sensor 2
take reading
output sensor 2 reading
goto loop
... then I see the sensor 1 reading on the sensor 2 output and the
sensor 2 reading on the sensor 1 output! Similarly, if I have 3
sensors in the loop, sensor1 reading has sensor3 value, sensor2
reading has sensor 1 value, and sensor 3 reading has sensor 2 value.
I am 1000% sure that my hookups are correct, and that the input
states for the demux are correct, and that the programming is cool.
There is something going on with the adc.
If I call the "getCurrentVoltage" 2 times in a row before putting
the value into a variable, it works. (You can see the commented out
calls in the code below.) I have tried cycling CS high and low
several times before retrieving data, but that doesn't seem to reset
the reading. I can't find anything in the Tech sheet about
buffering results, or whatever is going on. Any ideas? Help!
'{$STAMP BS2}
adcbits var word
CS CON 11
CLK CON 12
DO CON 13
s1Reading var word
s2Reading var word
adcResolution CON 1023
'''''''''''''''''''''''''''''''''''''''''''''''''''
' ****** PROGRAM BODY ******
'''''''''''''''''''''''''''''''''''''''''''''''''''
debug cls
GOSUB MAIN
MAIN:
'debug cls
high 8 'setup pin1 on multiplex for sensor1
low 9
low 10
pause 10
GOSUB getCurrentVoltage
'GOSUB getCurrentVoltage
s1Reading = 2 * ((10 * ((10 *
adcBits)/2))/adcResolution)
debug home
debug CR, "BIN ADCBITS at sensor 1 :", bin10 adcbits
debug CR, "INT ADCBITS at sensor 1 :", dec4 adcbits
debug CR, "s1Per:", dec3 s1Reading
'pause 5000
low 8 'setup pin2 on multiplex
high 9
low 10
pause 10
GOSUB getCurrentVoltage
'GOSUB getCurrentVoltage
s2Reading = 2 * ((10 * ((10 *
adcBits)/2))/adcResolution)
debug CR, "BIN ADCBITS at sensor 2 :", bin10 adcbits
debug CR, "ADCBITS at sensor 2 :", dec4 adcbits
debug CR, "s1Per:", dec3 s2Reading
'pause 5000
goto MAIN
''''''''''''''''''''''''''''''''''''''''''''
' getcurrentVoltage takes in the current
' voltage reading via serial data, and inputs
' it into adcbits
''''''''''''''''''''''''''''''''''''''''''''
getCurrentVoltage:
high CS
low CS 'go low on the CS pin.. ADC now primed for
transmission
low CLK
pulsout CLK,210
shiftin DO,CLK,msbpost,[noparse][[/noparse]adcbits\10] 'current
binary reading is put into adcbits
RETURN
Comments
One of the 'problems' with multiplexing an ADC is that the switching
may introduce a value different than previously read and the caps in
the ADC need time to charge or discharge to get the new reading.
In addition, just by connecting to the circuit in question, you may
introduce a change that takes a cycle or two for the circuit to
compensate for.
--- In basicstamps@y..., "sailing711" <nospam@e...> wrote:
> Thanks to those who helped with my problems with the tlc1549 10bit
> adc. I am now getting legit data, and the problem was simply that
> there was overflow to my variables giving me wierd numbers.
>
> New problem though. I have the adc hooked up to a multiplexing IC
> that I switch with the stamp between different sensors. What is
> happening though is that it seems the adc is caching the result
from
> the previous sample, and then sending it out on the next request.
> In other words if I have: (this is just the theory not the real
> code!)
>
> Start loop:
> switch to sensor 1
> take reading
> output sensor 1 reading
>
> switch to sensor 2
> take reading
> output sensor 2 reading
>
> goto loop
>
> ... then I see the sensor 1 reading on the sensor 2 output and the
> sensor 2 reading on the sensor 1 output! Similarly, if I have 3
> sensors in the loop, sensor1 reading has sensor3 value, sensor2
> reading has sensor 1 value, and sensor 3 reading has sensor 2 value.
>
> I am 1000% sure that my hookups are correct, and that the input
> states for the demux are correct, and that the programming is
cool.
> There is something going on with the adc.
>
> If I call the "getCurrentVoltage" 2 times in a row before putting
> the value into a variable, it works. (You can see the commented out
> calls in the code below.) I have tried cycling CS high and low
> several times before retrieving data, but that doesn't seem to
reset
> the reading. I can't find anything in the Tech sheet about
> buffering results, or whatever is going on. Any ideas? Help!
>
> '{$STAMP BS2}
>
> adcbits var word
> CS CON 11
> CLK CON 12
> DO CON 13
> s1Reading var word
> s2Reading var word
> adcResolution CON 1023
>
> '''''''''''''''''''''''''''''''''''''''''''''''''''
> ' ****** PROGRAM BODY ******
> '''''''''''''''''''''''''''''''''''''''''''''''''''
>
> debug cls
>
> GOSUB MAIN
>
> MAIN:
> 'debug cls
> high 8 'setup pin1 on multiplex for sensor1
> low 9
> low 10
> pause 10
> GOSUB getCurrentVoltage
> 'GOSUB getCurrentVoltage
> s1Reading = 2 * ((10 * ((10 *
> adcBits)/2))/adcResolution)
> debug home
> debug CR, "BIN ADCBITS at sensor 1 :", bin10 adcbits
> debug CR, "INT ADCBITS at sensor 1 :", dec4 adcbits
> debug CR, "s1Per:", dec3 s1Reading
> 'pause 5000
>
> low 8 'setup pin2 on multiplex
> high 9
> low 10
> pause 10
> GOSUB getCurrentVoltage
> 'GOSUB getCurrentVoltage
> s2Reading = 2 * ((10 * ((10 *
> adcBits)/2))/adcResolution)
> debug CR, "BIN ADCBITS at sensor 2 :", bin10 adcbits
> debug CR, "ADCBITS at sensor 2 :", dec4 adcbits
> debug CR, "s1Per:", dec3 s2Reading
> 'pause 5000
>
> goto MAIN
>
> ''''''''''''''''''''''''''''''''''''''''''''
> ' getcurrentVoltage takes in the current
> ' voltage reading via serial data, and inputs
> ' it into adcbits
> ''''''''''''''''''''''''''''''''''''''''''''
> getCurrentVoltage:
>
> high CS
> low CS 'go low on the CS pin.. ADC now primed for
> transmission
> low CLK
> pulsout CLK,210
> shiftin DO,CLK,msbpost,[noparse][[/noparse]adcbits\10] 'current
> binary reading is put into adcbits
>
>
> RETURN
impedance on ADC's is usually very high, as to not load down the
signal
that is being sampled. If all you need is 8 channels then get a MAX186
from
Maxim. It is a 8 channel, 12 bit, serial ADC. With this you can get
rid
of the multiplexer and sample faster with the MAX186. Go to
www.maximic.com and request free samples of the MAX186. They will
send
you 2 for free and you will get them snail mail in 2 weeks usually.
These cost around 35 bucks each in small quantities otherwise.
Jason
--- In basicstamps@y..., "dave_mucha" <davemucha@j...> wrote:
> How long are you letting the ADC stabilize on the signal ?
>
> One of the 'problems' with multiplexing an ADC is that the
switching
> may introduce a value different than previously read and the caps
in
> the ADC need time to charge or discharge to get the new reading.
>
> In addition, just by connecting to the circuit in question, you may
> introduce a change that takes a cycle or two for the circuit to
> compensate for.
>
>
>
>
>
>
> --- In basicstamps@y..., "sailing711" <nospam@e...> wrote:
> > Thanks to those who helped with my problems with the tlc1549
10bit
> > adc. I am now getting legit data, and the problem was simply
that
> > there was overflow to my variables giving me wierd numbers.
> >
> > New problem though. I have the adc hooked up to a multiplexing
IC
> > that I switch with the stamp between different sensors. What is
> > happening though is that it seems the adc is caching the result
> from
> > the previous sample, and then sending it out on the next request.
> > In other words if I have: (this is just the theory not the real
> > code!)
> >
> > Start loop:
> > switch to sensor 1
> > take reading
> > output sensor 1 reading
> >
> > switch to sensor 2
> > take reading
> > output sensor 2 reading
> >
> > goto loop
> >
> > ... then I see the sensor 1 reading on the sensor 2 output and
the
> > sensor 2 reading on the sensor 1 output! Similarly, if I have 3
> > sensors in the loop, sensor1 reading has sensor3 value, sensor2
> > reading has sensor 1 value, and sensor 3 reading has sensor 2
value.
> >
> > I am 1000% sure that my hookups are correct, and that the input
> > states for the demux are correct, and that the programming is
> cool.
> > There is something going on with the adc.
> >
> > If I call the "getCurrentVoltage" 2 times in a row before putting
> > the value into a variable, it works. (You can see the commented
out
> > calls in the code below.) I have tried cycling CS high and low
> > several times before retrieving data, but that doesn't seem to
> reset
> > the reading. I can't find anything in the Tech sheet about
> > buffering results, or whatever is going on. Any ideas? Help!
> >
> > '{$STAMP BS2}
> >
> > adcbits var word
> > CS CON 11
> > CLK CON 12
> > DO CON 13
> > s1Reading var word
> > s2Reading var word
> > adcResolution CON 1023
> >
> > '''''''''''''''''''''''''''''''''''''''''''''''''''
> > ' ****** PROGRAM BODY ******
> > '''''''''''''''''''''''''''''''''''''''''''''''''''
> >
> > debug cls
> >
> > GOSUB MAIN
> >
> > MAIN:
> > 'debug cls
> > high 8 'setup pin1 on multiplex for sensor1
> > low 9
> > low 10
> > pause 10
> > GOSUB getCurrentVoltage
> > 'GOSUB getCurrentVoltage
> > s1Reading = 2 * ((10 * ((10 *
> > adcBits)/2))/adcResolution)
> > debug home
> > debug CR, "BIN ADCBITS at sensor 1 :", bin10 adcbits
> > debug CR, "INT ADCBITS at sensor 1 :", dec4 adcbits
> > debug CR, "s1Per:", dec3 s1Reading
> > 'pause 5000
> >
> > low 8 'setup pin2 on multiplex
> > high 9
> > low 10
> > pause 10
> > GOSUB getCurrentVoltage
> > 'GOSUB getCurrentVoltage
> > s2Reading = 2 * ((10 * ((10 *
> > adcBits)/2))/adcResolution)
> > debug CR, "BIN ADCBITS at sensor 2 :", bin10 adcbits
> > debug CR, "ADCBITS at sensor 2 :", dec4 adcbits
> > debug CR, "s1Per:", dec3 s2Reading
> > 'pause 5000
> >
> > goto MAIN
> >
> > ''''''''''''''''''''''''''''''''''''''''''''
> > ' getcurrentVoltage takes in the current
> > ' voltage reading via serial data, and inputs
> > ' it into adcbits
> > ''''''''''''''''''''''''''''''''''''''''''''
> > getCurrentVoltage:
> >
> > high CS
> > low CS 'go low on the CS pin.. ADC now primed for
> > transmission
> > low CLK
> > pulsout CLK,210
> > shiftin DO,CLK,msbpost,[noparse][[/noparse]adcbits\10] 'current
> > binary reading is put into adcbits
> >
> >
> > RETURN
switches (around 5 seconds), and still had the exact same problem.
Any other ideas? I'll look into the MAX186 though.
--- In basicstamps@y..., "jbirnsch" <jbirnsch@v...> wrote:
> Dave is correct. Try adding some delay between samples. The input
> impedance on ADC's is usually very high, as to not load down the
> signal
> that is being sampled. If all you need is 8 channels then get a
MAX186
> from
> Maxim. It is a 8 channel, 12 bit, serial ADC. With this you can get
> rid
> of the multiplexer and sample faster with the MAX186. Go to
> www.maximic.com and request free samples of the MAX186. They will
> send
> you 2 for free and you will get them snail mail in 2 weeks
usually.
> These cost around 35 bucks each in small quantities otherwise.
>
> Jason
>
> --- In basicstamps@y..., "dave_mucha" <davemucha@j...> wrote:
> > How long are you letting the ADC stabilize on the signal ?
> >
> > One of the 'problems' with multiplexing an ADC is that the
> switching
> > may introduce a value different than previously read and the caps
> in
> > the ADC need time to charge or discharge to get the new reading.
> >
> > In addition, just by connecting to the circuit in question, you
may
> > introduce a change that takes a cycle or two for the circuit to
> > compensate for.
> >
> >
> >
> >
> >
> >
> > --- In basicstamps@y..., "sailing711" <nospam@e...> wrote:
> > > Thanks to those who helped with my problems with the tlc1549
> 10bit
> > > adc. I am now getting legit data, and the problem was simply
> that
> > > there was overflow to my variables giving me wierd numbers.
> > >
> > > New problem though. I have the adc hooked up to a multiplexing
> IC
> > > that I switch with the stamp between different sensors. What
is
> > > happening though is that it seems the adc is caching the
result
> > from
> > > the previous sample, and then sending it out on the next
request.
>
> > > In other words if I have: (this is just the theory not the
real
> > > code!)
> > >
> > > Start loop:
> > > switch to sensor 1
> > > take reading
> > > output sensor 1 reading
> > >
> > > switch to sensor 2
> > > take reading
> > > output sensor 2 reading
> > >
> > > goto loop
> > >
> > > ... then I see the sensor 1 reading on the sensor 2 output and
> the
> > > sensor 2 reading on the sensor 1 output! Similarly, if I have
3
> > > sensors in the loop, sensor1 reading has sensor3 value,
sensor2
> > > reading has sensor 1 value, and sensor 3 reading has sensor 2
> value.
> > >
> > > I am 1000% sure that my hookups are correct, and that the
input
> > > states for the demux are correct, and that the programming is
> > cool.
> > > There is something going on with the adc.
> > >
> > > If I call the "getCurrentVoltage" 2 times in a row before
putting
> > > the value into a variable, it works. (You can see the commented
> out
> > > calls in the code below.) I have tried cycling CS high and
low
> > > several times before retrieving data, but that doesn't seem to
> > reset
> > > the reading. I can't find anything in the Tech sheet about
> > > buffering results, or whatever is going on. Any ideas? Help!
> > >
> > > '{$STAMP BS2}
> > >
> > > adcbits var word
> > > CS CON 11
> > > CLK CON 12
> > > DO CON 13
> > > s1Reading var word
> > > s2Reading var word
> > > adcResolution CON 1023
> > >
> > > '''''''''''''''''''''''''''''''''''''''''''''''''''
> > > ' ****** PROGRAM BODY ******
> > > '''''''''''''''''''''''''''''''''''''''''''''''''''
> > >
> > > debug cls
> > >
> > > GOSUB MAIN
> > >
> > > MAIN:
> > > 'debug cls
> > > high 8 'setup pin1 on multiplex for sensor1
> > > low 9
> > > low 10
> > > pause 10
> > > GOSUB getCurrentVoltage
> > > 'GOSUB getCurrentVoltage
> > > s1Reading = 2 * ((10 * ((10 *
> > > adcBits)/2))/adcResolution)
> > > debug home
> > > debug CR, "BIN ADCBITS at sensor 1 :", bin10 adcbits
> > > debug CR, "INT ADCBITS at sensor 1 :", dec4 adcbits
> > > debug CR, "s1Per:", dec3 s1Reading
> > > 'pause 5000
> > >
> > > low 8 'setup pin2 on multiplex
> > > high 9
> > > low 10
> > > pause 10
> > > GOSUB getCurrentVoltage
> > > 'GOSUB getCurrentVoltage
> > > s2Reading = 2 * ((10 * ((10 *
> > > adcBits)/2))/adcResolution)
> > > debug CR, "BIN ADCBITS at sensor 2 :", bin10 adcbits
> > > debug CR, "ADCBITS at sensor 2 :", dec4 adcbits
> > > debug CR, "s1Per:", dec3 s2Reading
> > > 'pause 5000
> > >
> > > goto MAIN
> > >
> > > ''''''''''''''''''''''''''''''''''''''''''''
> > > ' getcurrentVoltage takes in the current
> > > ' voltage reading via serial data, and inputs
> > > ' it into adcbits
> > > ''''''''''''''''''''''''''''''''''''''''''''
> > > getCurrentVoltage:
> > >
> > > high CS
> > > low CS 'go low on the CS pin.. ADC now primed for
> > > transmission
> > > low CLK
> > > pulsout CLK,210
> > > shiftin DO,CLK,msbpost,[noparse][[/noparse]adcbits\10] 'current
> > > binary reading is put into adcbits
> > >
> > >
> > > RETURN