4.5.17. ADC Test

4.5.17.1. Test Principle

ADC (Analog-to-Digital Converter) testing is used to verify the functional correctness and sampling accuracy of the on-chip ADC module. The X5 chip integrates a 10-bit ADC with 8 sampling channels (channel 0-7), exposed through the Linux IIO (Industrial I/O) subsystem via sysfs and character device interfaces.

The ADC test script adc_test.sh supports two sampling modes:

  • Single sampling: Reads the raw value of a specified channel through the sysfs interface one at a time, suitable for low-frequency sampling scenarios. Each read from in_voltageN_raw obtains the current ADC raw value.

  • Continuous sampling: Achieves high-speed continuous sampling through the IIO buffer mechanism. After enabling the buffer for the specified channel, continuous data streams are read from the character device /dev/iio:device0, suitable for high-frequency sampling and stress testing scenarios.

Voltage conversion formula:

Voltage(mV) = raw × vol_scale

Where vol_scale is read from in_voltage_scale (unit: mV/LSB), calculated by the driver based on the reference voltage (vref) and resolution. For example, with vref = 1.8V and 10-bit resolution, vol_scale = 1800 / 1024 1.7578 mV/LSB.

4.5.17.2. Preparation

Script Usage

adc_test.sh supports the -h option to display help information:

# ./adc_test.sh -h
usage: ./adc_test.sh <channel{3-7}> [-m mode] [-n count] [-i interval]
  channel      ADC channel number (3-7)
  -m mode      sample mode: single (default) / continuous
  -n count     sample count, 0=infinite (default: 0)
  -i interval  sample interval in seconds for single mode (default: 1)

Parameter Description

Parameter Description Default
channel ADC channel number, range 3-7 Required
-m mode Sampling mode: single / continuous single
-n count Number of samples, 0 for infinite loop 0
-i interval Sampling interval in seconds, single mode only 1

Notes

  1. Verify that the IIO device files exist:

    # ls /sys/bus/iio/devices/iio:device0/
    

    The directory should contain in_voltageN_raw, in_voltage_scale, and other nodes.

  2. Continuous sampling mode requires IIO buffer and character device support. Verify that the following paths exist:

    /sys/bus/iio/devices/iio:device0/buffer0/
    /dev/iio:device0
    
  3. Before testing, confirm the pin location corresponding to the channel under test. Refer to the X5 EVB schematic to locate the ADC channel pins and connector positions, and connect the voltage signal to be measured.

  4. The ADC input voltage range depends on the reference voltage (vref). Do not exceed the measurement range, otherwise the chip may be damaged.

4.5.17.3. Test Steps

Single Sampling Test

Single sampling mode reads ADC raw values one at a time through the sysfs interface, suitable for basic functional verification.

Basic usage (infinite loop, press Ctrl+C to stop):

# ./adc_test.sh 3

Example output:

========================================
ADC Test Info
========================================
Channel     : 3
Mode        : single
IIO Device  : 34190000.adc
Scale       : 1.757812500
ADC Clock   : 9523810 Hz
ADC APB Clk : 200000000 Hz
Count       : infinite
Interval    : 1s
========================================
Press Ctrl+C for quit

[0] vol_raw:500 vol:878.90 mV
[1] vol_raw:501 vol:880.66 mV
[2] vol_raw:500 vol:878.90 mV
^C
=== Statistics ===
Samples: 3
Raw   - min: 500  max: 501  avg: 500
Volt  - min: 878.90  max: 880.66  avg: 879.48 mV

Specify sample count and interval:

# ./adc_test.sh 3 -n 10 -i 0.5

Automatically stops after 10 samples with a 0.5-second interval, and outputs statistics upon completion.

Continuous Sampling Test

Continuous sampling mode achieves high-speed data acquisition through the IIO buffer, suitable for stress testing and signal analysis.

Specify sample count:

# ./adc_test.sh 3 -m continuous -n 100

Example output:

========================================
ADC Test Info
========================================
Channel     : 3
Mode        : continuous
IIO Device  : 34190000.adc
Scale       : 1.757812500
ADC Clock   : 9523810 Hz
ADC APB Clk : 200000000 Hz
Count       : 100
========================================
Press Ctrl+C for quit

[0] vol_raw:500 vol:878.90 mV
[1] vol_raw:501 vol:880.66 mV
[2] vol_raw:500 vol:878.90 mV
...
[99] vol_raw:500 vol:878.90 mV
=== Statistics ===
Samples: 100
Raw   - min: 498  max: 502  avg: 500
Volt  - min: 875.38  max: 882.42  avg: 878.90 mV

Infinite loop sampling (press Ctrl+C to stop and output statistics):

# ./adc_test.sh 3 -m continuous

Sampling continues until Ctrl+C is pressed, after which the IIO buffer is automatically disabled and statistics are output.

4.5.17.4. Test Criteria

Output Information

The test script prints ADC system information before sampling begins, including:

Field Description
Channel ADC channel number currently being tested
Mode Sampling mode (single / continuous)
IIO Device IIO device name
Scale Voltage scale factor (mV/LSB)
ADC Clock ADC main clock frequency
ADC APB Clk ADC APB clock frequency
Count Number of samples (infinite for continuous loop)
Interval Sampling interval (single mode only)

Statistics are output after sampling completes:

Field Description
Samples Actual number of samples collected
Raw min/max/avg Minimum, maximum, and average of raw values
Volt min/max/avg Minimum, maximum, and average of voltage values (mV)

Result Assessment

  1. Functional normal: The script can print sampling values and statistics normally, and the sampled values are within the expected range (calculated based on input voltage).

  2. Accuracy normal: The raw value fluctuation range (max - min) in the statistics should be small (typically ≤ 10 LSB), indicating stable ADC sampling.

  3. Error conditions:

    • If the script exits with an error (e.g., device file not found), check whether the driver is loaded correctly and the ADC node is enabled in the device tree.

    • If sampled values are consistently 0 or at full scale (1023), check whether the channel pin connections are correct and the input signal is within the measurement range.

    • If continuous sampling mode reports an error, check whether the IIO buffer and /dev/iio:device0 character device are available.