Multifunction DAQ

cancel
Showing results for 
Search instead for 
Did you mean: 

Reading wrong voltage on USB-6009 when reading multiple channels

I am using a USB-6009 device with NI-DAQmx Base 2.1.0

I have a control loop where I read 4 analog inputs once, and then do some processing on them, change the analog outputs, and then repeat. I have simplified my code and listed it below. I have encountered a problem where I will occasionally read the wrong voltages. In a loop of 200 times, I will get wrong voltage readings 0-6 times out of 200. I have the following voltages connected to AI0:3 : 0.5, 1.8, 6.9, 2.75. I read those voltages correctly most of the time, but sometimes I will get a reading like: 1.80, 6.90, 2.75, 2.75.

I tried changing my code so that I only read AI0, and changed arraySizeInSamps to 1, and when I do that I *always* read the correct voltage of 0.5 for AI0. It's only when I read multiple channels that I occasionally get wrong readings.


{
    int i;
    
    // Task parameters
    int32       error = 0;
    TaskHandle  inTaskHandle = 0;    
    char        errBuff[2048]={'\0'};
    
    // Channel parameters
    char        chan[128]={'\0'};
    float64     min = 0.0;
    float64     max = 5.0;    
    
    // Data write parameters
    float64     timeout = 10.0;
    // Data read parameters
    float64     data[4];    
    int32       numSampsPerChan = 1;    
    uInt32      arraySizeInSamps = 4;
    int32       pointsRead;    
    

    sprintf(chan,"Dev1/ai0:3");
    DAQmxErrChk (DAQmxBaseCreateTask("",&inTaskHandle));
    min = -10.0;
    max = 10.0;
    DAQmxErrChk (DAQmxBaseCreateAIVoltageChan (inTaskHandle, chan, "", DAQmx_Val_Diff, min, max, DAQmx_Val_Volts, NULL));    
    DAQmxErrChk (DAQmxBaseStartTask(inTaskHandle));
    
    for (i=0; i < 200; i++)
    {
        DAQmxErrChk (DAQmxBaseReadAnalogF64(inTaskHandle,numSampsPerChan,timeout,DAQmx_Val_GroupByScanNumber,data,arraySizeInSamps,&pointsRead,NULL));
    NSLog(@"---> %.2f, %.2f, %.2f, %.2f", data[0], data[1], data[2], data[3]);

        /*** Do some processing here based on data[] ***/
    }
    NSLog(@"** DONE read %d samples **", i);

Error:
    if( DAQmxFailed(error) )
        DAQmxBaseGetExtendedErrorInfo(errBuff,2048);
    if( inTaskHandle!=0 ) {
        DAQmxBaseStopTask(inTaskHandle);
        DAQmxBaseClearTask(inTaskHandle);
    }
    if( DAQmxFailed(error) )
        printf("DAQmxBase Error: %s\n",errBuff);

}
0 Kudos
Message 1 of 9
(4,210 Views)
I did some more tests and found that this bug also happens when I do mutiple reads per channel. In the case below, when I read each input channel 1,000 times I get bad reads 1.0 % to 1.5 % of the time (these percentages hold true if I increase the number of reads to 10,000 or 100,000).


