Shop OBEX P1 Docs P2 Docs Learn Events
I would like to connect two LTC1298's to a STAMP 2 — Parallax Forums

I would like to connect two LTC1298's to a STAMP 2

Tom PTom P Posts: 97
edited 2007-05-21 21:38 in BASIC Stamp
I need some help!
I would like to connect two LTC1298's to a STAMP 2.
How can I use the code below in such a way as to sequentially monitor two ADCs in order to watch four voltages??

****************************************************************************************

"LTC1298 & BS2
CS con 0
CLK con 1
DIO_n con 2
config var nib
AD var word
startB var config.bit0
sglDif var config.bit1
oddSign var config.bit2
msbf var config.bit3

high CS
high DIO_n
again:
for oddSign = 0 to 1
gosub convert
debug "channel ",DEC oddSign, ": ",DEC AD,cr
pause 500
next
goto again
'
convert:
config = config | %1011
low CS
shiftout DIO_n,CLK,lsbfirst,[noparse][[/noparse]config\4]
shiftin DIO_n,CLK,msbpost,[noparse][[/noparse]AD\12]
high CS
return

Post Edited By Moderator (Chris Savage (Parallax)) : 5/20/2007 5:15:17 PM GMT

Comments

  • FranklinFranklin Posts: 4,747
    edited 2007-05-20 15:13
    You need to use seperate pins for the data and possibly CS (I didn't look at the spec sheet) then do your shift outs for each in sequence. I think you can use the same CLK pin as the one you are not reading won't be sending data you care about if at all.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    - Stephen
  • Tracy AllenTracy Allen Posts: 6,664
    edited 2007-05-20 15:37
    Actually it only requires a separate CS for each chip. Keep them high except for for one chip at a time to select it.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Tracy Allen
    www.emesystems.com
  • Tom PTom P Posts: 97
    edited 2007-05-20 16:23
    Tracy:

    Ok, so then I would have to add three more lines to the BS2, for the extra LTC1298
    Is the assumption below correct to add second CS2,CL2,DIO_n2 ?????

    CS1 con 0
    CL1 con 1
    DIO_n1 con 2 '1st LTC 1298

    CS2 con 3 '2nd LTC1298
    CLK2 con 4
    DIO_n2 con 5


    Ok, so then do I have to duplicate a section of the code to read the additional LTC1298???
    How is this best done?
  • FranklinFranklin Posts: 4,747
    edited 2007-05-20 17:25
    According to Tracy you would have these assignments:
    CS1 con 0
    CS2 con 1
    CLK con 2
    DIO con 3

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    - Stephen
  • Tracy AllenTracy Allen Posts: 6,664
    edited 2007-05-20 23:57
    Tom, you only need one extra CS line, and the data and clock lines are shared between the two. Suppose it is hooked up conveniently like Franklin listed, with p0 to p1 as the two chip selects . Here is one possible program. Notice that there is now a one bit variable, cs, that will have the value 0 to activate the first LTC1298 and value 1 to activate the second one. This program is recast into PBASIC 2.5 syntax, using a DO:LOOP. Inside the DO:LOOP there are two FOR:NEXT loops instead of just one. The outside one is for the two LTC1298s and inside one is for the channel 0 or 1 on each, and the DEBUG is modified to show Channel 0.0, 0.1, 1.0 and 1.1 for the four readings. The convert subroutine remains the same, except that the cs is now a variable instead of a constant.

    ' {$STAMP BS2}
    ' {$PBASIC 2.5}
    ' LTC1298 & BS2
    cs0 CON 0
    cs1 CON 1  '<-- two chip selects
    clk CON 2
    dio CON 3
    ad VAR Word
    cs VAR bit   <-- cs is a variable
    config VAR Nib
     startB VAR config.Bit0
     sglDif VAR config.Bit1
     oddSign VAR config.Bit2  '<-- ad channel 0 or 1
     msbf VAR config.Bit3
    
    HIGH cs0
    HIGH cs1
    HIGH dio
    DO
      FOR cs=0 to 1   <-- outside selects which LTC1298
        FOR oddSign = 0 TO 1   <-- inside selects channel
          GOSUB convert
          DEBUG "channel ",BIN1 cs, ".", BIN1 oddSign, ": ",DEC ad,cr
          PAUSE 500
        NEXT
      NEXT
    LOOP
    '
    convert:
      config = config | %1011
      LOW cs
        SHIFTOUT dio, clk, LSBFIRST, [noparse][[/noparse]config\4]
        SHIFTIN dio, clk, MSBPOST, [noparse][[/noparse]AD\12]
      HIGH cs 
      RETURN
    

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Tracy Allen
    www.emesystems.com
  • Tom PTom P Posts: 97
    edited 2007-05-21 12:45
    Tracy:
    Thanks for the code on selecting two LTC1298's.
    It appears to work, I was a bit consfused as to how the channels were displayed at first!
    A few questions

    in the original debug line:
    debug "channel ", DEC, oddsign,":",DEC AD,cr
    new debug line:
    debug "channel ",BIN1 cs, ".", BIN1 oddsign, ": ",DEC ad,cr

    Why are these two lines so different?
    Help me understand why the difference.

    I would like to add a conversion to millivolts such as :
    AC Var word

    AC = (AD*10)**14464+(AD*10) + 5/10
    would I add this after the Gosub convert?
    Would this work.
    Thanks
    Tom
  • Tracy AllenTracy Allen Posts: 6,664
    edited 2007-05-21 16:54
    Both cs and oddsign are bit variables and are the same value whether you display them as DECimal or BINary. I'm just in the habit of matching the display modifier to the type of variable. I used BIN1 because it is always going to be one binary digit, 0 or 1, and BIN1 is faster to execute and takes less code space than BIN or DEC. But bottom line, you could use either DEC or BIN there and the result would be exactly the same.

    There are now two variables, cs and oddsign, that need to be displayed to indicate the origin of the signal. Maybe you would rather display 0, 1, 2, 3 for the channel, instead of 0.0, 0.1, 1.0 and 1.1? Then you would use,
    DEBUG "channel ",DEC1 cs<<1+oddsign, ": ",DEC ad,cr
    That combines the two bits into one single channel number.

    You could insert the conversion formula either as you say, right after the gosub convert, or put in inside the convert routine, just before the RETURN.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Tracy Allen
    www.emesystems.com
  • Tom PTom P Posts: 97
    edited 2007-05-21 21:38
    Tracy:
    Thanks for all your help with the LTC1298 info and code
    A great help in understanding how things work
    tom
Sign In or Register to comment.