Analog-to-digital conversion (A/d) and digital to analog conversion (d/a)

Source: Internet
Author: User
Tags benchmark

MCU is a typical digital system, digital system can only be a digital signal processing input, its output signal is also digital. However, many quantities in industry or life are analog, which can be converted to the corresponding voltage, current and other analog quantities by the sensor. In order to realize the measurement, operation and control of the digital system, it is necessary to convert the analog quantity and the digital quantity into one another.

The basic concept of A/D and D/a

The A/d is an analog to digital conversion, relying on A/D converter (Analog to digital Converter), referred to as ADC. D/A is the conversion of digital to analog, and relies on a DAC (digitally to Analog Converter). Their rationale is exactly the same, but the conversion direction is different, so we explain the process is mainly A/d for example to explain.
What are analog quantities? Refers to the variable in a certain range of continuous changes in the amount, in short, any two numbers between the infinite intermediate values, so called continuous changes in the amount, that is, the analog amount. The ADC is the act of putting a continuous signal in discrete numbers.

The main indicator of a/d

When we select and use a/d, it is important to rely on what metrics. Because of the variety of ad, it is divided into integral type, successive approximation type, parallel/serial comparison type, σ-δ type and many other types. At the same time the indicators are also more, and some indicators are slightly different.

Number of bits in 1.ADC

An n-bit ADC indicates that the ADC has a total of 2 N square ticks. A 8-bit ADC that outputs a data scale from 0-255 of 256 digits, which is 2 of the 8-time square.

2. Reference source

The reference source is also called the reference voltage, is the ADC's 1 important criteria, to the input ADC signal measurement accuracy, then the reference source must be accurate, the deviation of the reference source will lead to the deviation of the conversion results such as a meter stick, the total length is supposed to be 1 meters, assuming this root meter stick was baked by fire, Actually become 1.2 meters, and then use this meter stick to measure the length of the object will naturally have a larger deviation. If our benchmark source should be 5.10V, but actually provide 4.5V, so mistakenly 4.5V as 5.10V to deal with, the deviation will be relatively large.

3. Resolution

When the resolution is a minimum scale for a digital change, the amount of variation in the analog signal is defined as the ratio of the full-scale metric to the 2n-1. Assuming that the 5.10V voltage system is measured using a 8-bit ADC, the equivalent of 0-255 of the 256 scale divides 5.10V into 255 parts, then the resolution is 5.10/255=0.02v.

INL (integral nonlinearity) and DNL (differential nonlinearity)

It is generally easy to confuse the two concepts of resolution and precision, the higher the resolution, the higher the accuracy, but in fact, there is no inevitable connection. Resolution is used to describe the scale division, and precision is used to describe the degree of accuracy. The same meter stick, the same number of ticks, the resolution is equal, but the accuracy can be very different, the ADC precision relationship between the two indicators is INL (Integral nonliner) and DNL (Differencial nonliner).
INL refers to the analog value of the ADC device in all numeric values, and the error value of the maximum error between the true values, which is the most important accuracy standard of the ADC, in LSB. LSB is the meaning of the least significant bit, then the resolution of the ADC is actually the corresponding one. A 8-bit ADC with a benchmark of 5.10V, its resolution is 0.02V, with it to measure a voltage signal, the actual result is 100, that is, it is measured by the voltage value is 100*0.02=2v, assuming its inl is 1LSB, is to indicate that the true value of the voltage signal is between the 1.98v--2.02, according to the ideal case of the number because it is 99-101, the measurement error is a minimum effective bit, that is, 1LBS.
DNL represents the largest difference between the two ticks adjacent to the ADC, and the unit is also an LSB. A ruler with a resolution of 1 mm, the adjacent scale is not exactly one millimeter, and there is always a large or small error. Similarly, the two tick marks of an ADC are not always exactly equal to the resolution, and there is an error, and this is DNL. A 8-bit ADC with a benchmark of 5.10V, assuming that DNL is 0.5LSB, then when its conversion results increased from 100 to 101, ideally the actual voltage should be increased 0.02V, but DNL is 0.5LSB in the case of the actual voltage between 0.01--0.03v, It is worth mentioning that DNL is not necessarily less than 1LSB, many times it will be equal to or greater than 1LSB, which to a certain extent the scale of the disorder, when the actual voltage remains unchanged, the results of the ADC may jump between several values, largely for this reason (but not exactly, Because there is still a lot of interference).

5. Conversion rate

