当前位置:网站首页>(16) ADC conversion experiment
(16) ADC conversion experiment
2022-07-01 17:10:00 【I love notes】
This section is mainly about reviewing ADC The corresponding content of , Our chapter adopts a AD chip xpt2046 To read the change of external voltage , Display the digital quantity of voltage on the nixie tube .
About ADC:
We all know that there are digital quantities inside the MCU , Namely 1 perhaps 0, And our current and voltage are analog quantities when they are transmitted , That is, the analog quantity is likely to be a dynamic continuous voltage , If we directly put this voltage on the MCU , Through our internal circuit transformation , More than how much voltage value is 1, Less than how much voltage is 0, But this does not indicate the specific size of the voltage value , So there is ADC To convert analog voltage value into multi digit digital voltage value , The more bits of voltage you convert , Explain that the more accurate your transformation . So for a ADC For example, there are several important indicators .1 It's resolution : Resolution is how many bits I use to express the output voltage ,ADC The resolution of is generally 8 Bits or 12 position , So 8 Bit and 12 Bit examples are converted at the same time 10v Voltage example , When we are 12 When a :

We say its resolution is 12 position , Each scale of it is 2.4mV, And when we are 8 When a :

At this time, we say its resolution is 8 position , Each scale of it is 39mV, It clearly verifies the previous conclusion ,12 Bit resolution is much higher .2 Is the conversion error , The conversion error we are talking about is half of our minimum scale , such as 12 Bit conversion error in conversion 10V The conversion error of time is 1.2mV.3 Is the conversion rate , That is, the number of conversions per second , And finish once A/D Time required for conversion , Is the reciprocal of the conversion rate .
About ADC transformation
ADC The conversion is mainly divided into three steps , They are sampling , Quantization and coding . Sampling is mainly about explaining the sampling principle , The sampling principle mainly means that the sampling frequency must be of the signal frequency 2 times , But the sampling frequency should not be too large , Too large will lead to too many sampling points , The sampling time is too long , The ideal sampling frequency should be the signal frequency 3 To 5 times . And about quantification , We all know that changes in numbers are not continuous , So the size of any numerical quantity , Are expressed as integer multiples of a minimum unit , Therefore, when using digital quantity to express voltage , It must also be converted into an integral multiple of the smallest unit , This process is quantification . We express each sampling value of a continuous voltage as an integral multiple of the smallest unit , And the integer multiple value is encoded in binary , Then it's coding , This binary signal is us AD Output value .
Hardware :
XPT2046 It is a four wire resistive touch screen , It contains 12 Bit resolution AD converter ,XPT2046 There are many functions , But in this section, we mainly focus on the use of voltage detection , my 51 There is a sliding rheostat on the MCU , We can change the input voltage by adjusting the voltage value of the sliding rheostat , The figure is shown below :

Among them AIN0 That is, with our XPT2046 The input pin of is connected , About XPT2046 The hardware diagram of is as follows

X,Y,Z,VBAT,AUX Enter after selecting through the on-chip control register ADC,ADC It can be configured as single ended or differential mode , choice VBAT,AUX perhaps X,Z Should be configured in single ended mode . As a touch screen application , You should choose differential mode , We can get it through the manual. We need to put A2,A1,A0 Configure to 001, Whole XPT2046 The sequence diagram of is as follows :

Among them 7 The meaning of is as follows :
![]()
We choose bit 7 by 1

