Reading from ADC hangs

Hi,

I enabled tscadc in the dts-file and then tried to read the ADC from command line:

ubuntu@arm:/sys/bus/iio/devices/iio:device0$ cat in_voltage*
3961
3581
3933
2233
2272
3400
3187
3816
ubuntu@arm:/sys/bus/iio/devices/iio:device0$ cat in_voltage*
3960
3588
3936
2454
2500
2891

and here it hangs. In dmesg I get every two minutes

[ 1680.880664] INFO: task cat:1775 blocked for more than 120 seconds.
[ 1680.887475] Not tainted 3.18.4-bone1 #1
[ 1680.892385] “echo 0 > /proc/sys/kernel/hung_task_timeout_secs” disables this message.
[ 1680.900979] cat D c05bfe53 0 1775 1690 0x00000001
[ 1680.901090] [] (__schedule) from [] (am335x_tsc_se_set_once+0x87/0xb8)
[ 1680.901188] [] (am335x_tsc_se_set_once) from [] (tiadc_read_raw+0x84/0x114 [ti_am335x_adc])
[ 1680.901344] [] (tiadc_read_raw [ti_am335x_adc]) from [] (iio_read_channel_info+0x56/0x5c [industrialio])
[ 1680.901687] [] (iio_read_channel_info [industrialio]) from [] (dev_attr_show+0x13/0x34)
[ 1680.901749] [] (dev_attr_show) from [] (sysfs_kf_seq_show+0x63/0xa8)
[ 1680.901798] [] (sysfs_kf_seq_show) from [] (seq_read+0x125/0x2d8)
[ 1680.901846] [] (seq_read) from [] (vfs_read+0x5d/0x110)
[ 1680.901886] [] (vfs_read) from [] (SyS_read+0x33/0x70)
[ 1680.901933] [] (SyS_read) from [] (ret_fast_syscall+0x1/0x44)

and I can’t kill the “cat” task. Have others encountered this? Are there known issues with the ADC on BBB? I’m using Ubuntu 14.04 with kernel 3.18.4-bone1.

There’re lots of issues using the sysfs ADC. That’s why I wrote libpruio, which gives you full control over the ADC subsystem and provides much faster sampling rates (beside other features). Just check out the examples. (Note: kernel 3.18 doesn’t have the capemgr, you may need to downgrade to 3.8, or ask RCN for a solution).

BR

Thanks for the suggestion. I’ll keep that in mind if I need higher sampling rates. However, I did find a way to read ADC through IIO so that it doesn’t hang.

First set up the channels and the buffer through sysfs:

echo 1 > /sys/bus/iio/devices/iio:device0/scan_elements/in_voltage0_en
echo 256 > /sys/bus/iio/devices/iio:device0/buffer/length
echo 1 > /sys/bus/iio/devices/iio:device0/buffer/enable

and then read from /dev/iio:device0. This way I can achieve about 8 kHz sampling rate with a single channel, 4 kHz with two channels and down to ~300 Hz with all eight channels.

Hi,

How come in my system, there is no /sys/bus/iio/devices/iio:device0?
Under /sys/bus/iio/devices/, there is only one file iio_sysfs_trigger, which is a symbolic link to some other directory.
Is there any configuration I need to do?
I am using the latest BB black Rev C by Element14. It is OS is 3.8.13-bone47.

Thx.

Hi,

How come in my system, there is no /sys/bus/iio/devices/iio:device0?
Under /sys/bus/iio/devices/, there is only one file iio_sysfs_trigger, which is a symbolic link to some other directory.
Is there any configuration I need to do?
I am using the latest BB black Rev C by Element14. It is OS is 3.8.13-bone47.

Thx.

Hi,

You need to enable the ADC either by enabling the correct “cape” with capemgr (only in kernel 3.8.*, see e.g. http://hipstercircuits.com/reading-analog-adc-values-on-beaglebone-black/), or by enabling it in the .dts-file (later kernels, such as the 3.18.4 which I’m using).

Matti

What cape did you load?
When I reboot, I see as you did
>: ls -als /sys/bus/iio/devices/
total 0
0 drwxr-xr-x 2 root root 0 Dec 31 1999 .
0 drwxr-xr-x 4 root root 0 Dec 31 1999 ..
0 lrwxrwxrwx 1 root root 0 Dec 31 1999 iio_sysfs_trigger -> ../../../devices/iio_sysfs_trigger

After I
echo cape-bone-iio > /sys/devices/bone_capemgr.9/slots
then I see
>: ls -als /sys/bus/iio/devices/
total 0
0 drwxr-xr-x 2 root root 0 Dec 31 1999 .
0 drwxr-xr-x 4 root root 0 Dec 31 1999 ..
0 lrwxrwxrwx 1 root root 0 Feb 26 10:07 iio:device0 -> ../../../devices/ocp.3/44e0d000.tscadc/tiadc/iio:device0
0 lrwxrwxrwx 1 root root 0 Dec 31 1999 iio_sysfs_trigger -> ../../../devices/iio_sysfs_trigger

and
>: cat /sys/devices/bone_capemgr.9/slots
  0: 54:PF---
  1: 55:PF---
  2: 56:PF---
  3: 57:PF---
  4: ff:P-O-L Bone-LT-eMMC-2G,00A0,Texas Instrument,BB-BONE-EMMC-2G
  5: ff:P-O-- Bone-Black-HDMI,00A0,Texas Instrument,BB-BONELT-HDMI
  6: ff:P-O-- Bone-Black-HDMIN,00A0,Texas Instrument,BB-BONELT-HDMIN
  7: ff:P-O-L Override Board Name,00A0,Override Manuf,cape-bone-iio

Chad

Hi

following ur guide, it almost worked.

However, when issuing command

echo 1 > /sys/bus/iio/devices/iio:device0/buffer/enable

System gives me error: echo: wrrite error: Invalid argument

I already use root to issue to command, and strangely “echo 1 > /sys/bus/iio/devices/iio:device0/buffer/length” worked.

Hi,

by issuing command: echo cape-bone-iio > /sys/devices/bone_capemgr.9/slots,
now i can see iio:device0.

However, when I ran
echo 1 > /sys/bus/iio/devices/iio:device0/scan_elements/in_voltage0_en
echo 256 > /sys/bus/iio/devices/iio:device0/buffer/length
echo 1 > /sys/bus/iio/devices/iio:device0/buffer/enable
The last one always fails with echo write error: invalid argument.

Hi,

Hi

following ur guide, it almost worked.

However, when issuing command

echo 1 > /sys/bus/iio/devices/iio:device0/buffer/enable

System gives me error: echo: wrrite error: Invalid argument

I already use root to issue to command, and strangely “echo 1 > /sys/bus/iio/devices/iio:device0/buffer/length” worked.

Does your kernel present /sys/bus/iio/devices/iio:device0/mode ? If it does, try issuing “echo continuous > /sys/bus/iio/devices/iio:device0/mode” and then try to enable buffer again.

Matti

Hi Guys,

Thank you all for your replies.
I found after issuing command: echo cape-bone-iio > /sys/devices/bone_capemgr.9/slots
The ADC can be read from /sys/devices/ocp.3/helper.15/AIN* files just as pointed out in http://hipstercircuits.com/reading-analog-adc-values-on-beaglebone-black/

Hi Matti,

Would you please provide details on which dts entries (or maybe a link to the entire dts file!) you’re specifying in order to get ADC working with 3.18?

Thanks!

Hi,

I simply added

&tscadc {
status = “okay”;
};

&am335x_adc {
ti,adc-channels = <0 1 2 3 4 5 6 7>;
};

to the end of am335x-boneblack.dts.