salte
Posts: 8
Joined: Wed Apr 27, 2016 9:50 am

How to compute voltage?

Mon May 02, 2016 8:07 am

I have a raspberry with unipi and by using a voltmeter I read that the voltage going in is 3.3 volt.

I use the raspberry to read the voltage from the unipi and I get 9504 as a 16 bit value.

The maximum voltage is 10.0 volt and the coefficient in EEPROM is 5.5475526.

So how do I get from 9504 to 3.3 volt? I would guess that the reading is a linear reading so that
the maximum value of 65535 would equal some voltage and so 9504 is 14 percent of that max voltage
but this doesn't get me near 3.3. At least not with a maximum of 10.0 voltage

3.3/10 * 65535 does not equal 9504. Also, such a simple calculation do not make use of the value read from EEPROM which apparently you need to adjust the value properly.

I don't know _how_ that adjustment is done. I don't know what other factors play a part in this
measurement and I am currently at a loss.

I could say the voltage is 9504 / 65536 * 5.5475526 * 4.101 but I have no idea where that coefficient 4.101 comes from. So I am at a loss as to how to interpret the value from the ADC. What am I doing wrong here and how do I get it straight?

When I read, there is also some bits to indicate some factor x1, x2, and so on, I currently have it at x1 is that what is wrong? Should I have it at some other setting instead? What determines which factor I should use?

User avatar
alexeames
Forum Moderator
Forum Moderator
Posts: 2874
Joined: Sat Mar 03, 2012 11:57 am
Location: UK
Contact: Website

Re: How to compute voltage?

Mon May 02, 2016 12:17 pm

Never heard of unipi, so no idea what chip is on it.

Often, an ADC chip will have a pin for Vref or reference voltage. If you can find out what that's connected to, you know what it's being measured against.

So if Vref was connected to 5V, your ADC reading of a 3V3 input should be 3.3/5 * 65535 = 43253
Alex Eames RasPi.TV, RasP.iO

pksato
Posts: 295
Joined: Fri Aug 03, 2012 5:25 pm
Location: Brazil

Re: How to compute voltage?

Mon May 02, 2016 12:57 pm

Hi,
UniPi documentation not mention how read voltage.
Have a text to read resistance, but need to know voltage.
From MCP3422 documentation.
At 16bits, and VI- connected to GND (positive reading), and 1x gain.
Vread=(Vmax/32767)*read
(10/326767)*9504=2.900V
12% of error.
What is the coefficient stored to eeprom? A reference Voltage?
5.5475526 is very close to halt of 10V, assuming that is it.
Vread=((5.5475526*2)/32767)*read
(11.0951052/32767)*9504=3.219V
97.54% of nominal 3.3V.
I suggest to build a table with voltage read by unipi and a multimeter. Use a potentiometer as voltage divider or a variable power supply to get a input voltage.
If reading voltage is negative (VI+<VI-, or VI+ connected to GND), replace 32767 for 32768, add a - sign. Check MSB bit to see if reading is negative.

salte
Posts: 8
Joined: Wed Apr 27, 2016 9:50 am

Re: How to compute voltage?

Tue May 03, 2016 11:16 am

Why you multiply the reference voltage by 2?

Also, thank you for notifying me about the divide by 32767 - I have used 65535 but as the voltage can be both + or - it is a signed value and so it makes sense to divide by 32767 instead.

beta-tester
Posts: 1412
Joined: Fri Jan 04, 2013 1:57 pm
Location: de_DE

Re: How to compute voltage?

Tue May 03, 2016 11:44 am

is nothing written on their web page about how to calculate and taking the EEPROM coefficient into account?
or ask them in their forum
http://unipi.technology/

