Measurement Studio for .NET Languages

cancel
Showing results for 
Search instead for 
Did you mean: 

Resolution Question

Ok here goes I am using a USB-6255 to take some analog measurements, this device has a resolution of 16 bits in which I am getting some white noise.  I would like to reduce the amount of resolution to 12 bits since I really don't quite need 16 bits and want to see if it will help with some of the noise.

 

I see methods for getting the resolution but how do you set it?  Do I need to open the Min and Max of the measurement?  My thoughts here are that a larger window will make each bit have a higher value.  Basically I am in taking measurements between -.5V and .5V, and values like 0.00103033586680347 contain too much noise.  I really only need about 8 decimal places and could just use Math.Round(value,8) but if I change scales later I think this would be wrong, while if I change resolution I won't have to use Round.

 

Any ideas?

 

While I do not think it will mater much for what I am asking below is a sample of how I have setup to take data in from the 6255:

 

 

//Declare some variables for taking data
NationalInstruments.DAQmx.Task;
AsyncCallback analogCallback;
AnalogMultiChannelReader someTaskReader;


private void InitDAQAndTakeReadings()
{
    someTask = new Task();

    someTask.AIChannels.CreateVoltageChannel("Dev1/ai0","Channel 1", AITerminalConfiguration.Differential, -10, 10, AIVoltageUnits.Volts);

    //Take about 20 Sec. worth of data
    someTask.Timing.ConfigureSampleClock("", 540,
                            SampleClockActiveEdge.Rising, SampleQuantityMode.FiniteSamples, 11000);

    someTask.Control(TaskAction.Verify);

    omeTaskReader = new AnalogMultiChannelReader(someTask.Stream);

    analogCallback = new AsyncCallback(AnalogInCallback);

    someTaskReader.SynchronizeCallbacks = true;

    someTaskReader.BeginReadWaveform(, analogCallback, myTask);
}

private void AnalogInCallback(IAsyncResult ar)
{
    try
    {
        AnalogWaveform<double>[] waveForms= someTaskReader.EndReadWaveform(ar);
        
        foreach (AnalogWaveform<double> waveForm in waveForms)
        {
            //Do some data storage for later analysis             
        }
    }
    catch(DaqException exception)
    {   
        //Handle error 
        MessageBox.Show(exception.Message);
        someTask = null;
        someTask .Dispose();
    }
}

 

liek below 

 

 

0 Kudos
Message 1 of 7
(3,752 Views)

Maybe I can phrase it a little different and that will help.

 

I want to take measurements with a 6255(which is 16 Bit) and use only 12 bits worth of resolution.  What needs to be done or what is the best way to do this?

0 Kudos
Message 2 of 7
(3,715 Views)

Hello,

 

There is no way to change the resolution of the Digital to Analog Converter (DAC) on the Data Acquisition board from 16-bits to 12-bits.  The resolution of the steps depends on the range of the card.  For the 6133, valid ranges are ±10, 5, 2.5, and 1.25V.  Each range uses the same 16-bit DAC for the steps to the measurement.  To display or record data with less significant digits would require some function or algorithm like you mention.  For each resolution, you can have a case structure which uses the round function to round so many digits based on the resolution you are at.  For instance, round 8 places for ranges ±1.25V, 10 places for 2.5V, and so on. 

Kyle A.
National Instruments
Senior Applications Engineer
0 Kudos
Message 3 of 7
(3,712 Views)

Thanks for the response. 

 

Do you mean the 6123? I thought the 6133 was 14 bit.

 

I also have a question on the second part of the answer would the decimals increase as the range increases? 
 
I was thinking along the lines of ±1.25V would be 2.5/((2^16-1)-1)= 2.5/32767 = .00007629|6273689992980742820520645772 and ±2.5V would be 5/32767 = .00015259254737998596148564104129154.
So wouldn't the lower/lesser range have more resolution since the range is not as spread out resulting in a finer result?
 
