[STM32F4] stm32F407 ADC

[复制链接]
3314|40
 楼主| c17 发表于 2023-5-27 00:44 | 显示全部楼层 |阅读模式
ADC 介绍:

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


740136470e1d1bb4a7.png


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 | 显示全部楼层
输入通道 717846470e219e55e3.png
 楼主| 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)顺序。
693206470e2345052c.png
673976470e23ba33f6.png
 楼主| c17 发表于 2023-5-27 00:45 | 显示全部楼层
注入通道
270616470e2461a3bf.png
 楼主| 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
 楼主| 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

341126470e25b4ecea.png
 楼主| c17 发表于 2023-5-27 00:46 | 显示全部楼层
快速转换模式
858606470e2686a569.png
 楼主| 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
 楼主| c17 发表于 2023-5-27 00:46 | 显示全部楼层
采样率,决定了ADC能采集多大频率的信号
208256470e27c94607.png
 楼主| c17 发表于 2023-5-27 00:46 | 显示全部楼层
最短的转换时间: Tconv = 采样时间 + 12 个周期( 12)
PCLK2 = 84M, ADC_CLK = 84/4 = 21M
Tconv = 3+12 = 15周期 = 15/21us=0.71us
 楼主| c17 发表于 2023-5-27 00:47 | 显示全部楼层
转换方式
1、单次转换

842326470e290bc99b.png
 楼主| c17 发表于 2023-5-27 00:47 | 显示全部楼层
连续转换
143416470e29c098f4.png
 楼主| 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
 楼主| 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.
393006470e34b98c3c.png
 楼主| c17 发表于 2023-5-27 00:50 | 显示全部楼层
数据寄存器
一切准备就绪后, ADC 转换后的数据根据转换组的不同,规则组的数据放在ADC_DR 寄存器,注入组的数据放在 JDRx。 如果是使用双重或者三重模式那规矩组的数据是存放在通用规则寄存器 ADC_CDR 内的 448456470e35c2bb06.png
 楼主| c17 发表于 2023-5-27 00:50 | 显示全部楼层
 楼主| c17 发表于 2023-5-27 00:51 | 显示全部楼层
 楼主| c17 发表于 2023-5-27 00:51 | 显示全部楼层
模拟看门狗
模拟看门狗如何保护多个通道? 436366470e37f3c62b.png
 楼主| c17 发表于 2023-5-27 00:51 | 显示全部楼层
保证在多少范围内
您需要登录后才可以回帖 登录 | 注册

本版积分规则

c17

40

主题

312

帖子

1

粉丝
快速回复 在线客服 返回列表 返回顶部