http://unipi.technology/wp-content/uplo ... ual_en.pdf
Analog Inputs UniPi features two analog 0-10V input channels (via the MCP3422, address 0x68) marked as AI1 and AI2. Each channel has its own + and – (e.g. AI1+ and AI1-). The + connector expects positive voltage from the connected device and – expects the negative pole (the GND). The guaranteed accuracy is 5% however 1% is commonly reachable. To correctly calculate the input voltage, a coefficient of the resistor divider has to be taken into account. The coefficient of each channel is saved in EEPROM as single precision binary floating point format binary32 (IEEE 754). Before version 1.1 the coefficient is not saved in the EEPROM and thus must be calculated during conversion in software (Typically the value is around 5.56). See chapter EEPROM for more details.
there must be a resitor divider, that divides the input voltage i think. in the datasheet of the ADC it seems the Vref is a fixed voltage (2.048V)

so normally the ADC can only handle a voltage from 0..2.048V
to be able to handle 0..10V, there must be a voltage divider to divide the input range down to 0..2.048V.
in ideal case 10V / 2.048V = 4.8828125, but the divider is not an ideal one (e.g. because resistors have tolerances and resistors are not available in all values - i can not see a pot so it must be fixed value resistors) and the manufacturer of UniPi was measured that the real factor is 5.5475526 and wrote that value to the EEPROM.
so there is a delta between ideal and reality. 5.5475526 instead of 4.8828125.

assuming, that i am not talking absolutely bullshit, then the input resistor divider of your UniPi divides the 10V range by a measured factor of 5.5475526.
then at 10V input, the voltage on the input of ADC is only 1.8025967V instead of 2.048V. so at 10V you don't have the assumed max binar code for (2.048 Vref)
that you have to take into account.
Last edited by beta-tester on Wed May 04, 2016 6:05 am, edited 2 times in total.
{ I only give negative feedback }
RPi B (256MB), B (512MB), B+, ZeroW; 2B; 3B, 3B+; 4B (4GB)

salte
Posts: 8
Joined: Wed Apr 27, 2016 9:50 am

Re: How to compute voltage?

Tue May 03, 2016 12:51 pm

What you say appear to make a lot of sense. I am just trying to translate this into a formula I can use.

I read 9504 and if you divide that by the maximum possible value of 32767.0 you get a fraction.

Ideally if you multiply this fraction then with 2.048 V you get the actual measured voltage but this has been divided down by the divider so I need to multiply it by the factor of 5.5475526 as well to get the voltage. Have I got that right? so the formula is:

u * 2.048 * 5.5475526 / 32767.0 where u is the read value?
This gives me: 3.2953 or 3.3 V

So it appears to work - thank you so much.

beta-tester
Posts: 1412
Joined: Fri Jan 04, 2013 1:57 pm
Location: de_DE

Re: How to compute voltage?

Tue May 03, 2016 1:42 pm

known fixed values (datasheet/EEPROM):
Vref = 2.048V
total_bits = 16bit
coefficient = 5.5475526

for the ADC:
V_per_bit = (Vref / ((total_bits - 1bit) -1))
V_per_bit = (2.048V / (15bit -1)) # 16bit - 1bit for +/- signum (polarity)
V_per_bit = (2.048V / (2^15 -1))
V_per_bit = (2.048V / (32768-1)) # -1 because of range 0..32767 = 32768 values
V_per_bit = (2.048V / 32767)

binary_value * V_per_bit = V_at_ADC
binary_value * (2.048V / 32767) = V_at_ADC

for the resistor voltage divider in front of the ADC:
V_at_input / coefficient = V_at_ADC

all combined:
binary_value * V_per_bit = V_at_input / coefficient
binary_value * V_per_bit * coefficient = V_at_input
binary_value * (2.048V/32767) * coefficient = V_at_input
binary_value * (2.048V/32767) * 5.5475526 = V_at_input

looks pretty much like your formular... :o ;)
{ I only give negative feedback }
RPi B (256MB), B (512MB), B+, ZeroW; 2B; 3B, 3B+; 4B (4GB)

pksato
Posts: 295
Joined: Fri Aug 03, 2012 5:25 pm
Location: Brazil

Re: How to compute voltage?

Tue May 03, 2016 8:18 pm

Hi,
Voltage divider coefficient make more sense.
I forgot it to analyze from voltage divider perspective.
Now, on my equation, is not times 2, is times 2.048. :)

Return to “General discussion”