Analog-to-digital converter ADC

Publisher:幸福的21号Latest update time:2020-04-21 Source: eefocus Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

6.1 ADC structure and register description

The main function of the analog-to-digital converter (ADC) is to convert analog signals into digital signals for data processing by the microcontroller.

ADC is divided into successive comparison type, double integration type and ∑-∆ type according to the conversion principle.

The successive approximation ADC converts analog signals into digital signals through successive comparisons. It has a fast conversion speed but low accuracy and is the most commonly used ADC.


The dual-integral ADC converts analog signals into digital signals by integrating twice. It has high accuracy and strong anti-interference ability, but it is slow. It is mainly used in measuring instruments such as multimeters.


∑-∆ ADC has the dual advantages of successive approximation and dual integration, and is gradually being widely used.


The STM32ADC is a 12-bit successive comparator with up to 18 channels. It can measure 16 external and 2 internal signal sources. The conversion of each channel can be performed in word, continuous, scan or discontinuous mode. The conversion result can be stored in a 16-bit data register in left-aligned or right-aligned mode.


The STM32ADC analog watchdog feature allows the application to detect if the input voltage exceeds the user-defined high/low thresholds

The input clock must not exceed 14MHz and is generated by dividing PCLK2


The STM32ADC is mainly composed of analog multiplexers, analog-to-digital converters, data registers, and trigger selection.

The conversion channels are divided into two groups: regular channels and injection channels.


Regular channels consist of up to 16 channels, converted in sequence

The injection channel consists of up to 4 channels, which can be inserted into the conversion

GPIO pins used by ADC

Channel 16 of ADC1 is internally connected to the temperature sensor

Channel 17 is internally connected to the reference power supply VREFINT


The ADC operates through 20 registers

 

6.2 ADC Design Example

    6.2.1 Using ADC1 regular channel to realize analog-to-digital conversion of external analog signals

Registers and their contents related to regular channels

ADC regular channel initialization subroutine

//ADC1 initialization subroutine

 

void Adc1_Init(void)

{

    RCC->APB2ENR |= 1<<3; //Turn on GPIOB clock

 

    RCC->APB2ENR |= 1<<9; //Turn on ADC1 clock

 

    GPIOB->CRL &=0xffffff00; //PB.01 (IN9), PB.00 (IN8) analog input

 

    ADC1->CR1 |= 1<<8; //Scan mode

 

    ADC1->CR2 |= 1<<20; //Regular channel external trigger: TIM1_CH1

 

    ADC1->SQR1 |= 1<<20; //Regular channel sequence length: 2

 

    ADC1->SQR3 |= 9; //1st conversion channel: IN9

 

    ADC1->SQR3 |= 8<<5; //2nd conversion channel: IN8

 

    ADC1->CR2 |= 1; //Turn on ADC

 

    ADC1->CR2 |= 1<<2; //Calibrate ADC

 

    while(ADC1->CR2 & 1<<2); //Wait for calibration to complete

}

ADC regular channel processing subroutine

//ADC1 processing subroutine

 

void Adc1_Proc(void)

{

    if(ADC1->SR & 2) //EOC=1 (conversion ends)

    {    

        adc1_dat[adc1_num] = ADC1->DR; //Read conversion value

 

        if(++adc1_num == 2)

            adc1_num = 0;

    }

}

 

6.2.2 Using ADC1 injection channel to measure the temperature of the internal temperature sensor

There is a temperature sensor in STM32, which is connected to channel 16 of ADC1 and can be used to measure the temperature of the chip

The maximum sampling time of the temperature sensor is 17.1ms, the temperature range is -40~125°C, and the temperature calculation formula is as follows:

             

Where: V is the voltage value of the temperature sensor, N is the digital value after analog-to-digital conversion


Injection channel related registers and their contents

ADC injection channel initialization subroutine

//ADC1 initialization subroutine

 

void Adc1_Init(void)

