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 ...
随机推荐
- ubuntu无法获得锁 /var/lib/dpkg -open 问题
问题: 方法: sudo rm /var/lib/dpkg/lock 然后再安装就可以了
- 使AJAX可缓存——基于flask
主流浏览器都有缓存机制,主要基于HTTP协议定义的缓存策略.对于一定时间内不发生变动的文档缓存起来,对于下次请求,就可以直接返回缓存的结果.使用缓存有以下好处: 1.减少冗余的数据传输,节省网络流量成 ...
- (总结)MySQL自带的性能压力测试工具mysqlslap详解
PS:今天一同事问我有木有比较靠谱的mysql压力测试工具可用.其实mysql自带就有一个叫mysqlslap的压力测试工具,还是模拟的不错的.下面举例说说.mysqlslap是从5.1.4版开始的一 ...
- 将table导出为excel格式文件
html: <table cellpadding="0" cellspacing="0" class="data_table" id= ...
- HTML+CSS图文排版
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xht ...
- function(函数)中的动态参数
我们可向函数传递动态参数,*args,**kwargs,首先我们来看*args,示例如下: 1.show(*args) def show(*args): print(args,type(arg ...
- php将长字符串拆分为指定最大宽度的字符串数组
/** * 将字符串拆分为指定最大宽度的字符串数组.单字节字符宽度为1,多字节字符通常宽度为2 * @param string $msg 要拆分的字符串 * @param int $width 结果数 ...
- ASP.NET MVC 3和Razor中的@helper
ASP.NET MVC 3支持一项名为“Razor”的新视图引擎选项(除了继续支持/加强现有的.aspx视图引擎外).当编写一个视图模板时,Razor将所需的字符和击键数减少到最小,并保证一个快速.通 ...
- 【C#】Unicode的流言终结者和编码大揭秘
如果你是一个生活在2003年的程序员,却不了解字符.字符集.编码和Unicode这些基础知识.那你可要小心了,要是被我抓到你,我会让你在潜水艇里剥六个月洋葱来惩罚你. 这个邪恶的恐吓是Joel Spo ...
- ThinkPHP 多语言的实现
1.按照官方文档进行修改 2.注意区分项目语言包和系统语言包 3.实现语言包和数据库语言同步切换 4.thinkPHP多语言实现与Cookie有关, 谷歌浏览器下按F12查看Request Heade ...