Ⅰ, overview
The previous article covered the following: three-channel successive conversion (performs, single-channel software trigger), that is, 3 channels to three times the software trigger to complete the conversion, but also through the software to read the value of the conversion.
This paper describes the three-channel DMA continuous conversion (3-channel, software single-shot), that is, 3 channels need only one software trigger to complete the conversion, using DMA to save the value.
The previous article is an instance of a single-shot channel acquisition using a discontinuous mode , this article is a single-shot three channel acquisition using DMA mode . The advantage of using DMA transmission is that the efficiency is very high, we directly read the result of the conversion, such as want to do the oscilloscope instance is the requirement of high efficiency.
Example Experiment Effect:
The experimental effect of this article is the same as the previous article, but the way of implementation is different
Channel 1 ground, Channel 2 connect 1.5V power supply, channel 3 VCC
Previous article content:
ADC three-channel successive conversion (performs, single-channel software trigger)
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 the project is on the board after many tests and no problem before uploading to 360 cloud disk, Welcome to download test, reference learning.
Downloadable software engineering is based on the Keil (mdk-arm) V5 version, Stm32f103ze chip, but F1 other models also apply (applicable F1 Other models: attention, reply to "modified model").
STM32F10X_ADC three-channel DMA Continuous Conversion (3- channel, software single-shot ) Instance source code engineering:
Https://yunpan.cn/cBCmnZ58mI3Pp 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 (performs, single channel software trigger)" It is not difficult to understand the process of its transformation, but how to achieve it 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 every time the trigger is converted once.
4. Single channel : Only one channel is converted per trigger.
It is simple to explain its principle :
There are three channels Channel 1, Channel 2, Channel 3, respectively, corresponding order, 1, 2, 3. We define the order by software:
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);
So, we convert the saved order: Adc_buf[0] is the data of Channel 1, adc_buf[1] is the data of Channel 2, ADC_BUF[2] is the data of Channel 3
Also follow the above. Of course, you can also change the order.
Ⅴ, 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. DMA Configuration
The function is located under adc.c file;
1. Peripheral Address:dma_peripheralbaseaddr = (uint32_t) (& (ADC1->DR));
We use the ADC data register address as the peripheral address of the DMA;
2. memory address:dma_memorybaseaddr = (uint32_t) adc_buf;
Here is the address where we define an array of stored values;
3. Transmission direction:Dma_dir = dma_dir_peripheralsrc;
DMA_DIR_PERIPHERALSRC: Memory for Peripherals
DMA_DIR_PERIPHERALDST: Peripherals with memory
4. Transmission length:dma_buffersize = adc_buf_size;
Adc_buf_size is a macro definition, equal to 3, which means that we need to convert and save 3 sets of data (3 channel values).
5. Peripheral Address growth:dma_peripheralinc = dma_peripheralinc_disable;
Since the address of the peripheral is the ADC data register, there is no change, so there is no need to increase the address;
6. memory address growth:dma_memoryinc = dma_memoryinc_enable;
Since we have defined a number, we need to save 3 values, so we need to grow.
"Data can be cycled according to transmission length and cycle mode "
7. Peripheral Data length:dma_peripheraldatasize = Dma_peripheraldatasize_halfword;
Dma_peripheraldatasize_byte:8 bit data
Dma_peripheraldatasize_halfword:16 bit data
DMA_PERIPHERALDATASIZE_WORD:32 bit data
Since we use 16 bits of data, we use Dma_peripheraldatasize_halfword;
8. Memory Data length:dma_memorydatasize = Dma_memorydatasize_halfword;
Similar to " peripheral data length ";
9. Cycle mode:Dma_mode = dma_mode_circular;
The loop we're talking about here is that we collect 3 sets of data (more transmission length to determine).
Priority level:dma_priority = Dma_priority_veryhigh;
Priority should be clear to him, we only use a set of DMA this priority can be high and low;
Priority:dma_m2m = dma_m2m_disable;
Memory transfer to Memory: No
Note :
Why are we using DMA1_CHANNEL1?
We require the use of DMA channels and are required to follow the rules provided in the manual (e.g.), please refer to the manual:
3. ADC Configuration
The function is located under adc.c file;
This function is the focus of this article, the following in turn to explain the meaning of the source code content;
A. Initialize basic parameters:
operating mode: Adc_mode = adc_mode_independent;
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 1th, Channel 2 to 2nd, Channel 3 to 3rd;
C. Checksum:
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 is used to eliminate the error generated on each capacitor in subsequent conversions.
Ⅵ, 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 articles I will be 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 DMA continuous conversion (3-channel, software single-shot)