BB-ADC analog input update

I have enabled the analog inputs on a Beaglebone Black by adding BB-ADC to optargs in uEnv.txt:

optargs=capemgr.disable_partno=BB-BONELT-HDMI capemgr.enable_partno=BB-SPIDEV0,BB-SPIDEV1,BB-UART1,BB-ADC

The basic analog input works, if I do a:

cat /sys/bus/iio/devices/iio:device0/in_voltage3_raw

it returns a value which is proportional to the applied voltage.

However the value is not always up-to-date. If I change the input voltage, I can read the old input voltage several times before I can read the correct value. The strange part is that I am obviously not just reading a stored value, because the LSB can change on subsequent reads, until I finally read the correct value:

jsa@bb00:~$ cat /sys/bus/iio/devices/iio:device0/in_voltage3_raw
489

The applied voltage is now halved (from ~200mV to ~100mV). I wait for about 1 second between each read:

jsa@bb00:~$ cat /sys/bus/iio/devices/iio:device0/in_voltage3_raw
489
jsa@bb00:~$ cat /sys/bus/iio/devices/iio:device0/in_voltage3_raw
488
jsa@bb00:~$ cat /sys/bus/iio/devices/iio:device0/in_voltage3_raw
489
jsa@bb00:~$ cat /sys/bus/iio/devices/iio:device0/in_voltage3_raw
489
jsa@bb00:~$ cat /sys/bus/iio/devices/iio:device0/in_voltage3_raw
489
jsa@bb00:~$ cat /sys/bus/iio/devices/iio:device0/in_voltage3_raw
488
jsa@bb00:~$ cat /sys/bus/iio/devices/iio:device0/in_voltage3_raw
489
jsa@bb00:~$ cat /sys/bus/iio/devices/iio:device0/in_voltage3_raw
243

Finally I read the correct value. What is going on? Can I force an update (sample)?

I’m seeing the same issue. The number of reads it takes to get the actual value seems to correspond to the number of analog pins you have read from. If you have only read from one adc pin, you will get the correct values each time. I’ve mailed those who were listed on the commits for ti_am33x_adc. Hopefully we will get a response.

That would be nice. My application requires more than one ADC.

I did a little experimenting, and unfortunately it seems the the relationship is more complex. For example if I reboot, and read from AIN3, the value updates for every read. I then read from AIN4, after which I still see the AIN3 update for every read. I then read from AIN0, and AIN3 starts updating only on every second read. I then read from AIN1, but AIN3 still updates every second read. I then tried reading from AIN0-AIN6, after that AIN3 updates every 4th read. After which I invoked the FSM with a cry of argh!

It’s a bug. Being discussed here.

http://marc.info/?l=linux-iio&m=139623868828389&w=2

It is introduced by patch

0019-iio-ti_am335x_adc-Add-continuous-sampling-and-trigge.patch

I AM experimenting the same very issue. I havê opened a tópicos about this but got no reply. Hopefully se can get a solution here.

Issue and steps to build a kernel w/ the fixes here.

http://bugs.elinux.org/issues/73