Answer the question
In order to leave comments, you need to log in
How to get volts from an analog signal?
How to get voltage from an analog signal (for example 1023 = 5V)?
Answer the question
In order to leave comments, you need to log in
On arduino there is an excellent map function and in English. , to convert ranges.
Математически функция map() может быть записана так:
long map(long x, long in_min, long in_max, long out_min, long out_max)
{
return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min;
}
//а если заменить long на float или double, то она будет работать с плавающей точкой
//и соответственно изменить имя функции, что бы оно не пересекалось с родной библиотекой ардуины
We drag something, if I didn’t finish in the exam, that is, the so-called. "proportions". If A/B=C/D, then C=A*D/B.
Here, of course, there may be a more complicated case - the reference voltage may differ from 5 V. But there are no fundamental differences.
I don’t know how it is in arduins, but ...
I think that the analog signal is fed to the ADC and in the program you are already dealing with a discrete (digitized) signal.
So, in the ADC, there are usually a couple of coefficients (zero offset and scale), the ADC documentation provides a formula for how to use these coefficients with a digital signal readout to get volts (by the way, the ADC does not necessarily measure the voltage). Usually the formula is something like: (X + offset)*scale. But there may be other options.
The coefficients on all ADCs are different. Even on two identical ADCs, they can be different (and usually they are different). ADCs are calibrated at the factory and the coefficients are hardwired into the chip. The documentation for the ADC should describe how these coefficients are obtained. If the ADC is multichannel, then the coefficients may be different for each channel.
In the ADC library, there are usually functions for obtaining calibration coefficients and maybe even receiving an already converted signal.
In general, if the ADC were ideal, then it would be easy to convert the digital reading to volts. For example, the ADC outputs 16-bit unsigned readings (i.e., the ADC output numbers from 0 to 65535, data type uint16_t), the measurement range is valid [-5; +5]V. Let uint16_t X be the digital reading received from the ADC, then you can convert it to volts like this: ((double)(((int32_t)X) - 0x7FFF)) / 0x7FFF ) * 5.0. If desired, you can open the brackets and get the same 2 calibration coefficients for the ideal ADC.
But since ADCs are not perfect and there are various errors and interferences, then the same calibration coefficients appear. The conversion formula remains approximately the same, but not exact numbers are used, but selected coefficients.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question