Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What is STM32 ADC?

2025-02-22 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/01 Report--

This article is to share with you about what STM32 ADC is. The editor thinks it is very practical, so share it with you as a reference and follow the editor to have a look.

01. Introduction to ADC

ADC is the abbreviation of Analog-to-DigitalConverter. Finger / digital converter or analog / digital converter. It refers to the device that converts the analog signal of continuous variable into discrete digital signal. A typical analog-to-digital converter converts an analog signal into a digital signal that represents a certain proportion of voltage.

As can be seen from the following figure in the STM32F207 data manual, STM32F207VC has 3 12bit precision ADC controllers and 16 external channels, while the 144pin STM32F207Zx and 176pin STM32F207Ix have 8 more channels and 24 external channels because they have PF feet. The ADC D conversion of each channel can be performed single, continuously, scanned or intermittently, and the results of the ACMD conversion can be left-aligned or right-aligned and stored in a 16-bit data register.

02. ADC peripherals of STM32

As mentioned above, STM32F207 has three ADC controllers for 12bit, which will be explained in channel 10 of ADC3 below.

First of all, let's confirm the address bus where the ADC peripherals are located. From the following figure in the STM32F207 data manual, we can see that ADC belongs to the APB2 bus, and the APB2 clock frequency is 60MHz. For a specific STM32, if you get the APB2 of 60MHz through an external 25m crystal oscillator, please see "STM32F207 clock system Analysis".

For GPIO, we can see from the STM32F207 data manual that we can use PC0 as channel 10 for ADC3.

It should be noted here that when the previous article uses other peripherals, such as "STM32PWM output", when looking for the corresponding pin, we all look for it from the Alternatefunctionmapping table in the STM32F207 data manual, this is because the ADC corresponding pin uses the Additionalfunctions,PWM corresponding pin uses Alternatefunctions.

The difference is:

Additionalfunctions: additional, auxiliary functions, pins are connected to other modules for use, and can be directly configured in general configuration. For example, ADC uses an input channel and is configured for analog input.

Alternate functions: multiplexing function, that is, the IO port is used as a function other than ordinary input and output, such as serial input and output, and the reuse mode needs to be configured when it is used.

The following is described in the previous article "detailed explanation of STM32GPIO".

The following code is found in the STM32 standard peripheral library

Typedef enum {GPIO_Mode_IN = 0x00, / *! < GPIO Input Mode * / GPIO_Mode_OUT = 0x01, / *! < GPIO Output Mode * / GPIO_Mode_AF = 0x02, / *! < GPIO Alternate function Mode * / GPIO_Mode_AN = 0x03 / *! < GPIO Analog Mode * /} GPIOMode_TypeDef

GPIO_Mode_AF corresponds to Alternate functions: reuse function, and GPIO_Mode_AN corresponds to Additional functions: additional, auxiliary functions.

03. Explanation of STM32ADC block diagram

The following figure is the structural block diagram of STM32ADC, which is divided into seven parts to explain.

1. Input voltage range

The voltage range that ADC can measure is that VREF- ≤ VIN ≤ VREF+, ground VSSA and VREF-, connect VREF+ and VDDA to 3V3, and get the input voltage range of ADC: 0mm 3.3V.

2. Input channel

The signal of ADC enters the interior of the single-chip microcomputer through the input channel, and the single-chip microcomputer converts the analog signal into digital signal through the ADC module. The section marked ② above shows the 16 external channels, the connected GPIO, and the corresponding relationship, as explained above, needs to be found in the STM32F20xpin and ball definitions table of the STM32F207 data manual. In fact, the STM32 has an internal channel, channel 16 of the ADC1 is connected to the temperature sensor inside the chip, and the Vrefint is connected to channel 17. ADC2's analog channels 16 and 17 are connected to the internal VSS.

3. Conversion channel

During the conversion, the 16 external channels are divided into regular channels and injection channels, of which there are up to 16 regular channels and 4 injection channels at most (not many injection channels seem to be used). Here is a brief description of the two channels:

Regular channel

Regular channel, as its name implies, is the most common channel and the most commonly used channel, and the usual ADC transformations are implemented with regular channels. The rule channel and its conversion order are selected in the ADC_SQRx register, and the total number of rule group translations should be written to L [3:0] in the ADC_SQR1 register.

Injection channel

The injection channel is relative to the regular channel, and the injection channel can forcibly insert the transformation when the regular channel is converted, which is equivalent to an "interrupt channel". When there is an injection channel that needs to be converted, the conversion of the regular channel will be stopped, the conversion of the injection channel will be performed first, and when the conversion of the injection channel is completed, it will go back to the previous regular channel for conversion. Up to 4 channels, the injection group and its conversion order are selected in the ADC_JSQR register. The total number of conversions in the injection group should be written to L [1:0] in the ADC_JSQR register.

An ADC controller has multiple channels, which involves the use of multiple channels for conversion involves a sequence problem, after all, the regular conversion channel has only one data register. The use order of multiple channels can be divided into two cases: the conversion order of regular channels and the conversion order of injection channels.

Regular channel conversion order

The conversion order in the regular channel is controlled by three registers: SQR1, SQR2, and SQR3, which are all 32-bit registers. The SQR register controls the number of conversion channels and the conversion order. As long as the corresponding channel is written in the corresponding register bit SQx, this channel is the xth conversion. The realization of the conversion order on the register can be understood through the SQR1 register.

Injection channel conversion sequence

Like the control of the regular channel conversion order, the conversion of the injection channel is also controlled by the injection register, but only by one JSQR register. The control relationship is as follows:

It is important to note that only when JL=4 is used, the conversion order of the injection channels is performed in the order of JSQ1, JSQ2, JSQ3, and JSQ4. When JL

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report