STM32F10X_ADC three-channel successive conversion (performs, single-channel software trigger)

Source: Internet
Author: User

Ⅰ, overview

This article describes the more powerful ADC modules for the STM32 feature. ADC (Analog to Digital Converter) is analog to digital, and STM32 ADC module function is more, this article mainly describes " three channels successive conversion (performs, single channel Software Trigger)".

According to the author's experience, STM32 all series of Chip ADC module function and configuration are similar. Therefore, although this article is taking F1 as an example, in fact the other series (F0, F2, F4, etc.) are applicable.

This article provides example code: three channels, configured as a successive conversion (interval mode), applicable software trigger conversion (one channel per trigger), a cycle that requires software to trigger three times.

Example Experiment Effect:

Channel 1 ground, Channel 2 connect 1.5V power supply, channel 3 VCC


This article tells relatively more knowledge points, if the first learning STM32 ADC conversion function, you can refer to my other relatively simple article: STM32F10X_ADC1 single-channel single -Pass acquisition

For more details on this article, please look down.

Ⅱ, Case Engineering download

The author for beginners to provide routines are removed a lot of unnecessary features, streamlining the official code, for beginners to understand, a simple and clear engineering for everyone to learn.

I provide examples of projects are on the board after many tests and no problem before uploading to The cloud disk, welcome to download testing, reference learning.

Software engineering for download is based on the Keil(mdk-arm)V5 version,Stm32f103ze chip, but F1 Other models are also available (for F1 Other models: attention, reply to "modified model").

STM32F10X_ADC Three-channel successive conversion (single- pass , single-channel software trigger ) Instance source code engineering:

Https://yunpan.cn/cBNcrax8UHhmE access password

STM32F1 Information:

https://yunpan.cn/crBUdUGdYKam2 access password ca90

Ⅲ, about ADC

For an introduction and function of the ADC, please download the reference manual to see the author here to tell a few important facts:

1.12-Bit resolution

Only a few of the STM32 in all series of chips are 16 bits, such as: F373 chip.

The 12-bit resolution means that the accuracy of our acquisition voltage can be achieved: vref/4096.

Acquisition voltage = Vref * adc_dr/4096;

Vref: Reference voltage

ADC_DR: Read the value of the ADC data register

Since the register is 32-bit, left-aligned and Right-aligned at the time of configuration, we generally use right-justified, that is, the low 12-bit data is valid data.

2. Conversion Mode

A. Single and continuous conversions

Single: single-channel single conversion, multi-channel single-Pass (multiple) conversion;

Continuous: Single channel continuous conversion, multi-channel continuous (cycle) conversion;

B. Dual ADC Mode

That is, the use of two ADCs, such as: ADC1 and ADC2 simultaneously using the dual ADC mode. In this mode, you can configure the following modes: Synchronization rule mode, Synchronous injection mode, standalone mode, and so on.

3. Trigger Source

Trigger source is the source of triggering ADC conversion, with external interrupt line, timer, software and other trigger sources. We beginners commonly used software trigger, that is, need to convert once, our software started once (this article provides an example is also software trigger).

Ⅳ, examples of this article describe

The configuration and knowledge points of ADC parts in this example are relatively more and more difficult to understand for beginners.

According to the topic "ADC three-channel successive conversion (single- pass , single-channel software trigger )" We are not difficult to understand the process of its transformation, But how to achieve is a difficult point.

1, three channels : We define 3 channels ADC1 adc_channel_1, adc_channel_2, Adc_channel_3.

2. Successive conversions : We are using discontinuous mode (rule group), that is, the sequence that triggers the conversion is defined in the rule group.

3. single-shot : We are not triggering a conversion once.

4. single channel : Only one channel is converted per trigger.

Ⅴ, source code Analysis

The author uses the F1 Standard Peripheral Library (also suggests that beginners use the official Standard Peripheral Library) as the foundation of the project, mainly in the library way to tell (if your F1 chip and the provision of the project is not the same, you can reply to the "modified model").

The important points of the ADC are described below:

1. Input PIN configuration


The function is located under the adc.c file;

For pin-to-channel correspondence, please refer to your data sheet using the chip.


