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 ...
随机推荐
- spring web 生命周期理解
spring web /bean 生命周期 反射注解 aop代理类生成 init servlet 初始化 load spring-context.xml load XmlParser 类解析对象 ...
- MySQL 作业题及答案
MySQL 测试题 一. 表关系: 请创建如下表,并创建相关约束 创建表sql如下: /* Navicat MySQL Data Transfer Source Server : 192.168.11 ...
- EnumSet基本用法
enum Season { SPRING, SUMMER, FALL, WINTER } public class EnumSetTest { public static void main(Stri ...
- Java学习(一)Scanner报错java.util.NoSuchElementException
我在一个方法A中使用了Scanner的 Scanner input=new Scanner(System.in),随后又将其关闭了,因为Eclipse里面你若不关闭,他会有一个warning:Reso ...
- 深度学习方法(十二):卷积神经网络结构变化——Spatial Transformer Networks
欢迎转载,转载请注明:本文出自Bin的专栏blog.csdn.net/xbinworld. 技术交流QQ群:433250724,欢迎对算法.机器学习技术感兴趣的同学加入. 今天具体介绍一个Google ...
- AXFR和IXFR区域传输及原理
由于区域在DNS中发挥着重要的作用,因此希望在网络上的多个DNS服务器中提供区域,以提供解析名称查询时的可用性和容错.否则,如果使用单个服务器而该服务器没有响应,则该区域中的名称查询会失败.对于主要区 ...
- Spring MVC数据绑定(二)
之前学习了SpringMVC数据绑定的基本知识和简单数据绑定以及POJO类型数据的绑定.接下来总结剩下的一些数据类型的绑定 1. 绑定包装POJO 所谓的包装POJO,就是在一个POJO中包含另一个简 ...
- day1作业一:编写登陆接口
作业一:编写登陆接口 1.输入用户名和密码 2.认证成功后显示欢迎信息 3.输错三次后锁定 Readme: (1)提示用户输入用户名: (2)用户名验证,验证是否已经锁定: (3)是否锁定:已锁定告诉 ...
- maven的认识
>>>>>>>>>> 安装完成后,设置为环境变量 命令行输入,如下图片就表明成功 >>>>>>>& ...
- React Native踩坑之启动android模拟器失败
报错 Could not install the app on the device, read the error above for details.Make sure you have an A ...