File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ ---
2+ title : ADC
3+ ---
4+
5+ ADC ,即analog to digital converter(模数转换器)是一种非常常见的外设,用于将电压等模拟信号转换为数字形式,以便微控制器可以读取和处理。
6+
7+ ADC 在控制和监控应用中非常有用,因为大多数传感器(例如温度、压力、力)都会产生模拟输出电压。
8+
9+ ::: note
10+ 每个 MCU 或模块都有不同数量的 ADC,以及不同数量的可用通道和引脚。有关详细信息,请参阅每个板的数据手册。
11+ :::
12+
13+ ## ADC 通用 API
14+
15+ ### analogRead
16+
17+ 此函数用于获取给定引脚/ADC 通道的 ADC 原始值。
18+
19+ ``` cpp
20+ uint32_t analogRead (uint32_t pin);
21+ ```
22+
23+ - `pin` GPIO 引脚或 ADC 通道。
24+ - - ADC的内部通道可以为`ATEMP` (内部温度传感器)、`AVBAT` (VBAT电压)、`AREF` (内部参考电压)。
25+
26+ 该函数将返回模拟原始值。
27+
28+ 读取内部通道时需要最小 ADC 采样时间,因此默认将其设置为最大可能值。它可以通过定义更精确地定义:
29+
30+ - `ADC_SAMPLINGTIME_INTERNAL` 到所需的 ADC 采样时间。
31+
32+ `ADC_SAMPLINGTIME` 和 `ADC_CLOCK_DIV` 也可以通过变体或使用 build_opt.h 重新定义。
33+
34+ ### analogReference
35+
36+ 配置模拟输入所用的基准电压(即用作输入范围上限的值)。保留此功能只是为了与现有的基于 AVR 的 API 兼容。
37+
38+ ```cpp
39+ void analogReference(eAnalogReference ulMode) ;
40+ ```
41+
42+ ## AirMCU 专用 API
43+
44+ ### analogReadResolution
45+
46+ 此函数用于设置 ADC 读取的分辨率。默认为 10 位(范围为 0 至 1023)。
47+
48+ ``` cpp
49+ void analogReadResolution (uint8_t bits);
50+ ```
You can’t perform that action at this time.
0 commit comments