PDA

View Full Version : Twitchy ADC LTC1298 12-bit analog to digital converter



mica
01-07-2006, 01:38 PM
Howdy,

Just getting into the microcontroler stuff. Really cool. I have a project that involves a BS2 and a LTC1298 Analog to digital converter. I got it working but the values coming out are almost unusable. The ADC has 2 channels. They should range from 0 to 4095. When I give an input voltage between 0 and 5 volts I get something like 1740 but the number will jump +/- 20 to 30. Is this normal?

And I'm using it in two-channel mode and not as a differential. Differential is a real mess:)

As I do not have an oscilliscope I thought it was my sensor. But then I used a battery and resisters to cut down the voltage to something like 4.7v and it was still all over the place.

Also, channel 0 will not zero out. when connected to ground it should read 1 or 0. Currently it will vary depending on reset from 200 to 800 when grounded. Channel 1 will go to 0 or 1 when connected to ground and 4095 when 5 V. But yes channel 1 is just a jumpy.

Do you think it is a bad ADC or maybe the type in general is twitchy? Should I try the 8-bit? Or can someone recommend a better one.

Also, for my project all I really need is one channel

Thanks,

Mica

Newzed
01-07-2006, 08:05 PM
Try putting a .1uf cap as close to the ADC pin as you can get.ˇ Also put a 1.2K resistor in series with the analog input to the ADC.

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Sid Weaver
Do you have a Stamp Tester yet?
http://hometown.aol.com/newzed/index.html

ˇ

Newzed
01-07-2006, 08:16 PM
Also, pins 1 and 8 of the ADC should be tied together, as well as pins 3 and 4.

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Sid Weaver
Do you have a Stamp Tester yet?
http://hometown.aol.com/newzed/index.html

ˇ

Jonathan
01-07-2006, 10:39 PM
Sid,

Are you sure you mean the LTC1298? I'm using one as we speak, and pins 1-8 are chip select and Vdd, and 3-4 are gnd and DIN.

Mica, as Sid says, try a cap and resistor to buffer. For more slowly changing signals you can use a larger cap. For example on my hot tub, which has a *very* slow change in temp but a very long run of wire from sensor to ADC, I use a 1uF cap. Smooths it right out.

Also, it depends on what you are reading. If it is changing a lot, so is your number going to change a lot. In this case, you can do a software fix, collecting say 10 samples and averaging them. Also, being mounted on a breadboard, or being mounted next to something noisy (xfrmr, PWM, etc) can also introduce 'bounce" to the readings. Also put a decoupling cap across the power pins of the ADC.

What are you trying to read?

Jonathan

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
www.madlabs.info (http://www.madlabs.info) - Home of the Hydrogen Fuel Cell Robot

Newzed
01-07-2006, 11:23 PM
Jonathan, I just looked at the data sheet for the LTC1298 8-pin DIP.ˇ Here are the pinouts:
TOP VIEW
VREF - 1
+IN - 2
–IN - 3
GND - 4
CS/SHDN - 5
DOUT - 6
CLK - 7
VCC - 8

Sid

PJ Allen
01-08-2006, 12:13 AM
Let's have a look at the old datasheet (When in doubt, I whip it out, I happilyˇdo declare, It's a Free-for-All), to wit --

http://forums.parallax.com/attachment.php?attachmentid=40041

(Somebody else is looking at the pin-out for the LTC1286. )

Post Edited (PJ Allen) : 1/7/2006 5:34:59 PM GMT

Newzed
01-08-2006, 12:22 AM
So I was looking at the LTC1286http://forums.parallax.com/images/smilies/smhair.gif

Now quit pickin' on mehttp://forums.parallax.com/images/smilies/nono.gif

Sid

Jonathan
01-08-2006, 12:24 AM
Pj, Sid,

My data sheet is the same as PJ's. My bad on the pinout, meant to type that pins 3-4 are CH1 and GND. Sid, I think you are looking at the LTC1286, which has the pinout as you describe.

