打印
[STM32F4]

stm32F407 ADC

[复制链接]
490|40
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
c17|  楼主 | 2023-5-27 00:44 | 只看该作者 |只看大图 回帖奖励 |倒序浏览 |阅读模式
ADC 介绍:

1-三个独立的ADC 1 / 2 / 3
2-分辨率有12/10/8/6 位可选
3-每个ADC具有18个通道,其中外部通道16个



1:电压输入范围

输入电压: VREF- ≤ VIN ≤ VREF+

决定输入电压的引脚: VREF-、 VREF+ 、 VDDA 、 VSSA

VSSA 和 VREF-接地,把 VREF+和 VDDA 接 3V3,

得到ADC 的输入电压范围为: 0~3.3V。数据寄存器 ADC_DR 的满值为0xFFF:


每一刻度值为(3.3/4096),等到值为y=(3.3/4096*ADC_DR)。



使用特权

评论回复
沙发
c17|  楼主 | 2023-5-27 00:45 | 只看该作者
输入通道

使用特权

评论回复
板凳
c17|  楼主 | 2023-5-27 00:45 | 只看该作者
外部的 16 个通道在转换的时候又分为规则通道和注入通道,其中规则通道最多有 16路,注入通道最多有 4 路
规则通道: 顾名思意,规则通道就是很规矩的意思,我们平时一般使用的就是这个通道。
注入通道: 注入,可以理解为插入,插队的意思,是一种不安分的通道。它是一种在规则通道转换的时候强行插入要转换的一种。这点跟中断程序很像,都是不安分的主。所以,注入通道只有在规则通道存在时才会出现=

使用特权

评论回复
地板
c17|  楼主 | 2023-5-27 00:45 | 只看该作者
通道转换顺序
规则通道
一般要设置有多少个转换通道在寄存器ADC——SQR1 bit【21,23】

转换通道1优先级高

void ADC_RegularChannelConfig(ADC_TypeDef* ADCx, uint8_t ADC_Channel, uint8_t Rank, uint8_t ADC_SampleTime)

这函数就是在ADCX 的ADC_Channel 通道插入转换通道(Rank)顺序。

使用特权

评论回复
5
c17|  楼主 | 2023-5-27 00:45 | 只看该作者
注入通道

使用特权

评论回复
6
c17|  楼主 | 2023-5-27 00:46 | 只看该作者
触发源
1、软件触发: ADC_CR2 :

ADON/SWSTART/JSWSTART
2、外部事件触发: 内部定时器/外部IO
选择: ADC_CR2 :EXTSEL[2:0]和 JEXTSEL[2:0]
激活: ADC_CR2 :EXTEN 和 JEXTEN

使用特权

评论回复
7
c17|  楼主 | 2023-5-27 00:46 | 只看该作者
转换时间
转换时间: Tconv = 采样时间 + 12 个周期( 12位)
The ADC samples the input voltage for a number of ADCCLK cycles that can be modified
using the SMP[2:0] bits in the ADC_SMPR1 and ADC_SMPR2 registers. Each channel can
be sampled with a different sampling time.
The total conversion time is calculated as follows:
Tconv = Sampling time + 12 cycles
Example:
With ADCCLK = 30 MHz and sampling time = 3 cycles:
Tconv = 3 + 12 = 15 cycles = 0.5 μs with APB2 at 60 MHz

ADC_CLK: ADC模拟电路时钟,最大值为36M,由
PCLK2提供,还可分频, 2/4/6/8, ADC_CCR 的
ADCPRE[1:0]设置。 PCLK2=84M
有关ADC_CLK时钟的具体描述参考datasheet:5.3.21

使用特权

评论回复
8
c17|  楼主 | 2023-5-27 00:46 | 只看该作者
快速转换模式

使用特权

