Article From:https://www.cnblogs.com/yangxinrui/p/9969570.html

1.First is the basic knowledge of ADC.

Analog signal, continuous

Digital signal, discrete

Analog signals, many things in the real world are continuous, so the use of analog signals can accurately describe, but analog signals are inconvenient to control.

Digital signals, most of the signals in the computer are digital, and digital signals are easy to control accurately.

Therefore, for analog signals, the processing methods are as follows:

Sensors acquire analog signals from the real world and convert them into analog levels.

ADCInput analog level and convert it to digital level.

Programming digital level,

DACConvert digital level to analog level output.

2. There are several important features for ADC

（1）Range, indicating the effective voltage range of the AD converter

（2）Accuracy, such as progress of 10, indicates that ADC uses 10 bits to represent digital signals.

（3）MSPS，The number of samples converted per second, MSPS is positively correlated with ADC working frequency, n * working frequency = MSPS

（4）The number of channels, which indicates how many channels can be converted simultaneously by ADC converters

（5）Analog pin, SOC usually consists of two kinds of pins, digital pin and analog pin. Digital pin will process the level in the way of digital signal, and analog pin will process the level in the way of analog signal.

3.With the above basic knowledge, you can practice your code.

First look at the schematic

This indicates that the ADC channel number to be used is 0.

Then set it according to the SoC register description and the important attributes in ADC5 above.

```void adc_init()
{
rTSADCCON0     &= ~(1<<2);        // normal operation mode// accuracy
rTSADCCON0 |= (1 << 16);    // 10bit resolution

// passageway
rADCMUX &= ~(0xf << 0); // channel 0

// frequency
rTSADCCON0 |= (1 << 14);    // enable prescaler
rTSADCCON0 &= ~(0xff << 6) ;
rTSADCCON0 |= (19 << 6); // 3.3MHZ
}

static void delay()
{
volatile unsigned int i = 10000, j =10000;
for (;i > 0; i--)
for (; j > 0; j--);
}

{

while (1) {