ADC overview

The ADC subsystem consists of a signal multiplexer and a voltage analog-to-digital converter (VADC). It routes internal and external analog signals to the VADC through a multiplexed architecture and converts them into digital values.

ADC module hardware architecture

Supported ADC channels

The module supports the following ADC channels:

Interface Pin no. Pin name PM4250 pin no. Voltage domain MPM interrupt Pin description
ADC 128 ADC0 GPIO4 1.8 V - PMU_GPIO04
ADC 185 ADC1 GPIO7 1.8 V - PMU_GPIO07

ADC interface location

The location of the ADC interface on the smart main control board is shown below:

ADC location on the smart single-board computer

ADC interface location on the smart main control board

ADC node usage example

The ADC nodes are mainly used to read the ADC values at the corresponding input nodes.

Usage method

For testing: use an adjustable DC power supply as the input signal source:

  • Connect the positive terminal of the power supply to the ADC0 or ADC1 pin.
  • Connect the power supply ground (GND) to the GND of the smart main control board.

Channel mapping and input characteristics are as follows:

  • ADC0:
    • Mapped to GPIO4
    • Corresponding node: in_voltage_adc_gpio4_input
    • Supported input voltage range: Approximately 0–5.25 V.
  • ADC1:
    • Mapped to GPIO7
    • Corresponding node: in_voltage_adc_gpio7_input
    • supported input voltage range: Approximately 0–5.25 V.

After setting the DC power supply to the desired voltage, the ADC sampling result can be read using the following commands (unit: μV):

adb shell
cd /sys/bus/iio/devices/iio:device0
cat in_voltage_adc_gpio4_input
cat in_voltage_adc_gpio7_input
Example of ADC read output

Example of ADC read output

Sample test code

The following sample code demonstrates how to read the ADC value in an application. It opens the ADC node file, reads the raw ADC value (in μV), and converts it to an integer for further processing.

Click to expand/collapse: ADC read test code (can be compiled with NDK)
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <fcntl.h>
#include <string.h>
#include <errno.h>

int main() 
{ 
    int fd = -1; 
    int adc_value; 
    char buff[64] = {0}; 

    // Open the ADC node file (ADC0 corresponds to GPIO4)
    fd = open("/sys/bus/iio/devices/iio:device0/in_voltage_adc_gpio4_input", O_RDONLY);   
    if(fd < 0){ 
        perror("open error\n"); 
        return fd; 
    } 

    // Read the ADC value
    int n_read = read(fd, buff, sizeof(buff)); 
    if(n_read < 0) {
        perror("read error\n");
        close(fd);
        return -1;
    }

    // Convert the read string to an integer value (unit: μV)
    adc_value = atol(buff); 
    printf("read %d bytes, content: %s\n", n_read, buff); 
    printf("ADC value: %d μV\n", adc_value);   

    close(fd); 
    return 0; 
}

Code description:

  • Uses the open() function to open the ADC node file /sys/bus/iio/devices/iio:device0/in_voltage_adc_gpio4_input.
  • Uses the read() function to read the raw ADC value (string format, unit: μV).
  • Uses the atol() function to convert the string to a long integer.
  • The read ADC value is in microvolts (μV) and can be converted to a voltage value as needed.

Compilation and execution:

# Compile with NDK
# Push the compiled executable to the device and run it
adb push test_adc /data/local/tmp/test_adc
adb shell "chmod +x /data/local/tmp/test_adc"
adb shell "/data/local/tmp/test_adc"

Test data

ADC pin specifications

The ADC pins on the module are defined as follows:

Interface Module pin no. Module pin name Module I/O NET name (alternate function) Description
ADC 128 ADC0 I ADC0 1) Connector input voltage range: 0–5.25 V.
2) Divider resistors: RH = 18 kΩ, RL = 10 kΩ.
3) Voltage on ADC pin = connector input voltage (J0403) × (10/28).
4) Example: for an input of 3 V, the ADC pin voltage should be 3 V × 10/28 ≈ 1.0714 V.
ADC 185 ADC1 I ADC1 Same electrical characteristics as ADC0 (0–5.25 V input range, RH = 18 kΩ, RL = 10 kΩ, ADC pin voltage = Vin × 10/28).

ADC0 test data

Voltage source ADC0 (μV) Theoretical value (V)
1.8 V 638408 1.8 V×10/28 = 0.642857
3 V 1066414 3 V×10/28 = 1.07143
5 V 1784623 5 V×10/28 = 1.78571

ADC1 test data

Voltage source ADC1 (μV) Theoretical value (V)
1.8 V 640549 1.8 V×10/28 = 0.642857
3 V 1069269 3 V×10/28 = 1.07143
5 V 1789814 5 V×10/28 = 1.78571