评论回复
9
c17|  楼主 | 2023-5-27 00:46 | 只看该作者
采样时间: ADC 需要若干个 ADC_CLK 周期完成对输入的
模拟量进行采样,采样的周期数可通过ADC 采样时间寄存器
ADC_SMPR1 和 ADC_SMPR2 中的 SMP[2:0]位设置,
ADC_SMPR2控制的是通道 0~9, ADC_SMPR1 控制的是通
道 10~17。每个通道可以分别用不同的时间采样。其中采样
周期最小是 3 个,即如果我们要达到最快的采样,那么应该
设置采样周期为 3 个周期,这里说的周期就是 1/ADC_CLK

使用特权

评论回复
10
c17|  楼主 | 2023-5-27 00:46 | 只看该作者
采样率,决定了ADC能采集多大频率的信号

使用特权

评论回复
11
c17|  楼主 | 2023-5-27 00:46 | 只看该作者
最短的转换时间: Tconv = 采样时间 + 12 个周期( 12)
PCLK2 = 84M, ADC_CLK = 84/4 = 21M
Tconv = 3+12 = 15周期 = 15/21us=0.71us

使用特权

评论回复
12
c17|  楼主 | 2023-5-27 00:47 | 只看该作者
转换方式
1、单次转换

使用特权

评论回复
13
c17|  楼主 | 2023-5-27 00:47 | 只看该作者
连续转换

使用特权

评论回复
14
c17|  楼主 | 2023-5-27 00:47 | 只看该作者
Bit 11 DISCEN: Discontinuous mode on regular channels
This bit is set and cleared by software to enable/disable Discontinuous mode on regular
channels.
0: Discontinuous mode on regular channels disabled
1: Discontinuous mode on regular channels enabled

Bits 15:13 DISCNUM[2:0]: Discontinuous mode channel count
These bits are written by software to define the number of regular channels to be converted
in discontinuous mode, after receiving an external trigger.
000: 1 channel
001: 2 channels
...
111: 8 channels

使用特权

评论回复
15
c17|  楼主 | 2023-5-27 00:50 | 只看该作者
扫描模式

This mode is used to scan a group of analog channels.
The Scan mode is selected by setting the SCAN bit in the ADC_CR1 register. Once this bit
has been set, the ADC scans all the channels selected in the ADC_SQRx registers (for
regular channels) or in the ADC_JSQR register (for injected channels). A single conversion
is performed for each channel of the group. After each end of conversion, the next channel
in the group is converted automatically. If the CONT bit is set, regular channel conversion
does not stop at the last selected channel in the group but continues again from the first
selected channel.
If the DMA bit is set, the direct memory access (DMA) controller is used to transfer the data
converted from the regular group of channels (stored in the ADC_DR register) to SRAM
after each regular channel conversion.
The EOC bit is set in the ADC_SR register:
• At the end of each regular group sequence if the EOCS bit is cleared to 0
• At the end of each regular channel conversion if the EOCS bit is set to 1
The data converted from an injected channel are always stored into the ADC_JDRx
registers.

使用特权

评论回复
16
c17|  楼主 | 2023-5-27 00:50 | 只看该作者
数据寄存器
一切准备就绪后, ADC 转换后的数据根据转换组的不同,规则组的数据放在ADC_DR 寄存器,注入组的数据放在 JDRx。 如果是使用双重或者三重模式那规矩组的数据是存放在通用规则寄存器 ADC_CDR 内的

使用特权

评论回复
17
c17|  楼主 | 2023-5-27 00:50 | 只看该作者

使用特权

评论回复
18
c17|  楼主 | 2023-5-27 00:51 | 只看该作者
中断

使用特权

评论回复
19
c17|  楼主 | 2023-5-27 00:51 | 只看该作者
模拟看门狗
模拟看门狗如何保护多个通道?

使用特权

评论回复
20
c17|  楼主 | 2023-5-27 00:51 | 只看该作者
保证在多少范围内

使用特权

评论回复
发新帖 我要提问
您需要登录后才可以回帖 登录 | 注册

本版积分规则

c17

31

主题

272

帖子

1

粉丝