[beaglebone] unexpected behavior reading adc pins

I am reading multiple adc pins one after the other using /sys/bus/platform/devices/tsc/ain*.
Regardless of using the commandline like this:

cat /sys/bus/platform/devices/tsc/ain1
cat /sys/bus/platform/devices/tsc/ain2
cat /sys/bus/platform/devices/tsc/ain1

or using bonescript, there is an unexpected behavior.

The first value read for a certain pin seems to be wrong.
So reading the values of adc pins one after the other is giving wrong values at line.

Reading the value for the same pin two times gives the expected value from the second read.

My workaround at the moment is to read the value for an adc pin twice and using the last read value.

So for bonescript I patched the analogRead function this way:

analogRead = exports.analogRead = function(pin)
{
fs.readFileSync("/sys/bus/platform/devices/tsc/ain" + (pin + 1), null); //throw away the value., it might be wrong
return fs.readFileSync("/sys/bus/platform/devices/tsc/ain" + (pin + 1), null);
};

Could this behavior be a bug in the kernel driver code for adc?

I cannot recreate this behavior using the values from the file system and
uname -a : Linux beaglebone 3.2.9+ #1 Tue Mar 6 19:43:04 CET 2012 armv7l GNU/Linux

Markus

2012/3/17 yantsu <cthiele42@gmail.com>

I am using kernel 3.2.5. I will make an upgrade an check again.

Claas

Thanks Markus for your investigation.

Upgrade done. But that doesn’t solve the problem.

Further experiments have unveiled the root cause: It is the way I am supplying power to the board.
If the board is only connected via USB, no extra 5V power supply is connected, the problem shows up.
If the board is connected to the 5V power supply, everything works fine.

So, if somebody plans to use the adc, it is strongly recommended to make use of a 5V power supply.

Claas

AFAIK this is not entirely true. One of the 5V connectors also supplies 5V when connected to USB only.
And I just mention it, because I am not sure you know, I am not sure from your answer.
the analog pins only support 1.8V - don’t connect them to higher voltages. there is a Vadc for something like that pin on bank 9.

Markus

2012/3/20 yantsu <cthiele42@gmail.com>

Has this been resolved?

I’m currently running the A6A image ( http://circuitco.com/support/index.php?title=BeagleBone#Revision_A6A_Image ) with the latest opkg update and upgrade on a Rev. 6 BeagleBone. Using the default software: Cloud9 IDE, bonescript, etc.

A simple fs.readFileSync(ADCPATH + (pin.ain+1)) reads the incorrect value. A second read works correctly.

Any other work arounds?

Thanks,
David J.