11. ADC Operation Guide

11.1. The Preparations of ADC Operation Are as Follow

  • Use the kernel released by SDK.

11.2. Operation Process

  • Insert module: cv180x, insmod cv180x_saradc.ko, cv181x, insmod cv181x_saradc.ko.

  • Run ADC read/write command under the console or write ADC read/write program in kernel space or user space to carry out input/output operation on ADC.

  • The user layer accesses the IIO interface to implement trigger and sampling operations of three-channel and 12-bit ADC.

  • 1.5v ref reference voltage.

11.3. Operation Example

11.3.1. ADC Operation Commands Example:

Step 1:

Specify ADC channels 1 to 6, in this example, ADC1:

(ADC channel 4 is dedicated to measuring VDDC_RTC; ADC channel 5 is PWR_GPIO1; ADC channel 6 is PWR_VBAT_

echo 1 > /sys/class/cvi-saradc/cvi-saradc0/device/cv_saradc

Step 2:

Read selected ADC channe

cat /sys/class/cvi-saradc/cvi-saradc0/device/cv_saradc

11.3.2. ADC Read-Write Operation Program Example with User Space

Step 1:

Configure the ADC channel number to be operated:

fd = open(/sys/class/cvi-saradc/cvi-saradc0/device/cv_saradc”, O_RDWR|O_NOCTTY|O_NDELAY));
If (fd < 0)
   printf("open adc err!\n");
write(fd, “1”, 1);

Step 2:

Read the ADC values:

char buffer[512];
int len = 0;
int adc_value = 0;

len = read(fd, buffer, 10);
if (len != 0) {
    adc_value= atoi(buffer);
    printf("adc value is %d\n", adc_alue);
}
close(fd);