A
A
Anonymous54545872021-05-10 19:48:13
WordPress
Anonymous5454587, 2021-05-10 19:48:13

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

3 answer(s)
A
Alexander Gusev, 2021-05-10
@Anonymous5454587

On arduino there is an excellent map function and in English. , to convert ranges.

spoiler

_______________________
Математически функция 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, то она будет работать с плавающей точкой
//и соответственно изменить имя функции, что бы оно не пересекалось с родной библиотекой ардуины

_______________________

If you count in millivolts, i.e.
y = map(x, 0, 1023, 0, 5000), i.e. 1023 - corresponds to 5000 mV, i.e. 5 V.
If necessary, you can make your own on its basis, but digesting floating points. Just remember that floating points take a little longer to count than integers.

V
VT100, 2021-05-10
@VT100

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.

R
res2001, 2021-05-11
@res2001

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 question

Ask a Question

731 491 924 answers to any question