Shop OBEX P1 Docs P2 Docs Learn Events
Twitchy ADC LTC1298 12-bit analog to digital converter — Parallax Forums

Twitchy ADC LTC1298 12-bit analog to digital converter

micamica Posts: 23
edited 2006-01-09 17:23 in BASIC Stamp
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[noparse]:)[/noparse]

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

Comments

  • NewzedNewzed Posts: 2,503
    edited 2006-01-07 13:05
    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

    ·
  • NewzedNewzed Posts: 2,503
    edited 2006-01-07 13:16
    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

    ·
  • JonathanJonathan Posts: 1,023
    edited 2006-01-07 15:39
    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 - Home of the Hydrogen Fuel Cell Robot
  • NewzedNewzed Posts: 2,503
    edited 2006-01-07 16:23
    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


  • PJAllenPJAllen Banned Posts: 5,065
    edited 2006-01-07 17:13
    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 --

    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
    634 x 145 - 22K
  • NewzedNewzed Posts: 2,503
    edited 2006-01-07 17:22
    So I was looking at the LTC1286smhair.gif

    Now quit pickin' on menono.gif

    Sid
  • JonathanJonathan Posts: 1,023
    edited 2006-01-07 17:24
    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 - Home of the Hydrogen Fuel Cell Robot
  • PJAllenPJAllen Banned Posts: 5,065
    edited 2006-01-07 17:34
    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 AllenTracy Allen Posts: 6,656
    edited 2006-01-07 18:34
    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
  • micamica Posts: 23
    edited 2006-01-07 20:15
    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 AllenTracy Allen Posts: 6,656
    edited 2006-01-08 05:12
    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
  • micamica Posts: 23
    edited 2006-01-08 08:20
    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 AllenTracy Allen Posts: 6,656
    edited 2006-01-08 18:27
    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
  • micamica Posts: 23
    edited 2006-01-08 20:13
    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&#8217[noparse];)[/noparse], 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[noparse]:)[/noparse]

    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,[noparse][[/noparse]config\4] ' Send config bits.
    SHIFTIN DIO_n,CLK,MSBPOST,[noparse][[/noparse]AD\12] ' Get data bits.
    HIGH CS ' Deactivate the ADC.
    RETURN ' Return to program.
  • NewzedNewzed Posts: 2,503
    edited 2006-01-08 21:20
    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

    ·
  • micamica Posts: 23
    edited 2006-01-09 00:52
    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
  • micamica Posts: 23
    edited 2006-01-09 02:04
    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 AllenTracy Allen Posts: 6,656
    edited 2006-01-09 17:23
    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
  • I’m trying to use a Basic Stamp 2 with the LTC1298 as a single input (for Now). Should I allow the other channel input to float, tie it directly to ground and/or thru a thru a 10K pull-down resistor ?
    I’m using the LTC1298 to take readings from a homemade light sensor using a phototransistor. The reading is displayed on a 4-digit LED display using a MAX7219 driver. Right now the circuit appears to be working ok but I occasionally see erratic readings.
  • kwinnkwinn Posts: 8,697
    Newzed wrote: »
    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



    That pinout is for the LTC1286. Take a look at page 2 of the Linear Technology data sheet. It is the single channel differential input version and should have a 1286 or 1286I marking on it.No marking is listed on the data sheet for the LTC1298. It is the dual channel version. Data sheet attached.
  • I confirmed I'm using the LTC1298 with 2 channels (0 and 1). The question I have is if I'm only using Ch0, then should I tie Ch1 to Ground or leave floating.
  • kwinnkwinn Posts: 8,697
    I confirmed I'm using the LTC1298 with 2 channels (0 and 1). The question I have is if I'm only using Ch0, then should I tie Ch1 to Ground or leave floating.

    Why not put the signal on both channels so you can compare the results? I don't like floating pins so I usually have a 10k resistor from the pin to gnd or Vcc, usually gnd for an ADC.

    Have a small (0.1 or 0.01uF) between Vcc and gnd as close to the ADC chip as possible to reduce supply noise.
    Verify that the ADC pins are connected to the right signals.
  • Thanks for the suggestion regarding measuring the signal in duplicate. I feel like an idiot for not thinking of that myself.
    I’ll add the 10K resistors to ground for each channel as a precaution.
    Already have the decoupling caps in place.
  • ADC's are sensitive when they don't have any input filtering or buffer amps. I use a MCP3204 with my BS2. But I put a INA111 amp on the front end. So the signal from my input first goes into a volt divider, then into the INA111 instr. amp. as a filter I'm using a 1uf ceramic cap. from ADC pin to ground with a 1 meg resitor ADC pin to ground.
    A good filter is a 10k resistor in series, with the output of the 10K into a 10uf tant. cap. lead the other lead to ground. Repeat this and go into another 10K resistor with the 10uf. cap. to ground.
    Finally I used some averageing in my programing. The readings are as steady as a fluke meter.
  • Thank you for the suggestion on the op amp. Any chance you could post the code for the MCP3204?
  • I sure will when I'm back on my desktop. I might have used a johnny Mac code I don't remember
  • This is the basic MCP3204 code, uncomment the pause 270 line to stabilze the bit count readout.
  • Thank you. One question on adding a resistor to ground and/or capacitor from an ADC input pin. I’m already using a resistor to form the voltage divider to read the output voltage from a phototransistor. Is another really needed?
    Appreciate the help...I’m on the higher side of 70 and self-teaching myself on microcontrollers.
  • I'm using a 1 meg resistor from ADC pin to ground. This is only to simulate the impedance load of my fluke meter when I calibrate the ADC. So I calibrate the ADC using the meter without the 1 meg resistor. Then after removing the test meter I install the 1 meg resistor. The resistor simulates the impedance load put on the ADC by the meter during calibration. I also have a 1uf capacitor installed from ADC pin to ground. That cap. is permanently installed. The cap. is a 1uf 100 volt ceramic Z5U. 20% digikey P/N 478-4868.
    Remember if you want accurate readings use precision resistors on your volt dividers. Like DALE RN60D series 1% or less.
  • I recently used the ADC128S in a project. This is a successive approximation converter, like the LTC1298. Here are my observations:

    For best performance, these converters need capacitors on their analog inputs. The sampling process disturbs the input a bit. The right capacitor will filter that disturbance out. The LTC1298 is specified to have an input capacitance of 20pF. You'll want a capacitor at least 100x that. So .002uF to .1uF would be reasonable. Larger is fine as well. It will also help with filtering noise from whatever you are measuring.

    The output from microcontroller to ADC should not change unnecessarily. The ADC128S has many input bits which are marked "don't care." This allows them to be set to whatever is convenient. The ADC is designed to sample after receiving the channel number. If a pin changes during the sampling process it can add noise to the result. Some pins like the clock pin must change, that is unavoidable. I don't know if SHIFTOUT leaves the pin in the last state, or zeros it. The PAUSE 275 might help with that.
Sign In or Register to comment.