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.

am335x adc reading

Hi,

I am trying to read my battery level voltage from adc channel 6 under am335x custom board. I have configured pin mux and assigned the adc and touch as below

static struct tsc_data am335x_touchscreen_data = {
.wires = 0,
.x_plate_resistance = 200,
};

static struct adc_data am335x_adc_data = {
.adc_channels = 1,
};

static struct mfd_tscadc_board tscadc = {
.tsc_init = &am335x_touchscreen_data,
.adc_init = &am335x_adc_data,
};

It has created the ADC interface under /sys/bus/iio/devices/iio\:device0/in_voltage0_raw it shows 4095. nut i am unable to operate my touchscreen. as per my configuration weather the adc is giving the values are correct or not?? using with this adc configuration my touch screen is not working.

Is there any constraint to use either adc channel or touch screen.

Please help me. how to solve my issue.

Thanks,

Lofna

  • Hi Biser,

    Thanks for your response.

    I am using Linux 3.2 from TI SDK6. i am also referring the same document and created the interfaces under /sys/bus/iio/devices/iio\:device0/
    cat in_voltage0_raw
    4095
    It is giving the adc result. my issue is while defining the adc my touch screen is not functioning. if i remove the adc touch screen is working. is there any configuration i missing under board file.

    Thanks
  • Why do you have ".wires = 0," in your code?

  • I have tried .wires = 4 also, i am getting the same issue.

    Thanks
  • Hi Lofna,

    In <>/ti-sdk-am335x-evm-06.00.00.00/board-support/linux-3.2.0-psp04.06.00.11/arch/arm/mach-omap2/board-am335xevm.c file code menage TS and ADC is:

    /* TSc controller */
    static struct tsc_data am335x_touchscreen_data = {
    .wires = 4,
    .x_plate_resistance = 200,
    .steps_to_configure = 5,
    };

    static struct adc_data am335x_adc_data = {
    .adc_channels = 4,
    };

    static struct mfd_tscadc_board tscadc = {
    .tsc_init = &am335x_touchscreen_data,
    .adc_init = &am335x_adc_data,
    };
    ...
    static void mfd_tscadc_init(int evm_id, int profile)
    {
    int err;

    err = am33xx_register_mfd_tscadc(&tscadc);
    if (err)
    pr_err("failed to register touchscreen device\n");
    }

    and for me they works well together. Here is the log from the console:
    root@am335x-evm:/sys/bus/iio/devices/iio:device0# ls -l
    drwxr-xr-x 2 root root 0 Jun 25 23:40 buffer
    -r--r--r-- 1 root root 4096 Jun 25 23:40 dev
    -r--r--r-- 1 root root 4096 Jun 25 23:40 in_voltage4_raw
    -r--r--r-- 1 root root 4096 Jun 25 23:40 in_voltage5_raw
    -r--r--r-- 1 root root 4096 Jun 25 23:40 in_voltage6_raw
    -r--r--r-- 1 root root 4096 Jun 25 23:40 in_voltage7_raw
    -rw-r--r-- 1 root root 4096 Jun 25 23:40 mode
    -r--r--r-- 1 root root 4096 Jun 25 23:40 name
    drwxr-xr-x 2 root root 0 Jun 25 23:40 power
    drwxr-xr-x 2 root root 0 Jun 25 23:40 scan_elements
    lrwxrwxrwx 1 root root 0 Jan 1 2000 subsystem -> ../../../../../../bus/iio
    -rw-r--r-- 1 root root 4096 Jan 1 2000 uevent

    root@am335x-evm:/sys/bus/iio/devices/iio:device0# cat in_voltage4_raw
    503
    root@am335x-evm:/sys/bus/iio/devices/iio:device0# cat in_voltage4_raw
    837

    Results from not pressed and pressed TS.

    BR
    Ivan
  • Hi Ivan,

    As per your configuration i have changed the code and defined as below function and created 4 adc channel interfaces. But my touchscreen is not working. there is no cursor movement on my lcd.

    Is it required to define the touch screen pinmux configuration under the board-am335xevm.c file.

    static void mfd_tscadc_init(int evm_id, int profile)
    {
    int err;
    // setup_pin_mux(tsc_pin_mux);
    // setup_pin_mux(adc_pin_mux);
    err = am33xx_register_mfd_tscadc(&tscadc);
    if (err)
    pr_err("failed to register touchscreen device\n");
    }

    root@am335x-evm:/sys/bus/iio/devices/iio:device0# ls -al
    drwxr-xr-x 3 root root 0 Jan 1 2000 .
    drwxr-xr-x 4 root root 0 Jan 1 2000 ..
    -r--r--r-- 1 root root 4096 Mar 3 17:38 dev
    -r--r--r-- 1 root root 4096 Mar 3 17:38 in_voltage0_raw
    -r--r--r-- 1 root root 4096 Mar 3 17:38 in_voltage1_raw
    -r--r--r-- 1 root root 4096 Mar 3 17:38 in_voltage2_raw
    -r--r--r-- 1 root root 4096 Mar 3 17:38 in_voltage3_raw
    -r--r--r-- 1 root root 4096 Mar 3 17:38 name
    drwxr-xr-x 2 root root 0 Mar 3 17:38 power
    lrwxrwxrwx 1 root root 0 Jan 1 2000 subsystem -> ../../../../../../bus/iio
    -rw-r--r-- 1 root root 4096 Jan 1 2000 uevent

    Please let us know.

    Thanks
  • Hi Ivan,

    Now the touch screen is also working and i am able to create adc 4 channel interfaces under system interface /sys/bus/iio/devices/iio:device0/

    find the below adc channels list. it has to show the adc channels are in_voltage4_raw, in_voltage5_raw, in_voltage6_raw, in_voltage7_raw. but it showing as below.

    I am connecting channel 6(in_voltage6_raw) to my battery input for measuring the voltage.

    root@am335x-evm:/sys/bus/iio/devices/iio:device0# ls -al
    drwxr-xr-x 3 root root 0 Jan 1 2000 .
    drwxr-xr-x 4 root root 0 Jan 1 2000 ..
    -r--r--r-- 1 root root 4096 Mar 3 17:38 dev
    -r--r--r-- 1 root root 4096 Mar 3 17:38 in_voltage0_raw
    -r--r--r-- 1 root root 4096 Mar 3 17:38 in_voltage1_raw
    -r--r--r-- 1 root root 4096 Mar 3 17:38 in_voltage2_raw
    -r--r--r-- 1 root root 4096 Mar 3 17:38 in_voltage3_raw
    -r--r--r-- 1 root root 4096 Mar 3 17:38 name
    drwxr-xr-x 2 root root 0 Mar 3 17:38 power
    lrwxrwxrwx 1 root root 0 Jan 1 2000 subsystem -> ../../../../../../bus/iio
    -rw-r--r-- 1 root root 4096 Jan 1 2000 uevent
    root@am335x-evm:/sys/bus/iio/devices/iio:device0# cat in_voltage2_raw
    2749
    root@am335x-evm:/sys/bus/iio/devices/iio:device0# cat in_voltage2_raw
    2761
    root@am335x-evm:/sys/bus/iio/devices/iio:device0# cat in_voltage2_raw
    2753
    root@am335x-evm:/sys/bus/iio/devices/iio:device0# cat in_voltage2_raw
    2747
    root@am335x-evm:/sys/bus/iio/devices/iio:device0# cat in_voltage2_raw
    2744
    root@am335x-evm:/sys/bus/iio/devices/iio:device0# cat in_voltage2_raw
    2743

    Please let us know. Is this the value is getting from battery input channel or something else??

    Thanks
  • Check out this link to understand how to interpret that value. processors.wiki.ti.com/.../Linux_Core_ADC_User%27s_Guide
  • Hi,

    Is it required to define the pinmux for touchscreen and adc under the static void mfd_tscadc_init(int evm_id, int profile)
    function.

    Please find the below configuration is required to define under board file or not?? also let us know the sdk6 driver files for touch & adc. because something i am missing some elements under the /sys/bus/iio/devices/iio:device0.

    setup_pin_mux(tsc_pin_mux);
    setup_pin_mux(adc_pin_mux);
    static struct pinmux_config tsc_pin_mux[] = {
    {"ain0.ain0", OMAP_MUX_MODE0 | AM33XX_INPUT_EN},
    {"ain1.ain1", OMAP_MUX_MODE0 | AM33XX_INPUT_EN},
    {"ain2.ain2", OMAP_MUX_MODE0 | AM33XX_INPUT_EN},
    {"ain3.ain3", OMAP_MUX_MODE0 | AM33XX_INPUT_EN},
    {"vrefp.vrefp", OMAP_MUX_MODE0 | AM33XX_INPUT_EN},
    {"vrefn.vrefn", OMAP_MUX_MODE0 | AM33XX_INPUT_EN},
    {NULL, 0},
    };

    static struct pinmux_config adc_pin_mux[] = {
    {"ain6.ain4", OMAP_MUX_MODE0 | AM33XX_INPUT_EN},
    {"ain6.ain5", OMAP_MUX_MODE0 | AM33XX_INPUT_EN},
    {"ain6.ain6", OMAP_MUX_MODE0 | AM33XX_INPUT_EN},
    {"ain6.ain7", OMAP_MUX_MODE0 | AM33XX_INPUT_EN},
    {"vrefp.vrefp", OMAP_MUX_MODE0 | AM33XX_INPUT_EN},
    {"vrefn.vrefn", OMAP_MUX_MODE0 | AM33XX_INPUT_EN},
    {NULL, 0},
    };

    After booting my system i am not getting the below order.

    root@am335x-evm:/sys/bus/iio/devices/iio:device0# ls -l
    drwxr-xr-x 2 root root 0 Jun 25 23:40 buffer
    -r--r--r-- 1 root root 4096 Jun 25 23:40 dev
    -r--r--r-- 1 root root 4096 Jun 25 23:40 in_voltage4_raw
    -r--r--r-- 1 root root 4096 Jun 25 23:40 in_voltage5_raw
    -r--r--r-- 1 root root 4096 Jun 25 23:40 in_voltage6_raw
    -r--r--r-- 1 root root 4096 Jun 25 23:40 in_voltage7_raw
    -rw-r--r-- 1 root root 4096 Jun 25 23:40 mode
    -r--r--r-- 1 root root 4096 Jun 25 23:40 name
    drwxr-xr-x 2 root root 0 Jun 25 23:40 power
    drwxr-xr-x 2 root root 0 Jun 25 23:40 scan_elements
    lrwxrwxrwx 1 root root 0 Jan 1 2000 subsystem -> ../../../../../../bus/iio
    -rw-r--r-- 1 root root 4096 Jan 1 2000 uevent


    Please help me.

    Thanks,

  • Pinmuxing shouldn't have anything to do with seeing those additional entries under /sys/bus/iio/devices/iio:device0. Either you are missing a kernel config option or the kernel you are using doesn't have support for continuous mode.

    Your last post you mentioned that touchscreen and ADC are both working and you showed that you were getting samples from the ADC for your battery. I sent you a link that explains how to convert that value to a voltage.

    You are using a relatively old kernel from an old SDK. I would strongly recommend if possible using our latest SDK 8. There have been significant amount of improvements in general but I know of alot of bugs that are fixed related to touchscreen and adc within the new kernel.
  • Hi,

    I have interfaced the battery input to ADC channel 6. In my platform it has created the interface as below.

    reading the data from channel 6(ch0  - ch6) which value I need to read, Is it 'in_voltage2_raw' or 'in_voltage1_raw'

    root@am335x-evm:/sys/bus/iio/devices/iio:device0# ls -al
    drwxr-xr-x 3 root root 0 Jan 1 2000 .
    drwxr-xr-x 4 root root 0 Jan 1 2000 ..
    -r--r--r-- 1 root root 4096 Mar 3 17:38 dev
    -r--r--r-- 1 root root 4096 Mar 3 17:38 in_voltage0_raw
    -r--r--r-- 1 root root 4096 Mar 3 17:38 in_voltage1_raw
    -r--r--r-- 1 root root 4096 Mar 3 17:38 in_voltage2_raw
    -r--r--r-- 1 root root 4096 Mar 3 17:38 in_voltage3_raw
    -r--r--r-- 1 root root 4096 Mar 3 17:38 name
    drwxr-xr-x 2 root root 0 Mar 3 17:38 power
    lrwxrwxrwx 1 root root 0 Jan 1 2000 subsystem -> ../../../../../../bus/iio
    -rw-r--r-- 1 root root 4096 Jan 1 2000 uevent

    after OS booted up the ADC results are like this:

    root@am335x-evm:~# cat /sys/bus/iio/devices/iio\:device0/in_voltage0_raw

    411

    root@am335x-evm:~# cat /sys/bus/iio/devices/iio\:device0/in_voltage1_raw

    867

    root@am335x-evm:~# cat /sys/bus/iio/devices/iio\:device0/in_voltage2_raw

    4096

    root@am335x-evm:~# cat /sys/bus/iio/devices/iio\:device0/in_voltage3_raw

    4096

    As per the results which one is my ADC results. there is no order like "in_voltage0_raw" to "in_voltage7_raw"

    Thanks

  • Hi,

    After applied the patches now i am getting proper order values under below ADC sysfs interface. But still i am not getting the correct ADC battery value, always it shows 4096. I am using "AIN6" channel connected to my VBAT(Li-Ion).

    I have doubt in my schematic, Please find attached my schematic and suggest me where it is going wrong.

    root@am335x-evm:~# cd /sys/bus/iio/devices/iio\:device0/

    root@am335x-evm:/sys/bus/iio/devices/iio:device0# ls -al

    drwxr-xr-x    5 root     root             0 Jan  1  2000 .

    drwxr-xr-x    4 root     root             0 Jan  1  2000 ..

    drwxr-xr-x    2 root     root             0 Mar  3 17:31 buffer

    -r--r--r--    1 root     root          4096 Mar  3 17:31 dev

    -r--r--r--    1 root     root          4096 Mar  3 17:31 in_voltage4_raw

    -r--r--r--    1 root     root          4096 Mar  3 17:31 in_voltage5_raw

    -r--r--r--    1 root     root          4096 Mar  3 17:31 in_voltage6_raw

    -r--r--r--    1 root     root          4096 Mar  3 17:31 in_voltage7_raw

    -rw-r--r--    1 root     root          4096 Mar  3 17:31 mode

    -r--r--r--    1 root     root          4096 Mar  3 17:31 name

    drwxr-xr-x    2 root     root             0 Mar  3 17:31 power

    drwxr-xr-x    2 root     root             0 Mar  3 17:31 scan_elements

    lrwxrwxrwx    1 root     root             0 Jan  1  2000 subsystem -> ../../../../../../bus/iio

    -rw-r--r--    1 root     root          4096 Jan  1  2000 uevent

    root@am335x-evm:/sys/bus/iio/devices/iio:device0#

    root@am335x-evm:/sys/bus/iio/devices/iio:device0# cat in_voltage6_raw

    4096

    Thanks

    adc-schematic.docx

  • Hi Biser,

    Could you help me on the above issue.

    Please do the needful.

    Thanks

  • Are you applying more than the maximum input voltage of 1.8 volts to the ADC inputs?

    Regards,
    Paul
  • Hi Paul,

    I have checked the voltage at VREF is 1.825V and my VBAT voltage is 3.7V, 8000mAh and getting the divider voltage at IN6 is 1.17V.

    But i am getting still 4096 continuously.

    Please any changes required in software end.

    Thanks,
  • Looking at VBAT from your schematic the output of your voltage divider is 2.78 V which is well beyond the max 1.8 V that should be connected to the adc.

  • Hi Franklin,

    I am also have the same doubt and i have changed the resistor values. Please find the below divider circuit and give me your suggestions.

    after change values still i am getting continousely 4096 (1.8V) value

    root@am335x-evm:/sys/bus/iio/devices/iio:device0# cat in_voltage6_raw

    4096

    Thanks,

    adc-divider-circuit.docx

  • Well its possible that you have damaged the pin since you have been setting 3.7 volts. Can you try connecting another ADC to the output?
  • Your schematic shows VREFN connected to a different ground symbol than the input voltage divider. Are these two grounds at the same potential? How did you connect the ADC power supply terminals, VDDA_ADC and VSSA_ADC?

    Regards,
    Paul
  • Hi Paul,

    Yes we have connected the ADC & digital ground. Please find attached circuit.

    Thanks

    adc-circuit.docx

  • HI Paul,

    Even i have tried in AM335X evm and suing the same ADC code, it always showing the 4096 value. Applied externally 0.68V to TSC_AIN6 (on daughter board J8 connector). In evm also there is no effect. any suggestion test the ADC and get the right value across input voltage.

    Thanks
  • What is the value of R295 on your board?

    Based on your comments of testing the EVM, it sounds like you may have a software issue. I'm not familiar with the software, so will not be able to help you with any software issues.

    Regards,
    Paul
  • Hi

    R295 value is 1ohm with 1%. Please suggest me.

    Thanks

  • Okay, that should not be a problem.

    Regards,
    Paul

  • Hi Paul,

     

    Why i am not getting the ADC result. Any other issues, Because i am using Linux 3.2 from sdk6 and applied the current patches to drivers.

     

    Thanks