Shop OBEX P1 Docs P2 Docs Learn Events
A comand similar to lookup — Parallax Forums

A comand similar to lookup

marzec309marzec309 Posts: 146
edited 2006-03-10 21:43 in BASIC Stamp
I was woundering if there was a comand similar to LOOKUP. But instead of taking a value out of the list and storing it in a variable.
I would like to take a value and store it in a variable within the list.

Comments

  • Paul BakerPaul Baker Posts: 6,351
    edited 2006-03-10 18:14
    You mean like an array?

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    ·1+1=10
  • marzec309marzec309 Posts: 146
    edited 2006-03-10 18:27
    Paul,

    I mean. in this example

    for counter = 0 to 6
    lookup counter,[noparse][[/noparse]var0,var1,var2,var3,var4,var5,var6], var7
    next

    Instead of taking the value out of the list and storing it in var7. I would like to take the value of var7 and store it into one of the variables in the list. based on the variable counter.

    What this will be used for is. I'm tring to manualy do a SHIFTIN. because i need to shift in data on the rising edge a clock and shift out data on the falling edge of a clock. this has to happen at the same time. so i cannot just do a SHIFTOUT camand followed by a SHIFTIN camand.

    I hope this helps you under stand what im trying to do.

    mike
  • Paul BakerPaul Baker Posts: 6,351
    edited 2006-03-10 18:56
    Ok I can give you a way for it to work, but I need a little more information.
    1. Is the stamp generating the clock signal or is it recieving it?
    2. Is the communication lsbfirst or msbfirst?
    3. How many bits are there?
    4. What is the inactive level of the clock line?
    5. Does communication start on the first transition the clock or are there some transitions before data is shifted in/out?
    6. If the stamp is recieving the clock, what speed does the clock operate at?

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    ·1+1=10
  • marzec309marzec309 Posts: 146
    edited 2006-03-10 19:12
    Ok the stamp is generating the clock signal. Its communication is MSBFIRST. The output is 4 bits and the input is 8 bits The inactive level of clock would be low but it doesn't matter because there is a CS line(active low) also.
    there needs to be two clock pulses befor data is sent. For a total of 10 clock cycles.
  • marzec309marzec309 Posts: 146
    edited 2006-03-10 19:19
    here is the data sheet the operating sequence is on page 3.
    focus.ti.com/lit/ds/symlink/tlc541.pdf

    mike
  • Paul BakerPaul Baker Posts: 6,351
    edited 2006-03-10 21:43
    Ok something like this should work:

    CS  Pin  10
    Di  Pin  11
    Do  Pin  12
    Ck  Pin  13
     
    nbits Con 8
     
    Data    Var Byte                     'data 
    count   Var Nib                      'bit count
    Channel Var Nib                      'channel to be read next transmission
     
    INPUT Di                             'set pin directions
    OUTPUT Do
    OUTPUT CS
    OUTPUT Ck
     
    HIGH CS                              'set CS to inactive
    LOW  Ck                              'set clock to low
     
     
    'set channel to be read here
     
    Data = Channel << 4                  'put next channel to be read into upper nibble of data
     
    LOW CS                               'select chip for serial data
    FOR count = 1 TO nbits
      IF Data & $80 == $80 THEN          'if top bit is high
        HIGH Do                          'set output high
      ELSE 
        LOW Do                           'else set output low
      ENDIF
      HIGH Ck                            'set clock high
      Data = Data << 1                   'left shift data
      IF Di == 1 THEN Data = Data + 1    'shift in bit 
      LOW Ck                             'set clock low
    NEXT
    HIGH CS
     
    

    Set the Pin definitions to the pins you are actually using.

    This routine starts off with the channel to be read for next transmission in the upper 4 bits of the data, as this is shifted out of the top of the byte, the data for the previously selected channel is shifted in. This is the bit bang approach to doing simultaneous bidirectional communications. At the end you would have the data of the previously selected channel in data, and obviously you would run this once with the selected channel and ignore the data shifted in, the next time you run the loop you would aquire the data for the previously recorded channel. You will likely want to put·everything between LOW CS and HIGH CS·into a subroutine, setting Channel and Data = Channel << 4 before calling it. Upon return Data will contain the value.

    I don't ordinarily program Basic stamps so the code may contain some errors, though I did my best to prevent that from happening considering I don't have my stamp on hand to check it out, also some of the operations may have a faster method of doing the same thing (like Data = Data + 1 is the same as Data = Data | 1, and may or may not execute faster).

    <edit> Clarification: Data = Data + 1 is the same as Data = Data | 1 only when Data is an even number (bit 0 is low (0)) which is true for this case. </edit>

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    ·1+1=10

    Post Edited (Paul Baker) : 3/11/2006 5:55:40 AM GMT
Sign In or Register to comment.