Shop OBEX P1 Docs P2 Docs Learn Events
2 * ADC0838 problems — Parallax Forums

2 * ADC0838 problems

verobelverobel Posts: 81
edited 2006-02-17 04:31 in BASIC Stamp
Hi fellow stampers..

I hooked up one ADC0838 on my PDB with BS2pe and finally got it to work using code I found on the forum and pin/chip connectivity from a related website link. I thought it would be nice to be able to cascade these chips incase you needed more than 8 analog inputs so I added a second chip. When using the same data and clk lines and a new CS line, the first chip continued to work ok but the second faults. The problem seems to be that the high bit in the result is set to 1 improperly. There are other weird things as well. If you have 2 ADC0838 chips you can easily wire this up and check it out. Comments in my attached code give all pin assignments for stamp and chip.

When the first attempt failed, I tried a 2nd, using separate data, clk, and CS lines ( this is what shows in the attached code). This produces the same sort or error..the high bit in the result is forced to 1 improperly.

Can anyone fault the code or shed some light on this problem? It would be nice to cascade these chips using a common data/clk line.. kind of like the expansion of input and output ports using 74HC595(out) and 74HC165(in).

thanks, John

ps. swapping the code blocks.. swaps the problem..so the error would appear to be in the code

Comments

  • Jon WilliamsJon Williams Posts: 6,491
    edited 2006-02-16 18:03
    Since you're using one pin for data in and out to the chip you need to put a resistor in the Do line:

    · data buss
    *---/\/\/---·Do
    ···················|
    ·················· +
    Di

    Doing this prevents the output state of the Do pin from affecting data going to the Di pin.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax
  • verobelverobel Posts: 81
    edited 2006-02-17 00:33
    Thanks for the reply Jon

    How did you figure that out? Is it on the data sheet somewhere?

    What size of resistor do you recommend?

    I also tried seprate CS,CLK,DATA lines but that seemed to give the same error. How would you explain that?
  • verobelverobel Posts: 81
    edited 2006-02-17 00:54
    ·.. in the mean time I tried separate lines for CS,CLK,DataIn,DataOut on both chips but continue to have the same problem.. junk bit on topconfused.gif
  • PJAllenPJAllen Banned Posts: 5,065
    edited 2006-02-17 01:17
    ·· OK, well, it looks like you are taking ChipSelect (/CS -- IC pin18) LO in the first subroutine, that's OK.· BUT, you need to put it back HI once you're finished with it.· In the second subroutine, where you're accessing the 2nd IC, you're taking its /CS LO with the 1st IC's LO, too.· So, they both figure to be the object of attention.
    · They're not edge-triggered,·they're logic·level (on or off.)


    Post EDIT:· I've attached this program having added HIGH CS and HIGH CS2 after the ends of the FOR...NEXTs
    [noparse][[/noparse] Only the Conversion is initiated by the HI-to-LO transition of CS, but the Chip is STILL selected if it remains LO. ]

      FOR Channel = 0 TO 2  ' Go through all the channels
        [color=red]HIGH CS[/color]            ' from other working prog    .. triggers on high to low
        [color=red]LOW CS[/color]             ' ""
        MUXBYTE = %11000 | ((Channel & %001) << 2) | ((Channel & %110) >> 1)
        SHIFTOUT ADC,CLK,MSBFIRST,[noparse][[/noparse]MUXBYTE\5]
        SHIFTIN ADC,CLK,MSBPOST,[noparse][[/noparse]ADCRes]
        ADCVol = (ADCRes*100)*/5
        DEBUG DEC CHANNEL," (%",BIN3 Channel,") ;  ",DEC MUXBYTE, " (%",BIN MUXBYTE,") ;  "
        DEBUG DEC3 ADCRes," (%",BIN8 ADCRes,") ;  ",DEC3 ADCVol," (%",BIN8 ADCVol,") " , CR
      NEXT      ' Go to next channel
    DEBUG "--------------------------------------------------------------",CR
    ' 2nd unit on CS2 pin 11
    DEBUG "--------------------------------------------------------------",CR
    DEBUG " Channel ;    MUXBYTE   ;     ADCResult    ;    Voltage*100"  ,CR
    DEBUG "--------------------------------------------------------------",CR
      FOR Channel = 0 TO 2  ' Go through all the channels
        [color=red]HIGH CS2[/color]            ' from other working prog   .. triggers on high to low
        [color=red]LOW CS2[/color]             ' ""
        MUXBYTE = %11000 | ((Channel & %001) << 2) | ((Channel & %110) >> 1)
        SHIFTOUT ADC2,CLK2,MSBFIRST,[noparse][[/noparse]MUXBYTE\5]
        SHIFTIN ADC2,CLK2,MSBPOST,[noparse][[/noparse]ADCRes]
        ADCVol = (ADCRes*100)*/5
        DEBUG DEC CHANNEL," (%",BIN3 Channel,") ;  ",DEC MUXBYTE, " (%",BIN MUXBYTE,") ;  "
        DEBUG DEC3 ADCRes," (%",BIN8 ADCRes,") ;  ",DEC3 ADCVol," (%",BIN8 ADCVol,") " , CR
      NEXT      ' Go to next channel
    DEBUG "--------------------------------------------------------------",CR
    END
    

    Post Edited (PJ Allen) : 2/17/2006 1:51:13 AM GMT
  • Chris SavageChris Savage Parallax Engineering Posts: 14,406
    edited 2006-02-17 01:29
    PJ, nice catch.· That could definately be a problem.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Chris Savage
    Parallax Tech Support
    csavage@parallax.com
  • verobelverobel Posts: 81
    edited 2006-02-17 02:24
    thanks to all for input

    I was continuing to experiment and had actually tried what you suggested which I continue to do. I still had some problems with the result/output. Jon's original idea of resistor across DO (chip data out pin 14)·DI (chip data in pin 17) led me to try separate lines. Of course after so many changes I finely messed up some of the wires.. recommented stuff to avoid this.. then got some stuff working and fine tuned it. (see attachment)

    The end result appears to be: (w.r.t. multichip ADC0838 projects)
    1) you can use common CLK line across chips
    2) you can connect DI to DO on each chip
    · .. connect this to the 'DATA' line shift I/O
    3) you must use separate 'DATA' lines for each chip..else get bad results

    I added an outside DO LOOP to continously scan. How could you calculte the time it takes to scan the 2 chips?

    thanks, John

    ps. only tested 2 chips both with 8 single inputs voltages with common grnd.
  • Jon WilliamsJon Williams Posts: 6,491
    edited 2006-02-17 04:31
    Use a 1K resistor between Do and Di -- sorry I left that out of my original post.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Jon Williams
    Applications Engineer, Parallax
Sign In or Register to comment.