当前位置:网站首页>(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 .
边栏推荐
- ACM MM 2022视频理解挑战赛视频分类赛道冠军AutoX团队技术分享
- [Verilog quick start of Niuke network question brushing series] ~ priority encoder circuit ①
- SQL question brushing 1050 Actors and directors who have worked together at least three times
- 【牛客网刷题系列 之 Verilog快速入门】~ 优先编码器电路①
- 多线程并发之CountDownLatch阻塞等待
- 中国生物降解塑料市场预测与投资战略报告(2022版)
- 荣威 RX5 的「多一点」产品策略
- How wild are hackers' ways of making money? CTF reverse entry Guide
- [flask introduction series] cookies and session
- [live broadcast appointment] database obcp certification comprehensive upgrade open class
猜你喜欢
![[Verilog quick start of Niuke network question brushing series] ~ priority encoder circuit ①](/img/24/23f6534e2c74724f9512c5b18661b6.png)
[Verilog quick start of Niuke network question brushing series] ~ priority encoder circuit ①

美国国家安全局(NSA)“酸狐狸”漏洞攻击武器平台技术分析报告

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

C语言输入/输出流和文件操作

阿里云、追一科技抢滩对话式AI

Jojogan practice

Official announcement! Hong Kong University of science and Technology (Guangzhou) approved!

C語言輸入/輸出流和文件操作
![[flask introduction series] cookies and session](/img/2e/d50e0a032c4ec48935cb5df206a29b.png)
[flask introduction series] cookies and session

【splishsplash】关于如何在GUI和json上接收/显示用户参数、MVC模式和GenParam
随机推荐
Sword finger offer II 015 All modifiers in the string
官宣!香港科技大学(广州)获批!
unity3d扩展工具栏
【C語言補充】判斷明天是哪一天(明天的日期)
String类
(十七)DAC转换实验
Alibaba cloud, Zhuoyi technology beach grabbing dialogue AI
【牛客网刷题系列 之 Verilog快速入门】~ 优先编码器电路①
中国超高分子量聚乙烯产业调研与投资前景报告(2022版)
两数之和c语言实现[通俗易懂]
ShenYu 网关开发:在本地启用运行
Are you still using charged document management tools? I have a better choice! Completely free
如何写出好代码 — 防御式编程指南
存在安全隐患 起亚召回部分K3新能源
What is the effect of choosing game shield safely in the game industry?
pyqt5中,在控件上画柱状图
Hidden Markov model (HMM): model parameter estimation
P2592 [zjoi2008] birthday party (DP)
China sorbitol Market Forecast and investment strategy report (2022 Edition)
(1) CNN network structure