Shop OBEX P1 Docs P2 Docs Learn Events
Using PBASIC "SHIFTIN" command with an ADC, and a BS2 ? — Parallax Forums

Using PBASIC "SHIFTIN" command with an ADC, and a BS2 ?

po2lepo2le Posts: 76
edited 2008-11-12 18:59 in BASIC Stamp
When using the SHIFTIN (SHIFTIN Dpin, Cpin, Mode),· does the BS2 deliver pre-set clock pulses to a connected ADC chip?· What I mean is, are the pulses automatically set within the BS2?· Or do we need to prescribe the timing of the pulses?

PO2L

Comments

  • sylvie369sylvie369 Posts: 1,622
    edited 2008-11-12 18:59
    From the manual:
    BSM, p 432 metaphorically said...
    The SHIFTIN instruction first causes the clock pin to output low and the
    data pin to switch to input mode. Then, SHIFTIN either reads the data pin
    and generates a clock pulse (PRE mode) or generates a clock pulse then
    reads the data pin (POST mode). SHIFTIN continues to generate clock
    pulses and read the data pin for as many data bits as are required.

    You do need to concern yourself with the "mode", but the SHIFTIN/SHIFTOUT commands do take control of the clock pin and deliver those pulses as needed. You do not need to separately mess with clock pulses.

    You can read about this in some detail beginning on page 65 of the "Understanding Signals" text, available for free download here:

    www.parallax.com/Store/Books/EducationalTexts/tabid/181/CategoryID/66/List/0/Level/a/ProductID/150/Default.aspx?SortField=ProductName,ProductName.

    Just for the fun of it, here (attached) is an image of the output from the Stamp Logic Analyzer when I run the code below on a BS2sx. Notice the clock pulses produced automatically and at the right timings on P1.


    Dpin            PIN     0                       ' data pin to 74HC595
    Clk             PIN     1                       ' shift clock to 74HC595
    Latch           PIN     2                       ' latch 74HC595 outputs
    
    counter         VAR     Byte
    
    
    Setup:
      LOW Latch                                     ' initialize latch output
    
    ' This loop moves the 8-bit value 'counter' onto the output lines of the
    ' '595, pauses, then increments counter and repeats.  The data is shifted
    ' msb first so that the msb appears on pin QH and the lsb on QA. Changing
    ' MSBFIRST to LSBFIRST causes the data to appear backwards on the outputs.
    
    Main:
      DO
        SHIFTOUT Dpin, Clk, MSBFIRST, [noparse][[/noparse]counter]     ' send the bits
        PULSOUT Latch, 1                            ' transfer to outputs
        PAUSE 100                                   ' Wait 0.1 seconds
        counter = counter + 1                       ' increment counter
      LOOP
      END
    

    Post Edited (sylvie369) : 11/12/2008 7:16:58 PM GMT
    917 x 575 - 134K
Sign In or Register to comment.