ADC value is converted to voltage value (mechanical language gives voltage value)

How to use the ADC module of the microcontroller (or an independent ADC chip) to get the actual voltage value connected to the ADC pin?

This problem is a problem that everyone will encounter when they first come into contact with ADC.

what value will be read

What value will the microcontroller read? One feature that needs to be seen is the ADC of several bits, which will be given in the manual. For example, the ADC of STM32 is 12 bits. Also, there are 8-bit, 10-bit, 16-bit, 24-bit, etc.

Let me tell you the answer first: The ADC value read by STM32 is from 0 to 4095. When you connect the ADC pin to GND, it reads 0. When you connect the ADC pin to VDD, it reads 4095. .

Next, I will tell you why : As mentioned earlier, the ADC of STM32 is 12-bit. We know that the value of 8-bit is from 0 to 255; the value of 16-bit is from 0 to 65535. The maximum value of these two bits is the one we are most familiar with.

(How to figure it out? This problem is reduced to another level. The value of several bits we are talking about here, each bit can only be 0 or 1. For example, the value of 2 bits can be expressed as 00 01 10 11 four There are different values, which are expressed in binary, and converted to decimal is 0 1 2 3, so it is concluded that a 2-bit value can be represented from 0 to 3. Similarly, a 3-bit value can be expressed in decimal 0~9, you can expand and calculate. The value of 4 bits can represent 0~16, the value of 5 bits can be represented from 0~31, and similarly, you can get the range that the value of any bit can represent. )

Therefore, the 12-bit value can be represented from 0 to 4095, which is why the value of the 12-bit ADC is from 0 to 4095.

How to convert the read value into the actual voltage value

As mentioned earlier, we input GND, the read value is 0, input VDD, and the obtained value is 4095, then, when you read 2035, do you know how much V is the input voltage? This question, in the final analysis, comes to the mathematical XY coordinates, given the coordinate values ​​of two points (0,0) (3.3,4095), given any X coordinate value, the problem of finding the Y value, right? Simple or not?

ADC voltage measurement 2-2

what is the reference voltage

Before discussing this issue, what is the actual voltage of your VDDA with a multimeter? Is it the standard 3.300V? Shouldn't it? Maybe 2.296V, maybe 3.312V. Then after you connect VDD to the ADC pin, what you get is 4095, that is, in fact, when you read the data of 4095, the actual voltage value is not the 3.300V you imagined. Some beginners think that the voltage difference of a few millivolts does not matter, but in practical applications, a few millivolts may represent a large actual working condition, for example, on an electronic scale with a range of 50 grams.

Therefore, at this time, the chip manufacturer has thought of a way to introduce a reference voltage into the ADC module, and a very standard reference voltage chip is used to access the reference voltage pin. Standard voltage chips are generally called reference voltage chips, or reference voltage chips. For example REF3133 (output 3.300V) REF3025 (output 2.500V) and so on.

Note: There are reference voltage pins above 100 pins (including 100 pins) of STM32. On a microcontroller without a reference voltage pin, the reference voltage chip can be connected to VDDA, but the voltage difference between VDDA and VDD cannot exceed 0.3V. For example, if VDD is 3.3V, a 3.3V reference voltage can be connected to VDDA The chip or the reference voltage chip of 3.0V, but the reference voltage chip of 2.5V cannot be connected, and the consequence is that the chip cannot work.

What is the input voltage range of the ADC pins

Under normal circumstances, the input voltage of the ADC pin is from 0 to VDD. If there is a REF pin, it is generally 0 to Vref, and there are also cases of 0 to 2 Vref.

If the voltage to be measured is greater than the input voltage of the ADC, for example, if you want to measure the voltage of 0~5V with STM32, you can add a resistor divider and amplifier circuit before inputting the ADC pin.

 
 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325870176&siteId=291194637