Create a DAC from a microcontroller's ADC

Few microcontrollers include a DAC. Although you can easily find an inexpensive DAC to control from your microcontroller, you can use unused peripherals instead of adding parts. Fortunately, you can convert a microcontroller‘s ADC channel along with a GPIO (general-purpose input/output) pin into a DAC. You can make a DAC by charging a capacitor to an analog level by driving it high. You can also discharge the capacitor by driving it low, or you can hold its voltage by tristating it (Figure 1). At first glance, this approach seems like a crude way to make a DAC. The technique becomes more plausible, however, when you use a PID (proportional-integral-derivative) algorithm and monitor the voltage with the microcontroller‘s ADC.

You can use the PID algorithm to compare the output voltage with the desired value and calculate the error. If the error value is zero, then the I/O control block tristates the GPIO pin. If the error signal is positive or negative, then the I/O control block turns the I/O pin to a high state to charge the capacitor or to a low state to discharge it. Your microcontroller code should load the error value into a timer to generate a timed pulse. The error-value sign determines the charge/discharge cycle, and its magnitude determines the duration of the pulse. Once the cycle is complete, you can set the I/O pin to a tristate mode, which holds the value. The algorithm can run as a software loop. You can call it based on another timer interrupt. To minimize the response time, make sure that this algorithm runs at the desired output value slightly longer than 2.2RC. You need the extra time to completely charge or discharge the capacitor through resistor R1.

The DAC‘s resolution depends on several factors, the foremost of which is ADC resolution. The DAC‘s resolution never exceeds that of the ADC. Variable selection and timer resolution also affect DAC resolution. To implement a 10-bit DAC, you need a 16-bit timer and 16-bit variables for the PID algorithm. You can use a lower-resolution timer, but you must more frequently call the algorithm. That action results in longer settling times and higher CPU usage.

By adjusting the algorithm‘s PID variables, you can achieve surprisingly good output settling times with little change to the DAC‘s output after settling. The stability of the ADC‘s voltage reference limits temperature stability. Neither the temperature stability of R1 and C1 nor the leakage of C1 has an adverse effect on the DAC‘s stability. The selection of R1 and C1 depends on the application, and you should select them based on settling time. For relatively slow-acting DACs, you can increase the update rate by running the algorithm faster than the 2.2RC period and using an 8-bit timer. To buffer the DAC output, use an op amp as a voltage follower or use a common emitter follower. You can use a noninverting amplifier to amplify the output and feed just a portion of it to the ADC through a voltage divider.

Create a DAC from a microcontroller's ADC

时间: 2024-10-16 16:14:55

Create a DAC from a microcontroller's ADC的相关文章

Make a DAC with a microcontroller's PWM timer

Many embedded-microcontroller applications require generation of analog signals. An integrated or stand-alone DAC fills the role. However, you can often use PWM signals for generating the required analog signals. You can use PWM signals to create bot

Informatica&DAC

Informatica&DAC简介和常见问题解决 Informatica 安装Informatica之前需要新建用户,详见下面 INFORMATICA四个表空间: 1.INFORMATICA:主要用来存储informatica的源表目标表和映射以及mapplet 2.DAC:主要存放DAC的配置信息以及tasks,subject aear等 3.bidwd:这个就是我们自己用的目标存储库 4.BIDWD_IND:索引表空间 --创建三个表空间,分别用于存储Informatica.DAC.DW c

cortex_m3_stm32嵌入式学习笔记(十八):DAC实验(数模转换)

STM32 的 DAC 模块(数字/模拟转换模块)是 12 位数字输入,电压输出型的 DAC. DAC可以配置为 8 位或 12 位模式,也可以与 DMA 控制器配合使用. DAC 工作在 12 位模式时,数据可以设置成左对齐或右对齐. DAC 模块有 2 个输出通道,每个通道都有单独的转换器.在双 DAC 模式下, 2 个通道可以独立地进行转换,也可以同时进行转换并同步地更新 2 个通道的输出. 本节实验,我们将利用按键(或 USMART) 控制 STM32 内部 DAC1来输出电压,通过 A

