Multifunction DAQ

cancel
Showing results for 
Search instead for 
Did you mean: 

USB-6008 voltage calculation from binary data?

Hi all,


I'm using a USB-6008 device with NI-DAQmx. I'm reading the AI channels as binary data (with DAQmxReadBinaryI16 function, Single Ended mode, +/-10V), and next I want to convert these binary data to voltage scale, but I don't know how. I know, AI-resolution of this board is 11 bits, but the well known formula, which I used for 6025E before (without any problem), now gives absolutely false values.

The formula that I use:

voltage = [(reading–offset) / maxReading] * [maxVolt / (gain * gainAdjust)]

...if we clean it (no offset, gain is 1):

voltage = (reading/maxReading) * maxVolt

i.e.

voltage = (bindata/2048) * 20

but, as I wrote above, this formula gives false values. I tried some other variations (maxReading=4096, maxVolt=10, etc...), but none of them gives correct values.

Would anybody tell me, what is the correct voltage calculation for the USB-6008 device?!


- George Cs. -

Message Edited by George Cs on 12-03-2007 08:43 AM
0 Kudos
Message 1 of 16
(2,856 Views)
hi 🙂

which software do you use?
are the binary values correct?
can you upload your project?

Plamen
National Instruments Germany
Application Engineer
0 Kudos
Message 2 of 16
(2,825 Views)
Hi Plamen,

I'm using DAQmx API only.
Project is very simple: there is a smallint (i16) array which receives the actually sampled native binary data via DAQmxReadBinaryI16 function. But it's ok, if I change the amplitude of the input signals, I see the numeric changes in these values; it works fine, binary values are probably correct. Don't forget, this routine (I mean, absolutely same routine) works without any problem with 6025E (and other E series) card!!!
So the only problem is that I don't know which formula should I use to convert these values to voltage values (float), because there is no information anywhere about the format of binary data given by USB-6008...
Would you give me some information about it?...

Thanks

- George Cs -

Message Edited by George Cs on 12-05-2007 05:13 AM
0 Kudos
Message 3 of 16
(2,821 Views)
hi

There are 11 bits for the value, one for the signing and the others will be filled up with 0. this is the representation of the I16.

Plamen
National Instruments Germany
Application Engineer
0 Kudos
Message 4 of 16
(2,809 Views)

Hi,

You can programmatically get the device scaling coefficients using DAQmxGetAIDevScalingCoeff(). This returns the scaling polynomial, though in the case of a 6008 it's just an offset and a gain. The calculation should be:

voltage = reading*gain + offset

I didn't have a chance to try this out in C, I just confirmed it from LabVIEW so let me know if you run into problems implementing that scaling.

Cheers,

Andrew S

0 Kudos
Message 5 of 16
(2,802 Views)
>voltage = reading*gain + offset

In my case, gain = 1x and offset = 0, it means, voltage = reading... I'm afraid, this equation is not the appropriate solution to convert binary value to voltage...

>There are 11 bits for the value, one for the signing and the others will be filled up with 0. this is the representation of the I16.

When AI gets 0 volt (connected to GND), binary value is 0x7E20.
When AI gets 1.35 V, binary value is 0x8EC0.
It seems to me, the binary value is presented in the higher (alias MSB) 11 bits, so maybe it must be shifted to right 4(?) bits before conversion, and maybe bitmasking also necessary(?)... Or there is a big endian/little endian problem in the background?...
0 Kudos
Message 6 of 16
(2,787 Views)

Hi,

Sorry, it looks like I didn't explain that well. This KB talks more about the polynomial returned. In the case of the 6008, the scaling coefficients from DAQmxGetAIDevScalingCoeff()returned is just a first order polynomial - it just returns ao (what I refer to as offset) and a1 (gain).

I whipped up an example for the 6009 and it should work for the 6008 - I wrote the code in CVI but you should be able to use snippets for whatever ANSI C environment you are in. It wouldn't work for any device that has a higher order scaling equation (like M-Series) but might work for E-Series. Also, I'm a little rusty in C so don't make fun of my code Smiley Happy - and feel free to correct it and post back.

Cheers,

Andrew S

 

0 Kudos
Message 7 of 16
(2,760 Views)
Hi stilly32,

There is no problem with your code, but I just don't understand how can it produce correct values for you 🙂
I tried out this coefficient thing you suggested. The result is very interesting. Take a look at the little table below. The first column is the real voltage (connected to AI) the second is the calculated (from binary with coeff):

-1.62 V = -1.62 V
-1.35 V = -1.35 V
0.00 V = 0.00 V
+1.35 V = -19.49 V
+1.62 V = -19.22 V

As you can see, the negative potentials are correct, but the positive ones are not really exact... I think, this miscalculation arises from some binary overflow effect, though it's strange, because int16 is wider than 11 bits...
Any ideas?

Thanks

- George Cs -
0 Kudos
Message 8 of 16
(2,747 Views)
the error may be in the 12th bit, which is a sign bit.
the you will have different convert formulas for negativ and positiv values
National Instruments Germany
Application Engineer
0 Kudos
Message 9 of 16
(2,741 Views)
Here are the binary representations of the measured values:

-1.62 V = 0x95A0 = 10010101:10100000
-1.35 V = 0x6DA0 = 01101101:10100000
0.00 V = 0x7E20 = 01111110:00100000
+1.35 V = 0x8EC0 = 10001110:11000000
+1.62 V = 0x9200 = 10010010:00000000

12th bit is always zero. Maybe the 11th bit is the sign bit.
But how is it that this conversion works fine for stilly32?!... 😮
0 Kudos
Message 10 of 16
(2,731 Views)