<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>ADC on 吾思 梦阁</title><link>https://wstek.win/tags/adc/</link><description>Recent content from 吾思 梦阁</description><generator>Hugo</generator><language>zh-cn</language><managingEditor>wusitech@qq.com (WuSi09)</managingEditor><webMaster>wusitech@qq.com (WuSi09)</webMaster><copyright>本博客所有文章除特别声明外，均采用 BY-NC-SA 许可协议。转载请注明出处！</copyright><lastBuildDate>Fri, 06 Nov 2026 23:45:00 +0800</lastBuildDate><atom:link href="https://wstek.win/tags/adc/index.xml" rel="self" type="application/rss+xml"/><item><title>STM32 DMA：从存储器映射到多通道采集与双缓冲</title><link>https://wstek.win/posts/stm32-dma/</link><pubDate>Sat, 31 Oct 2026 19:30:00 +0800</pubDate><author>wusitech@qq.com (WuSi09)</author><guid>https://wstek.win/posts/stm32-dma/</guid><description>
<![CDATA[<h1>STM32 DMA：从存储器映射到多通道采集与双缓冲</h1><p>作者：WuSi09（wusitech@qq.com）</p>
        
          <p>总结自：<a href="https://www.bilibili.com/video/BV1th411z7sn">STM32入门教程-2023版</a> 第 8 章（8-1、8-2）。</p>
<p>代码基于 <strong>STM32F103C8T6 + STM32F10x 标准外设库 3.5.0</strong>（API 已按 STM32F10x StdPeriph 3.5 头文件核对；Delay/OLED/Key 为课程配套驱动），不包含新建工程和接线步骤。</p>
<table>
  <thead>
      <tr>
          <th>视频</th>
          <th>视频里讲了什么</th>
          <th>本文对应</th>
      </tr>
  </thead>
  <tbody>
      <tr>
          <td>8-1</td>
          <td>DMA 简介、存储器映像、DMA 框图、基本结构、DMA 请求、数据转运、ADC 扫描 + DMA</td>
          <td>0x00 ~ 0x30</td>
      </tr>
      <tr>
          <td>8-2</td>
          <td>数据转运、DMA + AD 多通道（代码）</td>
          <td>0x41、0x42</td>
      </tr>
  </tbody>
</table>
<p>视频之外还补了：通道映射全表、带宽估算、数据一致性、USART 发送 DMA、半传输双缓冲、定时器触发采集、10 条故障排查。</p>
<h2 id="0x00-为什么需要-dma">
<a class="header-anchor" href="#0x00-%e4%b8%ba%e4%bb%80%e4%b9%88%e9%9c%80%e8%a6%81-dma"></a>
0x00 为什么需要 DMA
</h2><p>先算一笔账。用 CPU 轮询搬数据，每搬一个 16 位数据大约要：</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-text" data-lang="text"><span class="line"><span class="cl">读外设寄存器 → 写内存 → 判断标志 → 循环
</span></span></code></pre></div><p>按 10 条指令、72 MHz、平均 2 周期/指令估算，一个数据约 0.28 µs，也就是 CPU 最多每秒搬 350 万个点。听起来不少，但：</p>
<ul>
<li>ADC 四通道、每通道 10 kHz，就是 4 万点/秒；</li>
<li>串口 115200 波特率，满速约 11.5 KB/s；</li>
<li>一块 SPI 屏刷一帧 320×240×2 B = 150 KB，按 10 MHz SPI 约 15 ms，CPU 如果一边搬一边算，帧率立刻掉。</li>
</ul>
<p>这些“搬砖”活不需要运算，却占着 CPU 和总线。DMA（Direct Memory Access）就是把这些活接过去：<strong>外设和存储器之间、存储器和存储器之间，由 DMA 控制器直接搬，CPU 只配置和收尾</strong>。</p>
        
        <hr><p>本文2026-10-31首发于<a href='https://wstek.win/'>吾思 梦阁</a>，最后修改于2026-11-06</p>]]></description><category>STM32</category></item><item><title>STM32 ADC：从逐次逼近到单通道、多通道与 DMA 采集</title><link>https://wstek.win/posts/stm32-adc/</link><pubDate>Fri, 30 Oct 2026 19:30:00 +0800</pubDate><author>wusitech@qq.com (WuSi09)</author><guid>https://wstek.win/posts/stm32-adc/</guid><description>
<![CDATA[<h1>STM32 ADC：从逐次逼近到单通道、多通道与 DMA 采集</h1><p>作者：WuSi09（wusitech@qq.com）</p>
        
          <p>总结自：<a href="https://www.bilibili.com/video/BV1th411z7sn">STM32入门教程-2023版</a> 第 7 章（7-1、7-2）。</p>
<p>代码基于 <strong>STM32F103C8T6 + STM32F10x 标准外设库 3.5.0</strong>（API 已按 STM32F10x StdPeriph 3.5 头文件核对；Delay/OLED/Key 为课程配套驱动），不包含新建工程和接线步骤；文中所有 <code>.c/.h</code> 都可以直接拖进工程编译。</p>
<table>
  <thead>
      <tr>
          <th>视频</th>
          <th>视频里讲了什么</th>
          <th>本文对应</th>
      </tr>
  </thead>
  <tbody>
      <tr>
          <td>7-1</td>
          <td>ADC 简介、逐次逼近、STM32 ADC 框图、输入通道、转换模式、转换时间、硬件电路、状态寄存器</td>
          <td>0x00、0x10、0x20、0x30</td>
      </tr>
      <tr>
          <td>7-2</td>
          <td>AD 单通道、AD 多通道、代码</td>
          <td>0x40 ~ 0x55</td>
      </tr>
  </tbody>
</table>
<p>视频之外还补了：采样定理与源阻抗计算、定时器触发 + DMA、注入组、Vrefint 反推 VDDA、数字滤波、输入保护、12 条故障排查。</p>
<h2 id="0x00-从物理量到数字量">
<a class="header-anchor" href="#0x00-%e4%bb%8e%e7%89%a9%e7%90%86%e9%87%8f%e5%88%b0%e6%95%b0%e5%ad%97%e9%87%8f"></a>
0x00 从物理量到数字量
</h2><p>单片机只认识 0 和 1，但真实世界是连续的：电池电压从 12.6 V 慢慢掉到 10.8 V，电位器被拧到某个角度，光敏电阻的阻值随光照变化，电机电流在几安培里抖动。要让程序“看见”这些量，必须先把它们变成电压，再变成数字。</p>
<p>一条完整的采集链是这样的：</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-text" data-lang="text"><span class="line"><span class="cl">物理量 → 传感器（电阻/电压/电流） → 调理电路（分压/放大/滤波）
</span></span><span class="line"><span class="cl">       → ADC（采样、量化、编码） → 数字滤波 → 标定 → 使用
</span></span></code></pre></div><p>ADC（Analog-Digital Converter）就是中间那一环。它把引脚上的电压和参考电压比较，输出一个比例数字：</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-text" data-lang="text"><span class="line"><span class="cl">CODE = VIN / VREF × 2^N
</span></span><span class="line"><span class="cl">VIN  = CODE / 2^N × VREF
</span></span></code></pre></div><p>F103 的 ADC 是 <strong>12 位逐次逼近型</strong>，VREF 通常就是 VDDA = 3.3 V，所以：</p>
        
        <hr><p>本文2026-10-30首发于<a href='https://wstek.win/'>吾思 梦阁</a>，最后修改于2026-11-06</p>]]></description><category>STM32</category></item></channel></rss>