How-to: Read ADC on the i.MX7 with Linux
Targeted Hardware | phyBOARD-Zeta (i.MX7) |
Targeted Software | Release PD17.2.0 (Coming Soon) |
Date |
|
This article will demonstrate how to set up and access X_ADC_IN0 on the phyBOARD-Zeta (i.MX7). Software release PD17.1.1 can be modified to enable the ADC1 channel following the instructions in this guide. Support for the ADC is planned to be incorporated in the PD17.2.0 software release.
ADC Access on the phyBOARD-Zeta
The ADC channel 1 pins on the phyCORE-i.MX7 are brought out to the expansion connector (X16) on the phyBOARD-Zeta as X_ADC_INx. This guide uses signal X_ADC_IN0 as an example, but the below table provides the location where alternative ADC input signals can be accessed.
Net Name | Expansion Connector Pin (X16) |
---|---|
X_ADC_IN0 | pin 85 |
X_ADC_IN1 | pin 87 |
X_ADC_IN2 | pin 89 |
X_ADC_IN3 | pin 91 |
Implementation Details
Software release PD17.1.1 does not enable the ADC by default. The steps below can be used as a guide to enable the ADC, rebuild the device tree, and deploy/test the changes. Please note that the next BSP Release, PD17.2.0 will support ADC and these steps will not be required.
Configuring the device tree
To enable the ADC peripheral, you will need to modify the device tree.
Using a text editor, open the file called 'imx7d-phyboard-zeta.dts' located in the following directory:
<your BSP directory>/yocto_imx7/build/tmp/work/imx7d_phyboard_zeta-poky-linux-gnueabi/linux-phytec-fsl/4.1.15+git_v4.1.15-phy2-r0/git/arch/arm/boot/dts/
CODEAdd the following device tree node to enable the ADC1 peripheral:
&adc1 { vref-supply = <®_vref_1v8>; status = "okay"; };
CODENext you want to edit the 'imx7d-pba-c-09.dtsi' file located in the same directory:
<your BSP directory>/yocto_imx7/build/tmp/work/imx7d_phyboard_zeta-poky-linux-gnueabi/linux-phytec-fsl/4.1.15+git_v4.1.15-phy2-r0/git/arch/arm/boot/dts/
BASHAdd the following device tree node under the regulators section to enable the 1v8 voltage reference:
reg_vref_1v8: regulator@2 { compatible = "regulator-fixed"; reg = <2>; regulator-name = "vref-1v8"; regulator-min-microvolt = <1800000>; regulator-max-microvolt = <1800000>; };
BASH
Rebuilding the Device Tree
After the necessary modifications to the device tree, you will need to rebuild the device tree.
Navigate to your build directory:
cd <your BSP directory>/yocto_imx7/build
BASHRun the following command to rebuild the kernel:
bitbake linux-phytec-fsl -f -c compile && bitbake linux-phytec-fsl
BASHMount an SD card with an existing PD17.1.1 image. If you do not have an SD card with image PD17.1.1, follow steps 1 through 3 in the 'Booting with Pre-built Images' section of the Quickstart guide.
Remove the existing device tree from the SD card using the following command:
rm /media/Boot\ imx7-p/imx7d-phyboard-zeta.dtb
CODENavigate to the directory on your build machine where the compiled images are deployed:
cd <your BSP directory>/build/tmp/deploy/images/imx7d-phyboard-zeta
CODECopy and rename the device tree to the SD card using the following command:
cp zImage-imx7d-phyboard-zeta.dtb /media/user/Boot\ imx7d-/imx7d-phyboard-zeta.dtb; sync
CODEUnmount the SD card.
Hardware setup
- Install the SD card on the i.MX7 board and configure the boot switch (SD1)
SD Card (4-bit SD1 interface)
Implement the following test circuit:
DO NOT use an input voltage greater than 1.8V on any of the X_ADC_INx input channels.
- Start your favorite terminal software (such as Minicom or TeraTerm) on your host PC and configure it for 115200 baud, 8 data bits, no parity, and 1 stop bit (8n1) with no handshake.
- Apply power and press the power switch (S2) to boot Linux. This will boot the system so you can test the updates.
Testing ADC
Now that all the software and hardware setup has been complete we can test the changes.
- At the login prompt, enter "root" as the username. There is no required password.
You should now be able to quickly test/read the ADC register by using the following command:
cat /sys/bus/iio/devices/iio\:device0/in_voltage0_raw
BASH- Here is an example of three measurements of roughly 1.8V (4096), 0.9V (2048) and 0.0V (0).