This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

AM437x read ADC value in Continuous Mode

Hi,


I have a the evalution module AM437x  with the following configuration:

root@am437x-evm:~# uname -a
Linux am437x-evm 3.12.10-ti2013.12.01 #1 Mon Jun 9 09:55:20 CDT 2014 armv7l GNU/Linux

I want to read the 8 values ​​of the ADCs in Continuous Mode.
I try to use the application generic_buffer mentioned in the wiki:
processors.wiki.ti.com/.../Linux_Core_ADC_User%27s_Guide

but I don't have all the files in / sys/bus/iio/devices /iio\: device0/
(for example :  /sys/bus/iio/devices/iio\:device0/buffer/)

Here are the contents of the directory on my board:
root @ am437x-evm: ~ # ls -l / sys / bus / iio / devices / iio \: device0 /
-r - r - r-- 1 root root 4096 Jun 9 dev 9:04 p.m.
-rw-r - r-- 1 root root 4096 Jun 9 9:04 p.m. in_voltage0_raw
-rw-r - r-- 1 root root 4096 Jun 9 9:04 p.m. in_voltage1_raw
-rw-r - r-- 1 root root 4096 Jun 9 9:04 p.m. in_voltage2_raw
-rw-r - r-- 1 root root 4096 Jun 9 9:04 p.m. in_voltage3_raw
-rw-r - r-- 1 root root 4096 Jun 9 21:04 in_voltage4_raw
-rw-r - r-- 1 root root 4096 Jun 9 9:04 p.m. in_voltage5_raw
-rw-r - r-- 1 root root 4096 Jun 9 9:04 p.m. in_voltage6_raw
-rw-r - r-- 1 root root 4096 Jun 9 9:04 p.m. in_voltage7_raw
-r - r - r-- 1 root root 4096 Jun 9 9:04 p.m. name
drwxr-xr-x 2 root root 0 Jun 9 9:04 p.m. power
../../../../../bus/iio ">lrwxrwxrwx 1 root root 0 1 January 2000 subsystem -> ../../../../../bus/iio
-rw-r - r-- 1 root root 4096 1 January 2000 uevent

Thank you for your reply.


Alexandre D.

  • Hi Alexandre,

    I will ask the SW team to look at this.

  • Hi Alexandre,

    You should have the in_voltageN_raw channels (N is the number of channels specified in your adc device tree nodes), name, power, subsystem & uevent.
    As I see from your console output you have those in your sys/bus/iio/devices/iio \:device0/ directory. Can you clarify what exactly is the problem?

    Best Regards,
    Yordan
  • Indeed, I can read the ADC values from the command line:
    root @ am437x-evm: ~ # cat / sys / bus / iio / devices / iio \: device0 / in_voltage0_raw
    3985

    But what I want to do is to read these values in a C ++ program with a sampling period of 1ms.
    Currently, every time I want to read an ADC value I have to open/read/close a file. I guess that there is a better way to do this.

    Below is my code to access the value (using C++ and QT functions)

    QFile file(QString("/sys/bus/iio/devices/iio\:device0/subsystem/devices/iio\:device0/in_voltage%1_raw").arg(i));
    if (file.open(QIODevice::ReadOnly | QIODevice::Text))
    {
    QTextStream in(&file);
    QString line = in.readLine();
    file.close();
    }

    Thank you for your rely.

    Best Regards,
    Alexandre
  • Hi Alexandre,

    alup nelso said:
    Currently, every time I want to read an ADC value I have to open/read/close a file

    When working with user space application (as the one you've implemented) this is the way to go. 

    And can you please describe what is the issue with the generic_buffer example in the Sitara SDK? 

    Best Regards, 
    Yordan

  • Yes, open/read/close is the way to go in userspace, but it seems that I am forced to close and open again the file before each reading otherwise I receive nothing.

    And I suppose that  open/close the file at each reading consumes CPU time for nothing. I am looking for the fastest way to access to the ADC data in user-space.

    And can you please describe what is the issue with the generic_buffer example in the Sitara SDK?

     The generic_buffer example doesn't work on my board because I don't have the file :
    /sys/bus/iio/devices/iio\:device0/buffer
    Here the part of the code where this file is call:

    ret = asprintf(&buf_dir_name,

          "%siio:device%d/buffer", iio_dir, dev_num);

    if (ret < 0) {

    ret = -ENOMEM;

    goto error_ret;

    }

    printf("%s \n", dev_dir_name);

    /* Setup ring buffer parameters */

    ret = write_sysfs_int("length", buf_dir_name, buf_len);

    if (ret < 0)

    goto error_free_buf_dir_name;

    Best regards,

    Alexandre