From the above list, we can know that the configuration signal we want to send is 0x94.
Software :
It's about XPT2046 The procedure is as follows , Although our voltage value is 5V, But we don't need to calculate the actual value of the voltage , We just need to get the actual number of copies , As for the follow-up treatment, we won't deal with it for the time being . It's about XPT2046 The reading and writing procedures are as follows :
#include "xpt2046.h"
#include <intrins.h>
void delay_us(unsigned int xus){
while(xus--);
}
unsigned int spi_read(){
int i;
unsigned int dat = 0;
DCLK = 0;
for(i = 0;i < 12;i++){
dat <<= 1;
DCLK = 1;
DCLK = 0;
dat |= DOUT;
}
return dat;
}
void spi_write(unsigned char dat){
int i;
DCLK = 0;
for(i = 0;i < 8;i++){
DIN= (dat >> 7) & 0x01;
dat <<= 1;
DCLK = 0;
DCLK = 1;
}
}
unsigned int read_data(unsigned char cmd){
unsigned int val;
int i;
DCLK = 0;
CS= 0;
spi_write(cmd);
for(i = 0;i < 6;i++);
DCLK = 1;
_nop_();
_nop_();
DCLK = 0;
_nop_();
_nop_();
val = spi_read();
CS = 1;
return val;
}The procedure about the nixie tube is as follows :
#include "key.h"
unsigned char smgduan[10]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f};
void key_scan(unsigned int val){
int i;
unsigned char table[4];
for(i = 0;i < 4;i++){
table[i] = val % 10;
val /= 10;
}
for(i = 0;i < 4;i++){
switch(i){
case 0:
LSC = 0; LSB = 0; LSA = 0;
break;
case 1:
LSC = 0; LSB = 0; LSA = 1;
break;
case 2:
LSC = 0; LSB = 1; LSA = 0;
break;
case 3:
LSC = 0; LSB = 1; LSA = 1;
break;
}
P0 = smgduan[table[i]];
delay_us(100);
}
}The procedure of the main function is as follows :
#include "reg52.h"
#include "xpt2046.h"
#include "key.h"
void main(){
unsigned char cmd =0x94;
unsigned int val;
int i = 0;
while(1){
if(i==50){
val = read_data(cmd);
i = 0;
}
key_scan(val);
i++;
}
}The code of the two header functions is as follows :
#ifndef _XPT_2046_H_
#define _XPT_2046_H_
#include "reg52.h"
sbit DIN = P3^4;
sbit DOUT = P3^7;
sbit CS = P3^5;
sbit DCLK = P3^6;
unsigned int spi_read();
void delay_us(unsigned int xus);
unsigned int read_data(unsigned char cmd);
#endif
#ifndef _KEY_H_
#define _KEY_H_
#include "reg52.h"
#include "xpt2046.h"
sbit LSA = P2^2;
sbit LSB = P2^3;
sbit LSC = P2^4;
void key_scan(unsigned int val);
#endifThis completes XPT2046 Programming for .
边栏推荐
- [pyg] document summary and project experience (continuously updated
- 多线程并发之CountDownLatch阻塞等待
- String class
- China carbon disulfide industry research and investment strategy report (2022 Edition)
- How wild are hackers' ways of making money? CTF reverse entry Guide
- 中国超高分子量聚乙烯产业调研与投资前景报告(2022版)
- (27) Open operation, close operation, morphological gradient, top hat, black hat
- 荣威 RX5 的「多一点」产品策略
- 判断链表是否是回文链表
- 美国国家安全局(NSA)“酸狐狸”漏洞攻击武器平台技术分析报告
猜你喜欢

Girls who want to do software testing look here

Borui data integrated intelligent observable platform was selected into the "Yunyuan production catalogue" of China Academy of communications in 2022

Sword finger offer 20 String representing numeric value

存在安全隐患 起亚召回部分K3新能源

C語言輸入/輸出流和文件操作

Vulnhub range hacker_ Kid-v1.0.1

String的trim()和substring()详解

Cookies and session keeping technology

Free lottery | explore the future series of blind box digital copyright works of "abadou" will be launched on the whole network!

美国国家安全局(NSA)“酸狐狸”漏洞攻击武器平台技术分析报告
随机推荐
中国生物降解塑料市场预测与投资战略报告(2022版)
DNS
(27) Open operation, close operation, morphological gradient, top hat, black hat
Cookies and session keeping technology
Machine learning 11 clustering, outlier discrimination
Detailed explanation of activity life cycle and startup mode
Transition technology from IPv4 to IPv6
中国茂金属聚乙烯(mPE)行业研究报告(2022版)
存在安全隐患 起亚召回部分K3新能源
Is the securities account given by the head teacher of goucai school safe? Can I open an account?
Official announcement! Hong Kong University of science and Technology (Guangzhou) approved!
Openlayers 自定义气泡框以及定位到气泡框
Soft test software designer full truth simulation question (including answer analysis)
Yyds dry inventory MySQL RC transaction isolation level implementation
开发那些事儿:EasyCVR集群设备管理页面功能展示优化
拼接字符串,得到字典序最小的结果
[live broadcast appointment] database obcp certification comprehensive upgrade open class
GameFramework食用指南
(12) About time-consuming printing
中国PBAT树脂市场预测及战略研究报告(2022版)