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.
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.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
HTH,
Darrel




Bookmarks