The conversion rate is the maximum number of times the ADC can perform a sample conversion per second, in the form of an SPS (or S/S, sa/s, or samples per second), which is reciprocal to the time it takes the ADC to complete a conversion from analog to digital. There are many kinds of ADCs, in which the integral ADC conversion time is millisecond, which belongs to the low-speed ADC, the successive-approximation ADC conversion time is subtle and belongs to the medium-speed ADC, and the conversion time of the parallel/serial ADC is up to nanosecond, which belongs to the high-speed ADC.
The main indicators of the ADC are familiar to you first, for others, as an entry level player, first of all, not anxious to understand deeply. After the use of the process encountered, and then find relevant information in-depth study, the current focus is to build an ADC in the Mind basic concept.

PCF8591

The PCF8591 is a single-supply, low-power, 8-bit CMOS data acquisition device with 4 analog inputs, 1 analog outputs and a serial I²c bus interface for communication with the microcontroller. Pins 1, 2, 3, 4 are 4 analog inputs, pins 5, 6, 7 are the hardware address of the I²C bus, 8 feet are digitally gnd,9 feet and 10 feet are the SDA and SCL of the I²c bus. 12 feet is the clock selection pin, if the high level means with an external clock input, the lower level with the internal clock, our circuit is the internal clock, so 12 feet directly to the GND, while 11 feet floating. 13 feet is a simulated ground agnd, in the actual development, if there are more complex analog circuit, then the AGND part in the layout and wiring to special treatment, and the connection to GND there are many ways, here we first understand. There is no complicated analog part of the circuit on our board, so we get agnd and gnd together. The 14 foot is the reference source, the 15 foot is the analog output of the DAC, and the 16 foot is the power supply VCC.
The PCF8591 ADC is a successive approximation and the conversion rate is a medium speed, but its speed bottleneck is on the i²c communication. Due to the slow speed of the i²c communication, the conversion speed of the final PCF8591 is directly dependent on the communication rate of the i²c. Due to the speed limit of i²c, so PCF8591 is a low-speed AD and DA integration, mainly used in some conversion speed requirements are not high, the hope for low-cost occasions, such as battery-powered equipment, measurement of battery power supply voltage, voltage below a certain value, alarm prompt replacement batteries and other similar occasions.
Software programming
PCF8591 communication interface is I²C, then programming is bound to conform to this protocol. Single-chip microcomputer to initialize the PCF8591, send a total of three bytes. The first byte, similar to the EEPROM, is the device address byte, where 7 bits represent the address and 1 bits represent the read-write direction. Address high 4 bit fixed is 0b1001, low three bits is a2,a1,a0, these three bits of our circuit are connected to GND, so that is 0b000, the second byte sent to PCF8591 will be stored in the control register, to control the function of PCF8591. where the 3rd and 7th digits are fixed 0, the other 6 have their respective functions.
The 6th bit of the control byte is the DA enable bit, and this position 1 represents the DA output pin enable, which generates an analog voltage output function. The 4th and 5th bits can be implemented to configure the PCF8591 4 analog inputs into single-ended mode and differential mode, the difference between single-ended mode and differential mode, we have introduced in section 17.5, here you only need to know that these two bits are configured to configure the ad Input mode control bit can be
The 2nd bit of the control byte is the automatic increment control bit, the automatic increment means, for example we have altogether 4 channels, when we all use, reads the channel 0, the next time reads, will automatically enters the channel 1 to read, does not need us to specify the next channel, because the A/d each read data, Is the result of the last conversion, so the students in the use of automatic increment function, pay special attention to the current reading is the value of the previous channel. In order to maintain the universality of the program, our code does not use this function, directly to do a common program.
The No. 0 and 1th bits of the control byte are channel selection bits, and 00, 01, 10, 11 represent a total of 0 channels selected from 3 to 4.
The third byte d/a data register sent to PCF8591, which represents the voltage value of the D/a analog output. D/A simulation we will introduce, you know the role of this byte can be. If we only use the A/D function, we can not send a third byte.

/* Read the current ADC conversion value, CHN-ADC channel number 0~3 */

unsigned char GetADCValue(unsigned char chn)      {unsigned char val;I2CStart();if (!I2CWrite(0x48<<1))  //寻址PCF8591,如未应答,则停止操作并返回0{    I2CStop();    return 0;}I2CWrite(0x40|chn);         //写入控制字节,选择转换通道I2CStart();I2CWrite((0x48<<1)|0x01);  //寻址PCF8591,指定后续为读操作    I2CReadACK();                //先空读一个字节,提供采样转换时间val = I2CReadNAK();         //读取刚刚转换完的值I2CStop();return val; }

Output of the DAC

此处输入代码/* 设置DAC输出值,val-设定值 */ void SetDACOut(unsigned char val)  {I2CStart();if (!I2CWrite(0x48<<1)) //寻址PCF8591,如未应答,则停止操作并返回{    I2CStop();    return;}I2CWrite(0x40);         //写入控制字节I2CWrite(val);          //写入DA值  I2CStop();}

Analog-to-digital conversion (A/d) and digital to analog conversion (d/a)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.