{
    int i;
    
    // Task parameters
    int32       error = 0;
    TaskHandle  inTaskHandle = 0;    
    char        errBuff[2048]={'\0'};
    
    // Channel parameters
    char        chan[128]={'\0'};
    float64     min = -10.0;
    float64     max = 10.0;    
    
    // Data write parameters
    float64     timeout = 10.0;
    // Data read parameters
    int32        counter = 0;
    int32        numChannels = 4;
    float64     *data;    
    int32       numSampsPerChan = 1000;
    uInt32      arraySizeInSamps;
    int32       pointsRead;    
    
    data = (float64 *)malloc(sizeof(float64)*numSampsPerChan*numChannels);
    arraySizeInSamps = numSampsPerChan*numChannels;
   
    sprintf(chan,"Dev1/ai0:3");
    DAQmxErrChk (DAQmxBaseCreateTask("",&inTaskHandle));
    DAQmxErrChk (DAQmxBaseCreateAIVoltageChan (inTaskHandle, chan, "", DAQmx_Val_Diff, min, max, DAQmx_Val_Volts, NULL));    
    DAQmxErrChk (DAQmxBaseStartTask(inTaskHandle));
    
    DAQmxErrChk (DAQmxBaseReadAnalogF64(inTaskHandle,numSampsPerChan,timeout,DAQmx_Val_GroupByScanNumber,data,arraySizeInSamps,&pointsRead,NULL));
    for(i=0; i < arraySizeInSamps; i+= numChannels)
    {
        if((data[i] > 0.55) || (data[i] < 0.45)) // Input voltage is a steady 0.5 V
            counter++;
    }
    NSLog(@"***************** Counted %d misreads on ai0 (%.1f %%) *************", counter, 100*(counter/(float)numSampsPerChan));

Error:
    if( DAQmxFailed(error) )
        DAQmxBaseGetExtendedErrorInfo(errBuff,2048);
    if( inTaskHandle!=0 ) {
        DAQmxBaseStopTask(inTaskHandle);
        DAQmxBaseClearTask(inTaskHandle);
    }
    if( DAQmxFailed(error) )
        printf("DAQmxBase Error: %s\n",errBuff);
}
0 Kudos
Message 2 of 9
(4,197 Views)
Another update: I verified the bug using nidatalogger.app, see attachment.

Anyone?
0 Kudos
Message 3 of 9
(4,194 Views)
Hi thricedaily,

This is very strange behavior that you are seeing with your USB-6009.  I have been unable to reproduce this so far with my testing (using DAQmxBase 2.1).  For your testing, are you using a benchtop power supply to provide the voltages for the various channels on your device?  If so, have you verified that this power supply is not the culprit in supplying voltages that switch on its own output channels?  Does this behavior exist when you configure 2, 3, or greater than 4 channels?  Do you have all of the channels configured as differential inputs?

Regards,
Andrew W
National Instruments

0 Kudos
Message 4 of 9
(4,169 Views)
I was originally using a benchtop power supply.  To eliminate that as the culprit I just re-ran the test with a 9 V battery connected to AI0+/- differential, and a AA 1.5 V battery connected to AI1+/- differential. I see the same problem with just two channels, see attachment. I have also tried this using RSE inputs, and 2, 3, or 4 channels, and get the same results. And I just tried running Dev1/ai0:7 and get the same results as well.

Message Edited by thricedaily on 01-30-2007 06:18 PM

0 Kudos
Message 5 of 9
(4,165 Views)
I hooked up one of my USB-6009 devices to a Windows box (and I believe the firmware was switched to NI-DAQmx) and ran a test panel and did not see this bug. So it seems like it is something with NI-DAQmx Base. Now I need to figure out how to revert back to the Base firmware.
0 Kudos
Message 6 of 9
(4,159 Views)
To switch back to NI-DAQmx Base from NI-DAQmx, you will need to have both drivers installed on the system.  Please refer to the KnowledgeBase article here that provides steps for switching between the two different drivers.

After the DAQmx Base firmware has been reloaded on your device, let us know if you still see the voltage swapping behavior.

Regards,
Andrew W
0 Kudos
Message 7 of 9
(4,143 Views)
Problem solved.

My two USB-6009 devices must have shipped with a bad version of the driver. After I connected them to a Windows computer and switched back and forth between NI-DAQmx and NI-DAQmx Base (version 2.1) the bug went away. Unfortunately I updated the firmware on both the devices before checking to see what the original firmware version was. I thought that I read somewhere on this forum that someone had a USB6008/9 that had shipped with a bad driver also. Is there a Changelog that details bug fixes in the different versions of NI-DAQmx Base?
0 Kudos
Message 8 of 9
(4,140 Views)
There have been no firmware changes in any of the versions of the NI-DAQmx Base drivers, so there is only one version of DAQmx Base firmware.  It is possible that the USB-6009 did not have its DAQmx Base firmware loaded correctly, and refreshing it was a good step to take.  The best place to see what has been added in new driver revisions is the readme located on the driver download page.

Regards,
Andrew W
0 Kudos
Message 9 of 9
(4,129 Views)