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.
- Make a DAC with a microcontroller's PWM timer
http://www.edn.com/design/analog/4337128/Make-a-DAC-with-a-microcontroller-s-PWM-timer Many embedded ...
- 基于STM32Cube的ADC模数采样设计
1.背景 此实验建立在STM32F429核心板基础上,对于深刻了解STM32Cube使用具有深刻意义.利用DMA进行ADC采样,具有速度快,极大减少CPU消耗的优势,对于数据采集系统具 ...
- Micropython TPYBoard ADC的使用方法
基本用法 import pybadc = pyb.ADC(Pin('Y11')) # create an analog object from a pinadc = pyb.ADC(pyb.Pin.b ...
- 【STM32】PWM DAC基本原理(实验:PWM实现DAC)
虽然STM32F103ZET6具有内部DAC,但是也仅仅只有两条DAC通道,并且STM32还有其他的很多型号是没有DAC的.通常情况下,采用专用的D/A芯片来实现,但是这样就会带来成本的增加. 不过S ...
- 玩转X-CTR100 l STM32F4 l DAC数字模拟转换
我造轮子,你造车,创客一起造起来!塔克创新资讯[塔克社区 www.xtark.cn ][塔克博客 www.cnblogs.com/xtark/ ] 本文介绍X-CTR100控制器 DAC接口 ...
- STC 单片机ADC实现原理
模数转换器原理 数模转换器( analog to digitI converter,ADC),简称为A/D,ADC是链接模拟世界和数字世界的桥梁.它用于将连续的模拟信号转换为数字形式离散信号.典型的, ...
- quick start guide for XMEGA ADC
This is the quick start guide for the Analog to Digital Converter (ADC), with step-by-step instructi ...
- AVR单片机教程——DAC
本文隶属于AVR单片机教程系列. 单片机的应用场景时常涉及到模拟信号.我们已经会使用ADC把模拟信号转换成数字信号,本讲中我们要学习使用DAC把数字信号转换成模拟信号.我们还将搭建一个简单的功率放 ...
- LPC43xx SGPIO Experimentation
LPC4350 SGPIO Experimentation The NXP LPC43xx microcontrollers have an interesting, programmable ser ...
随机推荐
- (MHA+MYSQL-5.7增强半同步)高可用架构设计与实现
架构使用mysql5.7版本基于GTD增强半同步并行复制配置 reploication 一主两从,使用MHA套件管理整个复制架构,实现故障自动切换高可用 优势: ...
- HDU 2066 一个人的旅行(dijkstra水题+判重边)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2066 题目大意:输入数据有多组,每组的第一行是三个整数T,S和D,表示有T条路,和草儿家相邻的城市的有 ...
- poj 1041(字典序输出欧拉回路)
John's trip Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 8641 Accepted: 2893 Spe ...
- Windows下的字体美化
转自HJK的博客 许多人钟情于Mac很大一部分是因为Mac优雅的字体渲染,Windows原生的效果很难做得到,即便是开启了CleartType效果也不尽如人意.不论是微软本身的审美原因还是历史包袱,与 ...
- 【Mac 10.13.0】安装 libimobiledevice,提示报错:warning: unable to access '/Users/lucky/.config/git/attributes': Permission denied解决方案
打开终端,执行命令: 1.sudo chown -R XXX /usr/local (XXX表示当前用户名) 2.ruby -e "$(curl -fsSL https://raw.git ...
- iBatis应用--控制执行SQL时的超时时间
https://blog.csdn.net/jackie_xiaonan/article/details/8459320
- bzoj 1861 treap
思路:搞搞平衡树. #include<bits/stdc++.h> #define LL long long #define fi first #define se second #def ...
- Vsftpd支持SSL加密传输
ftp传输数据是明文,弄个抓包软件就可以通过数据包来分析到账号和密码,为了搭建一个安全性比较高ftp,可以结合SSL来解决问题 SSL(Secure Socket Layer)工作于传输层和应用程 ...
- 主流PHP框架性能评测 (引用)
主要涉及到的框架有 CodeIgniter 老品牌易用性框架yaf 鸟哥用c写的php扩展,高性能框架yii 自动生成代码(gii)laravel 号称最优雅的框架swoole framework 支 ...
- BNUOJ 52516 Just A String
$KMP$. 枚举每一个后缀,去原串中进行匹配,每次匹配到原串到$i$位置的后缀与这次枚举的后缀的前缀,更新答案. #include<bits/stdc++.h> using namesp ...