Attention:

Why is "adc123_in1"? Instead of adc1_in1, or adc2_in1?

The reason is that ADC1, ADC2, and ADC3 share these pins.

2. ADC configuration


The function is located under the rtc.c file;

This function is the focus of this paper, which is the focus of configuration work mode, rule channel and discontinuous mode. The following in turn tells the meaning of the source code content;

A. Initialize the basic parameters:

operating mode: Adc_mode = Adc_mode_regsimult;

There are a total of 10, mainly for the use of dual ADC. For beginners Here is not much description, interested friends can first study the use of each mode.

Browse mode : Adc_scanconvmode = ENABLE;

Mainly for multiple channels, that is to say, you have multiple channels.

Multi-channel: ENABLE;

Single channel: DISABLE;

Conversion Mode : Adc_continuousconvmode = DISABLE;

Here is whether the configuration requires continuous conversion.

Continuous conversion enable: that is, only need to start (trigger) the conversion once, and then do not have to start (trigger) to work continuously.

Single conversion Disable: that is, you need to start (trigger) again to work once the conversion is complete.

trigger mode : Adc_externaltrigconv = Adc_externaltrigconv_none;

The trigger is the method used to trigger the ADC conversion. Yo timer, external trigger, software trigger, common software trigger. There are a number of triggering methods, and the details can be referenced by their parameters.

to its way : Adc_dataalign = adc_dataalign_right;

Right: The low 12-bit data is a valid bit (commonly used);

Left to it: High 12 for data as a valid bit;

number of channels :adc_nbrofchannel = 3;

This parameter is relatively simple and we define the number of channels to work on.

B. Set the Rule group channel:

Adc_regularchannelconfig (ADC1, Adc_channel_1, 1, adc_sampletime_55cycles5);

Adc_regularchannelconfig (ADC1, adc_channel_2, 2, ADC_SAMPLETIME_55CYCLES5);

Adc_regularchannelconfig (ADC1, Adc_channel_3, 3, ADC_SAMPLETIME_55CYCLES5);

We define the conversion sequence for Channel 1 to 1, Channel 2 for the conversion sequence of 2, Channel 3 for the conversion sequence of 3;

Adc_discmodechannelcountconfig (ADC1, 1);

Adc_discmodecmd (ADC1, ENABLE);

Rule group discontinuous mode configuration. We configure a short sequence of 1, which means that each trigger converts one channel at a time.

See the reference Manual for discontinuous mode .


C. Check:

Adc_resetcalibration (ADC1); Check Reset

while (Adc_getresetcalibrationstatus (ADC1)); wait for reset to complete

Adc_startcalibration (ADC1); start ADC1 Calibration

while (Adc_getcalibrationstatus (ADC1)); wait for verification to complete

It is recommended that each power-up correction be made.

The ADC has a built-in self-calibration mode. Calibration can significantly reduce the accuracy error due to changes in the internal capacitor banks. During calibration, an error correction code ( numeric value )is calculated on each capacitor, which isused to eliminate the error generated on each capacitor in subsequent conversions.

3. ADC Acquisition


The function is located under the adc.c file;

When the above configuration is complete, it is the process of actually collecting the data. Since we are configuring the browse (loop) mode, a single acquisition, that is, we do not call to trigger the function once, we will loop to collect a channel.

Ⅵ, description

About STM32 ADC Conversion This piece of function is really strong also relatively complex, perhaps the text is not clear enough, if there is unclear can pay attention to the message.

About the author provides the software engineering example, may pay attention, in the Session box reply "About the project", has about the engineering structure description, the model revision and so on.

The above summary is for reference only, if has the wrong place, please understanding.

Ⅶ, last

More wonderful articles I said the first time in the public number to share, the article has any questions to leave a message.

Based on the principle of free sharing, it is convenient for us to learn knowledge and share technical knowledge on the platform regularly. If you feel that the content you share is useful to you, and you want to learn more about the relevant articles, please use the search "embedddeveloper" or scan the QR code below, attention, there will be more exciting content waiting for you.



STM32F10X_ADC three-channel successive conversion (performs, single-channel software trigger)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.