Also I think I figured out a way to reduce the bits, I figured someone may benefit from the code as I have not seen anything like it posted anywhere, but this still leaves the extra decimals I am wanting to eliminate so I will still need to round to X number of decimal places either way and would prefer to do so with more bits of resolution than less. 
private void AnalogInCallback(IAsyncResult ar)
{
    try
    {
         if (runningTask.Equals(ar.AsyncState))
         {
    
             // Read the available data from the channels
             unscaledData = analogUnscaledReader.EndReadInt32(ar);
             
             //Now loop through the channels do extract data                           
             //Can use the following 
             //for (int channel = 0; channel < myTask.AIChannels.Count; channel++)
             //or
             for (int channel = 0; channel < unscaledData.Length; channel++)
             {
                 //load the calibration coefficeints for the channel being used.  
                 //***Note these values can be used to get a scaled calibrated result using a polynomial formula listed below
                 double[] ai0CoeffVals = myTask.AIChannels[channel].DeviceScalingCoefficients;
          
                 //Now loop through the data for the channel   
                 for (int dataReading = 0; dataReading < unscaledData.GetLength(1); dataReading++) 
                 {	
		   //For 16 bit you should have 2 byte array 1 for each 8 bits
		   byte[] tempByte = BitConverter.GetBytes(unscaledDataValue);

		   //convert the byte array to a BitArray for easier bitwies operations	
      	            BitArray tempBitArray = new BitArray(tempByte);

                     //And the converted BitArray by a BitArray with the mask wanted in this case 12 bits.
		   tempBitArray.And(new BitArray(new byte[] { 15, 255, 0, 0 }));

		   //Convert this value back to the byte array
		   tempBitArray.CopyTo(tempByte, 0);

		   //now convert it back to the int value
		   int unscaledDataValueMasked = BitConverter.ToInt32(tempByte, 0);
                     
                     //Scale the data using the calibrated values for the channel used.
                     //scale the data that was converted to 12 bits 
                     double scaledMaskedData = ai0CoeffVals[0] +
                                              (ai0CoeffVals[1] * unscaledDataValueMasked) +
                                              (ai0CoeffVals[2] * (unscaledDataValueMasked ^ 2)) +
                                              (ai0CoeffVals[3] * (unscaledDataValueMasked ^ 3));
 
                     //scale the original value for comparison
                     double scaledData = ai0CoeffVals[0] + 
                                        (ai0CoeffVals[1] * unscaledDataReading) + 
                                        (ai0CoeffVals[2] * (unscaledDataReading ^ 2)) + 
                                        (ai0CoeffVals[3] * (unscaledDataReading ^ 3));

                     //Convert data to a reading using scalling without calibration. 
                     //***Note a model could be made and calibration could be achieved that way.
                     double calcScaledMaskedData = (unscaledDataValueMasked / (Math.Pow(2, 18 - 1) - 1)) *
                                                   ((double)(maximumValueNumeric.Value - minimumValueNumeric.Value));

                     //scaled original value for comparison
                     double calcScaledData = (unscaledDataReading / (Math.Pow(2, 18 - 1) - 1)) *
                                             ((double)(maximumValueNumeric.Value - minimumValueNumeric.Value));
                }
            }
        }
    }
    catch(DaqException exception)
    {  
      //Handle error however you want or add some info and rethrow.
    }
}

 

 
Later

 

0 Kudos
Message 4 of 7
(3,703 Views)

Also forgot to note the above was done for a resolution of 18 bits thus the EndReadInt32 and the use of int[,] instead of short[,] for the retrieved data values.  I am sure that looking at the scaleing formula that that would stick out though, just as the fact that this is also written for a ± value thus the 18-1 for resolution.

0 Kudos
Message 5 of 7
(3,702 Views)

I think I see two errors in my logic as I am assuming that 1 bit is used for the sign of the data and it looks as if NI uses the full 16 bits or 18 in the case of my formula.   So the scaling part should look like:

 

double calcScaledMaskedData = (unscaledDataValueMasked / (Math.Pow(2, 18) - 1)) *
                              ((double)(maximumValueNumeric.Value - minimumValueNumeric.Value));
double calcScaledData = (unscaledDataReading / (Math.Pow(2, 18) - 1)) *
                        ((double)(maximumValueNumeric.Value - minimumValueNumeric.Value));

 

I was looking over the spec for the 6255 and realized that I was trying to figure out why the value was off when I ran the example above and that explains it.

 

0 Kudos
Message 6 of 7
(3,700 Views)

Hello,

 

Yes, I apologize, the 6255 has different ranges than the 6133, I have a lot of numbers on my mind apparently Smiley Happy

 

For resolution, you will have finer range with lower voltage ranges.  The less range you have, the finer the DAC can be tuned to detect smaller changes in voltage.  The board specifications manual gives more information pertaining to the accuracy of the measurement and sensitivity. 

Kyle A.
National Instruments
Senior Applications Engineer
0 Kudos
Message 7 of 7
(3,677 Views)