基于STM32Cube的ADC模数采样设计

1.背景         此实验建立在STM32F429核心板基础上,对于深刻了解STM32Cube使用具有深刻意义.利用DMA进行ADC采样,具有速度快,极大减少CPU消耗的优势,对于数据采集系统具有很大的优势,特别是其单路2.4MSPS采样速度,三路组合可以达到惊人的7.2MSPS采样速度,对于一般应用均可满足. 2.STM32Cube配置 2.1 工程建立在前面均与简述,这里不做赘述,系统时钟180MHz. 2.2 ADC参数配置 Scan Conversion Mode 扫描模式,当使用

LPC4350 SGPIO Experimentation

LPC4350 SGPIO Experimentation The NXP LPC43xx microcontrollers have an interesting, programmable serial peripheral called the SGPIO (Serial GPIO). It consists of a slew of counters and shift registers that can be configured to serialize and deseriali

SD卡WAV音乐播放器(quartus11.0)(FAT32)(DE2-115)

准备工具:格式工厂,Windows录音机,SD卡(小于等于2G),音箱 首先,选一首MP3,用格式工场转化成WAV格式.可以看到转化后的文件变得很大,因为WAV就是AD采样值加个文件头,所以数据量巨大,这也是MP3压缩算法流行的原因. 将转化后的WAV文件用Windows录音机打开编辑,采样率设置为8Khz,16位立体声,然后写入到SD卡里,恩,这里提一句,可以写入任意数量的歌曲,我写的程序是播放完卡里所有的WAV文件.当然别放其他文件例如图片文件进去捣乱啊,文件系统里没有识别其他文件的过程,开

mini2440裸机音乐播放器(很久以前的笔记)

[这是好久以前写的,有点乱,没时间整理,当做记录用的.] 图片粘贴失效,没上传图,想要的直接下载文档吧. 项目目的:通过IIS,触摸屏,LCD模块实现音乐播放器功能(按钮上一首.下一首.播放.暂停的音频控制功能,并实现播放歌曲时显示相应的歌曲图片,不播放时显示hello music图片) 项目设备:windows7(32位),mini2440,uboot(nandflash),ADS1.2开发环境,jlink v8,耳机: 功能模块LCD.触摸屏.IIS 分别介绍: Main函数中主频设置: U

单片机小白学步系列(十八) 单片机/计算机系统概述:通信接口与协议

前面说了信息与数据的概念,这里要说的是与之关系密切的问题--通信. 通信 何为通信?在英文中,通信用Communication表示,这个词也有交流的意思.实际上,通信和交流确实是一样的意思.不过在汉语中,交流常用来表示人与人之间的交流:而通信一般用于比较专业正式的场合,也就是所谓的术语. 人与人之间的交流,是信息交换的过程:微机系统或模块之间的通信,就是数据传输的过程了. 接口 人在用语言交谈时,需要用嘴说话,用耳朵听,通过空气来传播.信息的传递依赖嘴巴和耳朵来进行发送和接收. 微机系统的通信,

mini2440裸机试炼之IIS——音乐播放器

IIS 信号频率设置 IIS(Inter-IC Sound)由飞利浦公司开发,是一种常用的音频设备接口,主要用于CD.MD.MP3等设备. s3c2440一共有5个引脚用于IIS:IISDO.IISDI.IISSCLK.IISLRCK和CDCLK.前两个引脚用于数字音频信号的输出和输入,另外三个引脚都与音频信号的频率有关,可见要用好IIS,就要把信号频率设置正确. IISSCLK为串行时钟,每一个时钟信号传送一位音频信号.因此IISSCLK的频率=声道数×采样频率×采样位数,如采样频率fs为44