Help! - Very strange results with ShiftIn/ShiftOut


Results 1 to 4 of 4

Threaded View

  1. #3
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    Hi khufumen,

    I think the problem here is that the TLC2543 sends the previous result OUT at the same time the next address is clocked IN to start a conversion.

    The SHIFTIN and SHIFTOUT statements can't do both at the same time. Add in the Conversion Time that overlaps into the next SHIFTIN, and the 2 chips get out of Sync when the 12-bits don't match up.

    If you don't mind getting only every other sample, you can do it but there are a couple of timing issues.

    --------

    Do the SHIFTIN first, this will get the results of the last conversion. At the same time it will start a conversion of Channel 0.

    Wait at least 10us for the conversion to complete. (double that for safety)

    Now, do the SHIFTOUT to start the next Conversion with the desired channel, and exit the subroutine.

    Essentialy, you're starting a dummy conversion when Reading, and discarding the results when Writing to the device.

    Code:
    clear ' clear the variables
    High SensorPower
    
    ADch = TiltX  ' First AD reading will be garbage
    gosub ReadAD  '  but it also starts the next conversion
    
    
    MainLoop:
        ADch = TiltX
        gosub ReadAD
        serout2 TX, 6, [Dec result, 13, 10]
        goto MainLoop
    end
    
    '************************************************* *
    ' read the AD converter
    ReadAD:
        High SensorPower
        LOW ADcs                                ' select chip
        LOW sdo                                 ' send all 0's during read
        SHIFTIN sdi,sclk,MSBPRE,[result\12]     ' get result, 12 bits
        HIGH ADcs ' deselect chip
        PauseUS  20                             '  wait for conversion to finish
        LOW ADcs                                ' select chip
        SHIFTOUT sdo,sclk,MSBFIRST,[ADch<<8\12] ' Start next conversion
        HIGH ADcs ' deselect chip
        PauseUS 20                              '  wait for conversion to finish
    RETURN
    If you wanted to write you're own SHIFTIN/OUT routine, you could catch every sample by sending data in both directions at the same time. It would also be much faster. Since PBP's SHIFTOUT operates at somewhere around 50khz, it takes 240uS just to send the instruction to start a conversion, and another 240uS to read the result. If done manually, you should be able to get up to 400khz or more. That would SHIFTOUT 12 bits in 30uS.

    HTH,
    &nbsp;&nbsp;&nbsp;Darrel
    Last edited by Darrel Taylor; - 23rd February 2005 at 08:19.

Similar Threads

  1. RC - connection using RCTime produces strange results
    By selbstdual in forum mel PIC BASIC Pro
    Replies: 0
    Last Post: - 8th February 2007, 16:16
  2. Searches
    By bearpawz in forum Forum Requests
    Replies: 11
    Last Post: - 7th November 2005, 18:47
  3. Strange Results in Math
    By CocaColaKid in forum mel PIC BASIC Pro
    Replies: 6
    Last Post: - 31st August 2005, 07:09
  4. First test program, but strange results
    By bartman in forum General
    Replies: 12
    Last Post: - 19th November 2004, 03:14
  5. I'm getting strange Results using POT or RCTIME on PortB (or GPIO Port)
    By Melanie in forum FAQ - Frequently Asked Questions
    Replies: 0
    Last Post: - 15th July 2004, 20:01

Members who have read this thread : 0

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts