The phyCORE-AM65x SOM brings out four 12-bit ADC analog input channels (ADC0_AIN[3:0]). On the development kit, you can access these signals through a PHYTEC Expansion board (PCM-957). This guide provides a walk-through for wiring up a circuit with a potentiometer to test all four channels. 

Step-by-step guide

Connect to the ADC

VREF for ADC channels is 1.8V

Channels ADC0_AIN[3:0] can be found on the PHYTEC Expansion Board pins listed in the table below.

ADC ChannelExpansion Board Pin #
ADC0_AIN337C
ADC0_AIN236C
ADC0_AIN135C

ADC0_AIN0

34C

You can wire up a test circuit with a potentiometer (see example below):

Circuit Drawing

Expansion Board (PCM-957)

Set up Software Configuration

In order to be accessible in Linux, the ADC Channels need to be configured in the Linux device tree. PHYTEC has provided a sample device tree overlay in the boot directory of the root file system, which configures expansion connector interfaces used in this Peripheral Guide. To enable this device tree overlay:

  • The device tree overlay is set in U-Boot. 
  • Power on the device and immediately hit any key to enter U-Boot. (Approximately three seconds are allotted for the user to hit any key in order to halt autoboot of Linux.)
  • Clear the "default_overlays" variable and modify the "extra_overlays" variable to point to the sample dtbo: "k3-am65xx-phytec-expansion-sample.dtbo". The "default_overlays" variable needs to be cleared because it is set to k3-am65xx-phytec-lcd-018.dtbo which conflicts with the sample.

Target (U-Boot)

setenv default_overlays
setenv extra_overlays k3-am65xx-phytec-expansion-sample.dtbo
saveenv
CODE
  • To exit U-Boot and continue booting into Linux, type boot

Target (U-Boot)

boot
CODE


The Expansion Sample overlay k3-am65xx-phytec-expansion-sample.dtbo conflicts with the LCD-018 overlay due to the PWM being used for backlight in the LCD-018. Make sure to disconnect the display when using this overlay before powering on the development kit.

Read the ADC

You will be able to read each channel from the Linux command line. Below is a mapping of the ADC channel and corresponding device in Linux. 

ADC ChannelSignal Name

ADC0_AIN0

in_voltage0_raw
ADC0_AIN1in_voltage1_raw
ADC0_AIN2in_voltage2_raw
ADC0_AIN3in_voltage3_raw

This example shows how to read incoming data on ADC0_AIN0:

Target (Linux)

cat /sys/bus/iio/devices/iio\:device0/in_voltage0_raw
CODE

The ADC registers are 12 bits which will read from 0 to 4095. From the ADC reading you can calculate the voltage at the pin with the following formula:

ADC Reading to Voltage Formula

The potentiometer was adjusted and a couple readings were taken from Linux to calculate the voltage. See the below example. 

Expected Output

root@am65xx-phycore-kit:~# cat /sys/bus/iio/devices/iio\:device0/in_voltage0_raw
0
root@am65xx-phycore-kit:~# cat /sys/bus/iio/devices/iio\:device0/in_voltage0_raw
2092
root@am65xx-phycore-kit:~# cat /sys/bus/iio/devices/iio\:device0/in_voltage0_raw
4095
CODE
ADC readingVoltage
00V
20920.92V
40951.8V

Revert to the Default Software Configuration

This guide requires disabling the LCD-018 and enabling a sample expansion overlay. In order to revert back to the default overlay settings, the following needs to be run in U-Boot. (After application of power, approximately three seconds are allotted for the user to hit any key in order to halt autoboot of Linux.)

To enter U-Boot:

  • Power on or reset (S1) the hardware

  • Hit any key within 3 seconds to halt autoboot

Target (U-Boot)

env default -f -a
saveenv
CODE