Jonathan

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
www.madlabs.info (http://www.madlabs.info) - Home of the Hydrogen Fuel Cell Robot

PJ Allen
01-08-2006, 12:34 AM
So, anyways...


Jonathan said...
When I give an input voltage between 0 and 5 volts I get something like 1740 but the number will jump +/- 20 to 30. Is this normal?

Aˇvariation/deviation of 20-30 parts in 4,096 is less than 1%.ˇ How stable is the voltage that you're measuring?ˇ I wouldn't expect to have repeatability to 1 digit or anything.

Tracy Allen
01-08-2006, 01:34 AM
That kind of bad fluctuation can be due to poor wiring. It is very important to avoid ground loops. That will happen if you have the "ground" for your sensor at a different point in your circuit from the "ground" for the LTC1298. Especially if the two ground points are separated by big loops of wire or circuit traces that have currents for digital circuitry (the Stamp, or power transistors, motors etc) flowing in them. The ground for your sensor should attach close to GND pin 4 on the LTC1298. Be sure you have a good bypass capacitor, 0.1uf + 3.3uf directly across the power for the LTC1298, pin 4 to pin 8. That will assure that the reference voltage is stable. You should be able to get this down to bobble only in the least significant bit!

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Tracy Allen
www.emesystems.com (http://www.emesystems.com)

mica
01-08-2006, 03:15 AM
First, thanks you all for quick reply. Much apricated.

Give you a little more idea on my setup, this is all being done on the Rev C board I recieved in the Basic STAMP discovery kit. For power I'm using a new 9V battery. My sensor is a hall-effect sensor pivoting over 2 mangnets. I'm making an AOA (Angle of Attack) sensor or my R/C airplanes. The data will be fed into an Eagle Tree Systems Telemetry recorder. Once I get a stable read from the AD I can feed that into a digipot and send out a variable resistance to the temperature sensor (not that important). Measuring the hall effect sensor with my voltmeter it will read between 2.10 volts and 3.78 volts for a 40 degree sweep. If I just leave the sensor alone, so not moving, the meter will read a very stable reading of something like 3.10v. So I can't see the thousandths place or 0.001 but I would expect the AD to fluctuate no more then half of 8.333 or say +/- 5 on the safe side (given AD's 0.00122 resolution). Given other unknows even +/- 10 would work. I have a 6 page report with pictures I sent to parallax support if you want it.

Based on your suggestons above and some experiments I thought of I'm still stuck, but did learn some things. For the cap between 4 and 8 I originally had a 10uf tantalum. I tried backing this down to 1.0 and even tried two 10uf or 20uf. No help. But then using my volt meter I measured across pin 4 and 8. I'm seeing it jump quickly between 4.96 and 4.97v. Could this be it? Keep in mind this is on the board so it is a regulated voltage coming from a battery. I would not expect this kind of noise.

Do you think it would be worth wiring 3 AA batteries to get the power supply under the 5v regulator? Or maybe a 4.2 volt LiPo

Also, I know there could be some instability from my sensor, so I went to a pot to cut down the voltage. Still saw the high variation. So I still think it is something to do with the AD.

Thanks guys,

Mica

Tracy Allen
01-08-2006, 12:12 PM
The fluctuation from 4.96 to 4.97 volts in the power supply could be a problem, but that is only one digit on your meter, so it might just be bit bobble. Most multimeters do a lot of averaging, so there can be quite a lot of noise that does not show up on the meter. Try the meter on a sensitive AC range, if it has one, and see what it says about the AC component on your power supply. What else is the power supply doing, for example, any servos?

You didn't say anything about testing for ground loops. If you have a 10 kohm potentiometer, hook the outside legs directly from pin 4 to pin 8, and hook the center leg to both input channels 0 and 1, and connect a 0.1 uf capacitor from the center leg to pin 4. Okay, short direct connections. Set the output of the potentiometer to 2.5 volts using your multimeter. Run a short program on the Stamp that simply reads the two ADC channels and displays the result. What does the ADC say then?

I was trying to make sense of your observation:


>>Also, channel 0 will not zero out. when connected to ground it should read 1 or 0.
>>Currently it will vary depending on reset from 200 to 800 when grounded.
>>Channel 1 will go to 0 or 1 when connected to ground and 4095 when 5 V.
>>But yes channel 1 is just a jumpy.



That sounds like a programming issue, or maybe inconsistent wiring to the inputs.

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Tracy Allen
www.emesystems.com (http://www.emesystems.com)

mica
01-08-2006, 03:20 PM
Thanks for reply Tracy. I did have some success with your suggestion… but it is leading to more questions.

With the 10kpot, 0.1uf cap & setup how you described channel 0 and 1 at 2.5v gave between 2028 to 2029. Very good! Now if I turn the pot to 0 ohm so ch 0 & 1 are at the input V I get 4095. Good! Now if I slowly increase the resistance and so the difference in V, just below 3.72 or 1.25 from ground to channel the reading jumps to 9999. If I keep on bringing the V relative to ground down, ch 0 & 1 will jump between 0262 or 1262. Nothing in-between, both channels just flash back and forth on those numbers, 0262 or 1262.

So is my AD working correctly (i.e. I’m doing something wrong)? Isn’t the 1.25V some magical number? This sounds like a program problem with the 0262 or 1262 but maybe the way the pot is working, this is causing it. Any light on this would be great.

Regarding ‘ground loops’, my mechanical engineering definition of this is having different power supplies and not having a common ground. I have only one power source and that is from the board that came with the kit. You also hinted at an example of long wire. My wire coming from the hall-effect sensor is kind of long, say 12 inches. I can cut that down to about 2 in if you say so.

Also, the hall-effect, Honeywell SS-19T sensor has it’s own resistance, about 2k. Would this resistance cause a ‘ground loop’? Is there any way around it?

Is it time to get an oscilloscope or is there some way around all of this?

Mica

Tracy Allen
01-09-2006, 01:27 AM
A ground loop is a situation where currents flowing in one path affects a signal in another path.




v
Vdd o---------o----------oo----------;
| | | |
X Y S Z
X Y S Z
| | | |
Vss o---------o----------oo----------'
a b c




Suppose XX is your BASIC Stamp, which is driving loads such as a couple of LEDs and whatever else.
Suppose YY is your LTC1298 converter.
Suppose SS is your sensor.
Suppose ZZ is a servo motor.

The ground loop is the bottom line in the diagram that connects together the Vss supply and the grounds for all the devices. Due to those currents, the voltages you measure at different points along the "ground" can be different and also have different amounts of noise, depending on ohms law and the magnitude of the currents and the size of the wire or pcb traces and the contact resistance of connections (such as wires stuck in a white prototyping block). If you move the bottom connection of the sensor along the line (loop) from a to c the reading on the ADC will change. The specifics depend on exactly what is there. When the bottom reference point of the sensor is connected right next to the reference point of the ADC at "b", as it is with the potentiometer example, that should minimize both the DC errror and the noise. It is possible to wire systems in a "star" that radiates from "v" and "a", so that the digital and analog parts of the circuit are separated from one another. You always have to be thinking about potential ground loops when you include an ADC in a digital system. It all has to do with those hidden currents and how you route the wiring.

Noise pickup from external sources is another issue. That can be addressed by shorter leads, twisted pairs, shielding, and filtering (capacitor or software.).

Now, the business with the readings at less than 1.25 volts is a mystery, not due to ground loops. If the voltages as shown on your multimeter are okay, could you post your test code? It sounds like some kind of math or underflow error. hmmm.

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Tracy Allen
www.emesystems.com (http://www.emesystems.com)

mica
01-09-2006, 03:13 AM
Tracy and all, thank you so much. You should all be worshiped as Gods or at least small deities. I cut down the connection to my sensor and now I’m getting reads like 2497 +/-1 for 2.93 volts. Don’t know if it is the reduction of wire or that now the entire circuit is bathed in the same magnetic field. But it works.

For others that stumble into this same problem, with this working circuit if I leave the voltmeter on (even off but still ‘wired’), the readings go wild again. So take your voltage read for the position, then disconnect and let it settle and look at the debug. Settle time even for an entire sweep is one read with the half-second delay in the program below.

Also, at least for my voltage range of 2.10 to 3.78 from the hall sensor, I don’t get the wild number jumps. This goes for the simple subtraction and division to get the number into the 0 to 127 range of my digipot. So I think I’m good to go.

Thanks again. I think I’m going to go outside now:)

Mica

' {$STAMP BS2}
' {$PBASIC 2.5}

'-- A/D converter variables --
CS CON 0 ' Chip select; 0 = active
CLK CON 1 ' Clock to ADC; out on rising, in on falling edge.
DIO_n CON 2 ' Data I/O pin _number_.
config VAR Nib ' Configuration bits for ADC.
AD VAR Word ' Variable to hold 12-bit AD result.

startB VAR config.BIT0 ' Start bit for comm with ADC.
sglDif VAR config.BIT1 ' Single-ended or differential mode.
oddSign VAR config.BIT2 ' Channel selection.
msbf VAR config.BIT3 ' Output 0s after data xfer complete.


HIGH CS ' Deactivate ADC to begin.
HIGH DIO_n ' Set data pin for first start bit.
again: ' Main loop.
FOR oddSign = 0 TO 1 ' Toggle between input channels.
GOSUB convert ' Get data from ADC.
DEBUG "channel ",DEC oddSign, ": ",DEC AD,CR ' Display data.
PAUSE 500 ' Wait a half second.
NEXT ' Change channels.
GOTO again ' Endless loop.

convert:
config = config | %1011 ' Set all bits except oddSign.
LOW CS ' Activate the ADC.
SHIFTOUT DIO_n,CLK,LSBFIRST,[config\4] ' Send config bits.
SHIFTIN DIO_n,CLK,MSBPOST,[AD\12] ' Get data bits.
HIGH CS ' Deactivate the ADC.
RETURN ' Return to program.

Newzed
01-09-2006, 04:20 AM
Mica, let's put the finishing touches on it.ˇ Right after you read the ADC -

debug dec AD, cr

it will say 2497

Right after the debug ADC add:

AD = AD*/$012C

then debug it again.ˇ It should display very close to 2.930.ˇ You might have to change the C to B or D to get closer.

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Sid Weaver
Do you have a Stamp Tester yet?
http://hometown.aol.com/newzed/index.html

ˇ

mica
01-09-2006, 07:52 AM
Newzed,

Sorry but I'm missing something. Keep in mind I've only been dealing with microcontrollers for 9 days now. If I put in the equation you specified, AD=AD*/$012C and run the debug again, exact same debug, I see the following:

channel 0: 2386 <-- This is from the AOA sensor
channel 0: 2796 <-- post AD=AD*/$012C

This is at 2.78 volts form the sensor... of couse the readings are after I remove the voltmeter from the circuit.

Can you give me a little more info?

Mica

mica
01-09-2006, 09:04 AM
All,

Implementation advice. The AOA sensor and ADC based on my past ‘user errors’ you helped me get past will obviously need to be kept close together. But I would like to keep the BS2 up inside the wing. This distance will be about 9 to 12 inches. Considering the wires from the BS2 pins are digital, do you think this will be a problem?

Mica

Tracy Allen
01-10-2006, 12:23 AM
Get ahold of a shielded twisted pair wire. (tiny microphone or phono pickup wire). Of the two wires that are twisted, connect one to pin 4 of the ADC and the other to the ADC channel 0 input, and at the other end to sensor ground and signal respectively. Connect the shield to pin 4 of the ADC but at the sensor end don't connect it to anything at all. If the sensor needs power, run that through an extra wire. There may be an extra wire inside the shield, or, no problem, you can use a wire outside the shield, and run it from pin 8 on the ADC. Do _not_ use the shield for power. Be sure the wires connect to the ADC as close as possible to the pins.

▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Tracy Allen
www.emesystems.com (http://www.emesystems.com)