当前位置:网站首页>(17) 51 MCU - AD/DA conversion
(17) 51 MCU - AD/DA conversion
2022-08-05 01:01:00 【Meursault639】
目录
学习目标
What we need to learn today isAD/DA转换,That is, the conversion between digital signals and analog signals.To convert analog signal to digital signal we use adjustable resistor、Photoresistors and thermistors are implemented,The photoresistor is less than100时(较暗),D1灯会自动亮;And the conversion of digital signal to analog signal we use to achieveDABreathing light to show.
成果展示
AD
DA
硬件知识
介绍
- AD(Analog to Digital):模拟-数字转换,将模拟信号转换为计算机可操作的数字信号.
- DA(Digital to Analog):数字-模拟转换,将计算机输出的数字信号转换为模拟信号.
- AD/DA转换打开了计算机与模拟信号的大门,极大的提高了计算机系统的应用范围,也为模拟信号数字化处理提供了可能.
硬件电路模型
AD:It is to convert the voltage quantity into a digital quantity.
DA:其实有点类似于PWM,Finally it goes through a low pass filter,就能实现效果了.
- AD转换通常有多个输入通道,用多路选择开关连接至AD转换器,以实现AD多路复用的目的,提高硬件利用率
- AD/DA与单片机数据传送可使用并口(速度快、原理简单),也可使用串口(接线少、使用方便)
- 可将AD/DA模块直接集成在单片机内,这样直接写入/读出寄存器就可进行AD/DA转换,单片机的IO口可直接复用为AD/DA的通道
电路
AD
这是一个简单的AD芯片(ADC0809),First select the analog switch,之后进行AD转换,And then output through the buffer,就可以了.
DA
这是一个简单的DA芯片(ADC0832),首先输入数据,The registers are controlled by the control circuit,最后通过一个DAThe converter output becomes.
运算放大器
- 运算放大器(简称“运放”)It is an amplifying circuit unit with a very high magnification.A differential amplifier is integrated inside、电压放大器、Power amplifier three-stage amplifier circuit,is a performance complete、Powerful general-purpose amplifier circuit unit,Because of its wide application,It now appears in the circuit diagram as a basic circuit element
- There are circuits that can be formed by operational amplifiers:电压比较器、反相放大器、同相放大器、电压跟随器、加法器、积分器、Differentiators, etc
- Methods of Analysis for Operational Amplifier Circuits:虚短、虚断(under negative feedback conditions)
运放电路
电压比较器
This is what the voltage comparator does,当+大于-的时候,输出VCC,当-大于+的时候,输出GDN.
反向放大器
This conclusion can be obtained by analyzing virtual short and virtual segments.
同向放大器
电压跟随器
DA原理
T型电阻网络DA转换器
The specific process of this will not be described in detail,We just need to know that each switch is equivalent to each bit,At that time, you only need to know which switches are closed to know how many times the magnification is.
PWM型DA转换器
The effect of this is to filter out the communication,into a DC voltage.
AD原理
逐次逼近型AD转换器
逐次逼近型ADThe principle of the converter is throughDACConstantly changing to compare with the input voltage,until a suitable voltage is found,Just output the corresponding digital quantity.
AD/DA性能指标
- 分辨率:指AD/DA数字量的精细程度,通常用位数表示.例如,对于5V电源系统来说,8位的AD可将5V等分为256份,即数字量变化最小一个单位时,模拟量变化5V/256=0.01953125V,所以,8位AD的电压分辨率为0.01953125V,AD/DA的位数越高,分辨率就越高
- 转换速度:表示AD/DA的最大采样/建立频率,通常用转换频率或者转换时间来表示,对于采样/输出高速信号,应注意AD/DA的转换速度
XPT2046
时序
CS作为片选,Used to select different devices,然后是DCLKA rising edge is a transmit,Falling edge is read,DOUTis the read value.
代码
AD
// XRT2046.c
#include <REGX52.H>
#include "Delay.h"
//引脚定义
sbit XPY2046_DIN=P3^4;
sbit XPY2046_CS=P3^5;
sbit XPY2046_DCLK=P3^6;
sbit XPY2046_DOUT=P3^7;
/**
* @brief ZPT2046读取AD值
* @param Command 命令字,范围:头文件内定义的宏,结尾的数字表示转换的位数
* @retval AD转换后的数字量,范围:8位为0~255,12位为0~4095
*/
unsigned int XPT2046_ReadAD(unsigned char Command)
{
unsigned int ADValue = 0;
unsigned char i;
XPY2046_DCLK = 0;
XPY2046_CS = 0;
for(i=0;i<8;i++)
{
XPY2046_DIN=Command&(0x80>>i);
XPY2046_DCLK=1;
Delay(1);
XPY2046_DCLK=0;
}
for(i=0;i<16;i++)
{
XPY2046_DCLK=1;
Delay(1);
XPY2046_DCLK=0;
if(XPY2046_DOUT){ADValue|=(0x8000>>i);}
}
XPY2046_CS=1;
if(Command & 0x08){
return ADValue>>8;
}else
return ADValue>>4;
}
// main.c
#include <REGX52.H>
#include "LCD1602.h"
#include "Delay.h"
#include "XPT2046.h"
unsigned int ADValue1 = 0,ADValue2 = 0,ADValue3 = 0;
sbit LED = P2^0;
void main(){
LCD_Init();
LCD_ShowString(1,1,"ADD NTC GR");
while(1){
ADValue1 = XPT2046_ReadAD(XPT2046_XP_8);//读取AIN0,可调电阻
LCD_ShowNum(2,1 ,ADValue1,3);
ADValue2 = XPT2046_ReadAD(XPT2046_YP_8);//读取AIN1,热敏电阻
LCD_ShowNum(2,6 ,ADValue2,3);
ADValue3 = XPT2046_ReadAD(XPT2046_VBAT_8);//读取AIN2,光敏电阻
LCD_ShowNum(2,11 ,ADValue3,3);
if(ADValue3 < 100){// The photoresistor is less than 100(较暗)just shine
LED = 0;
}else{
LED = 1;
}
}
}
DA
//main.c
#include <REGX52.H>
#include "Delay.h"
#include "Time0.h"
sbit DA = P2^1;
unsigned char Counter,Compare;//计数值和比较值,用于输出PWM
unsigned char i;
void main(){
Timer0_Init();
while(1){
for(i=0;i<90;i++)
{
Compare=i; //设置比较值,改变PWM占空比
Delay(10);
}
for(i=90;i>0;i--)
{
Compare=i; //设置比较值,改变PWM占空比
Delay(10);
}
}
}
void Timer0_Routine() interrupt 1
{
static unsigned int T0Count;
TL0 = 0xAD; //设置定时初始值
TH0 = 0xFF;
Counter++;
Counter%=90;
if(Counter < Compare){
DA = 1;
}else
DA = 0;
}
总结
本节学习的是DA和AD,其中DA比较重要,而AD一般都能用PWM来实现,希望对大家有所帮助,If there are mistakes, I hope to point them out in time,谢谢大家.
边栏推荐
- The principle of NMS and its code realization
- Inter-process communication and inter-thread communication
- 手把手基于YOLOv5定制实现FacePose之《YOLO结构解读、YOLO数据格式转换、YOLO过程修改》
- 2021年11月网络规划设计师上午题知识点(上)
- GCC: compile-time library path and runtime library path
- Software testing interview questions: What stages should a complete set of tests consist of?
- 深度学习:使用nanodet训练自己制作的数据集并测试模型,通俗易懂,适合小白
- 【FreeRTOS】FreeRTOS与stm32内置堆栈的占用情况
- 深度学习训练前快速批量修改数据集中的图片名
- 测试工作这么难找吗?今年32,失业2个月,大龄测试工程师接下来该拿什么养家?
猜你喜欢
随机推荐
Dynamic Programming/Knapsack Problem Summary/Summary - 01 Knapsack, Complete Knapsack
After the staged testing is complete, have you performed defect analysis?
If capturable=False, state_steps should not be CUDA tensors
2022 Nioke Multi-School Training Session H Question H Take the Elevator
MongoDB construction and basic operations
4. PCIe 接口时序
行业现状?互联网公司为什么宁愿花20k招人,也不愿涨薪留住老员工~
gorm joint table query - actual combat
Method Overriding and Object Class
Pytorch使用和技巧
缺陷检测(图像处理部分)
【七夕如何根据情侣倾听的音乐进行薅羊毛】背景音乐是否会影响情侣对酒的选择
tensor.nozero(),面具,面具
The principle of NMS and its code realization
习题:选择结构(一)
主库预警日志报错ORA-00270
CNI (Container Network Plugin)
【翻译】CNCF对OpenTracing项目的存档
How DHCP works
[FreeRTOS] FreeRTOS and stm32 built-in stack occupancy