Thanks for all your help and input. What was causing the problem was that there was no delay between when I powered up the AD converter and when I started reading from the AD converter. The AD converter when powered up needs about 4 ms to stabilize before it can be read from. Once it stabilizes, it has no problem reading the the data.
The fixed code reads:
clear ' clear the variables
High SensorPower ' power up the sensors and the AD converter
Pause 4 ' wait for power to stabilize
MainLoop: ' enter main loop
ADch = TiltX
gosub ReadAD
serout2 TX, 6, [Dec result, 13, 10]
goto MainLoop
end
'************************************************* *
' read the AD converter
ReadAD:
LOW ADcs ' select chip
SHIFTOUT sdo,sclk,MSBFIRST,[ADch<<8\12] ' mode, left justify ADch
SHIFTIN sdi,sclk,MSBPRE,[result\12] ' get result, 12 bits
HIGH ADcs ' deselect chip
RETURN




Bookmarks