I've got the following code shown below. In order for it to work I need to put a pause in of 8 ms or greater or else the serout2 command outputs 0s. In other words, if the pause is set to 10 ms I get good data but if the pause is set to 5 seconds or there is no pause at all, I get 0s. Does this occur because my control pins for the AD converter are accessing different ports? This issue has been baffling me for some time.

The 16F876 I am using is a surface mount SOIC chip or else I would check it by moving my control lines to different I/O pins.

I hope somebody can give me some insight.

Kind Regards,
Eric

DEFINE OSC 20 ' define oscillator to be 20Mhz
ADCON1 = 7
include "MODEDEFS.bas"

' Power connections

MainPower VAR PORTC.3

' Communication connections
TX VAR PORTA.0

' AD converter connections
sclk VAR PORTC.1 ' SPI clock out from BS2 to AD2543
sdo VAR PORTC.0 ' SPI data out from BS2 to AD2543 sdi
sdi VAR PORTA.5 ' SPI data in from AD2543 sdo to BS2
ADcs VAR PORTA.3 ' AD2543 chip select, active low

' *********************** [ CONSTANTS ] ************************
' Sensor Constants
TiltX Con 2

' [ VARIABLES ]
Result VAR WORD
ADch var Byte

high MainPower
Adch = TiltX

'[ MAIN PROGRAM ]
Main:
pause 8
gosub ReadAD
serout2 TX, 16468, [dec result, 13]
goto Main


' read the AD converter
ReadAD: ' entry point to give result as millivolts
LOW ADcs ' select chip
SHIFTOUT sdo,sclk,MSBFIRST,[ADch<<8\12]
SHIFTIN sdi,sclk,MSBPRE,[result\12] ' get result, 12 bits
HIGH ADcs ' deselect chip
RETURN