Hi Eric,
Neat bit of code!
I tried it and it does give me more stable results, either 0V or a value around 4.9V, but not the value of the input to AIN0 which is still 2.5V. I amended my own code to make it more streamline and I get the same results. What I did find interesting is that if I place any piece of code anywhere in the For..Next loop I start to get completely random results again! E.g.
For Rd = 0 To 11
' Add any code here.. e.g. Wait 0.001
V = Inp(STATUS) And 64
If V = 0 Then GoTo skip1
iADCValue = iADCValue + Ary(Rd)
skip1:
' ..or here.. e.g. DoEvents
Out DATA, 0 'ck=lo, cs=lo, dta=lo
Out DATA, 2 'ck=hi, cs=lo, dta=lo
Out DATA, 0 'ck=lo, cs=lo, dta=lo
' .. or here with this bit of code..
For n=0 to 100
Next
Next Rd
What's even more interesting is that if I reduce the extra loop to n=0 to 10 for example, I get back the more stable results as mentioned above...!
This implies some sort of timing issue problem but I was under the impression that the ADC can be driven asychronously, as there is no mention in the datasheet of the need for any independent clock. I did come across this little snippet though, near the bottom of page #12 - Principles of Operation - Conversion Cycle:
"..The conversion cycle is transparent to the user, and it is controlled by an internal clock synchronized to I/O CLOCK..". How any internal clock can synchronise with an externally applied clock of indeterminate frequency I don't know.. Maybe it has no bearing on the problem... Hmmm..
Thanks again,
Salvatore.