SSD_SAR Reference


1. Sar Overview

Successive approximation register (SAR) analog-to-digital converters (ADCs) are a common structure for medium to high resolution ADC applications with sampling rates below 5Msps. SAR ADCs typically have a resolution of 8-16 bits. It has the characteristics of low power consumption and small size.


2. Platform Overview

On the SSD20X platform, 3 SAR ports are provided (SSD203 has only 2 SAR ports), the precision is 10bit (the actual valid data is 8bit), and the corresponding pins are:

pin SAR MODE Channel Note
PAD_SAR_GPIO0 MDRV_PUSE_SAR_GPIO0 0
PAD_SAR_GPIO1 MDRV_PUSE_CPUFREQ_VID1 1 The usage of this pin has been specified by hardware to adjust Core Power
PAD_SAR_GPIO2 MDRV_PUSE_SAR_GPIO0 2 SSD203 is not a sar port

3. Platform Config Description

3.1. kernel Config

config: CONFIG_MS_SAR

The corresponding node will be generated: /dev/sar


3.2 padmux config


4. Use of SAR

4.1 SAR IOCTL parameter description

IOCTL Interface Parameter Description Description
IOCTL_SAR_INIT NULL Initialize
IOCTL_SAR_SET_CHANNEL_READ_VALUE typedef struct
Get adc value

4.2 Demo code

SAR_ADC_CONFIG_READ adcCfg;
adcCfg.channel_value = 0;            //Input parameter, note: PAD_SAR_GPIO0 = 0 PAD_SAR_GPIO1 = 1 PAD_SAR_GPIO2 = 2
int fd = open("/dev/sar", O_WRONLY);
if(fd == -1) {
        return -1;
}
if (ioctl(fd, IOCTL_SAR_INIT, NULL) < 0) {
        int err = errno;
        printf("\n!!! IOCTL_SAR_INIT FAILED, errno: %d, %s\n", err, strerror(err));
}
if (ioctl(fd, IOCTL_SAR_SET_CHANNEL_READ_VALUE, &adcCfg) < 0) {
        int err = errno;
        printf("\n!!! IOCTL_SAR_SET_CHANNEL_READ_VALUE FAILED, errno: %d, %s\n", err, strerror(err));
}
else {
        printf("SAR: get value %d", adcCfg.adc_value);

}


4.3 Conversion of obtained results

As shown in the figure below, the value obtained is 1023. As mentioned earlier, the sampling accuracy of the Sar port of the SSD20X platform is 10bit (that is, the total value is 2^10=1024, 3.3/1024=0.00322 V/point), and the total power supply is 3.3V, then here

The voltage corresponding to 1023 is: 1023/1024*3.3=3.29

Note: Although the platform sampling accuracy is 10bit, the actual effective value should be 8bit (2^8 = 256), sampling accuracy: 3.3/256 = 0.0129 V/point (that is to say, the value we get has the margin of error)