{

    RCC->APB2ENR |= 1<<3; //Turn on GPIOB clock

 

    RCC->APB2ENR |= 1<<9; //Turn on ADC1 clock

 

    GPIOB->CRL &=0xffffff00; //PB.01 (IN9), PB.00 (IN8) analog input

 

    ADC1->CR1 |= 1<<8; //Scan mode

 

    ADC1->CR2 |= 1<<20; //Regular channel external trigger: TIM1_CH1

 

    ADC1->SQR1 |= 1<<20; //Regular channel sequence length: 2

 

    ADC1->SQR3 |= 9; //1st conversion channel: IN9

 

    ADC1->SQR3 |= 8<<5; //2nd conversion channel: IN8

 

    ADC1->CR2 |= 1<<10; //Injection channel automatic conversion

 

    ADC1->CR2 |= 1<<23; //Turn on the temperature sensor

 

    ADC1->SMPR1 |= 5<<18; //SMP16[2:0] =5(55.5)

                                        // (55.5+12.5)/4MHz=17s

 

    ADC1->JSQR |= 0x10<<15; //JSRR[4:0]=0x10 (channel 16)

 

    ADC1->CR2 |= 1; //Turn on ADC

 

    ADC1->CR2 |= 1<<2; //Calibrate ADC

 

    while(ADC1->CR2 & 1<<2); //Wait for calibration to complete

}

ADC injection channel processing subroutine

//ADC1 processing subroutine

 

void Adc1_Proc(void)

{

    if(ADC1->SR & 2) //EOC=1 (conversion ends)

    {    

        adc1_dat[adc1_num] = ADC1->DR; //Read conversion value

 

        if(++adc1_num == 2)

            adc1_num = 0;

    }

 

    if(ADC1->SR & 4) //JEOC=1 (injection channel conversion ends)

    {

        ADC1->SR &= ~6; //Clear JEOC and EOC

 

        adc1_jdat = ADC1->JDR1; //Read conversion value

    }

}

Reference address:Analog-to-digital converter ADC

Previous article:51 MCU: Use ADC0832 to do analog-to-digital conversion and measure voltage
Next article:51 MCU Notes

Recommended ReadingLatest update time:2024-11-22 20:30

STM32ADC conversion interrupt read
The ADC interrupt reading method is suitable for low-frequency ADC acquisition, while high-frequency AD acquisition must use DMA. The initialization function of ADC interrupt reading only adds an interrupt configuration file compared to the direct reading method in the previous article. The code is as follows: static
[Microcontroller]
STM32F4 study notes 13——ADC part1
ADC Introduction  The 12-bit ADC is a successive approximation analog-to-digital converter. It has up to 19 multiplexed channels that can measure signals from 16 external sources, two internal sources, and the VBAT channel. The A/D conversion of these channels can be performed in single, continuous, scan, or discontin
[Microcontroller]
STM32F4 study notes 13——ADC part1
ADC0809 made 51 single chip microcomputer 8-channel voltage acquisition
#include "reg52.h" float  shuju; unsigned char sj; unsigned int gata; unsigned char gw,sw,bw; unsigned char kk,tdao; //4-link common anode digital tube, the highest bit shows the channel number, the other three bits are voltage values ​​unsigned char code shuzi ={                                              
[Microcontroller]
Design of Precision Electronic Weigh Scale Using AD7192 24-bit Σ-Δ ADC with Built-in PGA
       Circuit Function and Advantages   This circuit is a weigh scale system built using the AD7192. The AD7192 is an ultralow noise, low drift, 24-bit Σ-Δ converter with an internal PGA. The device simplifies weigh scale design by having most of the system building blocks on chip. The device operates over the fu
[Power Management]
Design of Precision Electronic Weigh Scale Using AD7192 24-bit Σ-Δ ADC with Built-in PGA
How to use ADC in ARM7-LPC2148
In the electronics world, there are a variety of analog sensors available in the market for measuring temperature, speed, displacement, pressure, etc. Analog sensors are used to produce an output that changes over time. These signals from analog sensors tend to be small in value, from a few microvolts (uV) to a few mi
[Microcontroller]
How to use ADC in ARM7-LPC2148
ADC Application Elements in C8051F020
F020 has 8-channel 12-bit A/D conversion (ADC) interface and 8-channel 8-bit online programmable (ISP) ADC circuit. There are 15 special function registers (SFR) on the chip related to ADC control, which are: AMUX0SL——AMUX0 channel selection register, the reset value is 00000000; MAX0CF——AMUX0 configuration regist
[Microcontroller]
ARM9(S3C2440) ADC
Analog signal/digital signal (1) An analog signal is a physical quantity that is continuous in time and value, and has an infinite number of values. Most physical quantities perceived from nature are analog in nature, such as speed, pressure, temperature, sound, etc. (2) Digital signals are discrete in both time a
[Microcontroller]
Low-power ADCs are not limited to portable applications
It would be simplistic to think that there is only one dominant “trend” in the complex and ever-changing world of analog, but some trends are more obvious than others. For example, for analog-to-digital converters (ADCs), the “low power” trend is stronger than almost all the resolution and speed trends.
[Power Management]
Latest Microcontroller Articles
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号