Multifunction DAQ

cancel
Showing results for 
Search instead for 
Did you mean: 

DAQ Drifting problem using C#

Hi All

 

I am wondering if it is possible to help. I'm using Ni-PCI-6229 Card but i am having trouble acquiring the data as it seems to be drifting (As seen in the attached file. The drift doesnt seem like a lot but over a period of time it makes a big difference).

 

The code is as follows

SetUpAIChannels is the setup of the card

ThreadLogData     is the thread called by the program

LoadDataEvent     is the event called when the buffer is full

 

Also i am inputting a 20Hz clock which i have checked on the ossilliscope.

 

Thank you in advance

 

 

 

class Common_DataThread
{
private Task continuousTask = new Task();
private AnalogMultiChannelReader reader;
private AsyncCallback LoadDataCall;


private void SetUpAIChannels(out Task ContTask)
{
//Used for determining which channels have been output too
List<int> lclDisplayedChannels = new List<int>();
//Create Task
Task lclContinuousTask = new Task();
//Create ai channel
AIChannel tempAIChannel;


for (int i = 0; i < Inter_DataInterface.GetNumberOfChannels(); i++)
{
try
{
if (Inter_DataInterface.DisplayTraceList(i) || Inter_DataInterface.EnabledList(i) || Inter_DataInterface.LogDataList(i))
{
//Setup channel if it is either displayed, logged or alarm is enabled
tempAIChannel = lclContinuousTask.AIChannels.CreateVoltageChannel(
DataLoggerV4.Properties.Settings.Default.DeviceUsed + "/" + Inter_DataInterface.ChannelList(i),
"Voltage " + System.Convert.ToString(i),
DataLoggerV4.Properties.Settings.Default.TerminalConfiguration, //E.g NRSE , RSE , Diff
-10,
10,
AIVoltageUnits.Volts);

lclDisplayedChannels.Add(i);
}
}
catch (DaqException)
{ }

 

//Only AI0 is active

}
// For this example only AI0 is used


//configure DAQ
lclContinuousTask.Timing.ConfigureSampleClock(
"", // external clock source line or use "" for internal clock
100000,// expected rate of external clock or actual rate of internal clock
SampleClockActiveEdge.Rising, // acquire on rising or falling edge of ticks
SampleQuantityMode.ContinuousSamples, // continuous or finite samples
5000 // number of finite samples to acquire or used for buffer size if continuous
);


//Check it is working
lclContinuousTask.Start();
//Stop task
lclContinuousTask.Stop();
//Set task to memory
continuousTask = lclContinuousTask;
//Set Number of displayed channels
DisplayedChannels = lclDisplayedChannels;
}


public void ThreadLogData()
{

try
{

continuousTask.Start();
reader = new AnalogMultiChannelReader(continuousTask.Stream);
reader.SynchronizeCallbacks = true;
LoadDataCall = new AsyncCallback(LoadDataEvent);


if (LoopStop == false)
{
LoopStop = Inter_ThreadInterface.GetStop();
reader.BeginReadWaveform((Convert.ToInt32(continuousTask.Timing.SamplesPerChannel)), LoadDataCall, continuousTask);
}

}
catch (DaqException ex)
{
MessageBox.Show(ex.Message);
continuousTask.Dispose();



}


void LoadDataEvent(IAsyncResult ar)
{
Boolean NewFile;

try
{
AnalogWaveform<double>[] DataCollection;
// End waveform a write all 
DataCollection = reader.EndReadWaveform(ar);

//im reading using this function
DataCollection[0].GetRawData();


if (Inter_ThreadInterface.GetStop() == false)
{
reader.BeginReadWaveform(Convert.ToInt32(continuousTask.Timing.SamplesPerChannel), LoadDataCall, continuousTask);
}
else
{
continuousTask.Stop();
if (!(null == file))
{file.Close();}
}
}
catch
{
// continuousTask.Stop();
if (!(null == file))
{ file.Close(); }

}
}

 


}

0 Kudos
Message 1 of 5
(4,310 Views)

Is the analog input open ?

Have you tested it with a shortcuted input?

 

Sounds like an open input and not path for the bias current.

 

Greetings from Germany
Henrik

LV since v3.1

“ground” is a convenient fantasy

'˙˙˙˙uıɐƃɐ lɐıp puɐ °06 ǝuoɥd ɹnoʎ uɹnʇ ǝsɐǝld 'ʎɹɐuıƃɐɯı sı pǝlɐıp ǝʌɐɥ noʎ ɹǝqɯnu ǝɥʇ'


0 Kudos
Message 2 of 5
(4,290 Views)
Have you tested the acquisition in MAX?

My c# skills are rudimentary but it seems you are not specifying the termination (rse, diff). Do you know what the default is for the device. Explicitly set it if you don't. You seem to have also set it to internal clock so what it's the point of the external signal?
Message 3 of 5
(4,288 Views)

Hi Dennis 

 

We have tried the signal in ni max and the log was very accurate 

 

The terminal configuration and device used is set as so:

 

tempAIChannel = lclContinuousTask.AIChannels.CreateVoltageChannel(
DataLoggerV4.Properties.Settings.Default.DeviceUsed + "/" + Inter_DataInterface.ChannelList(i),
"Voltage " + System.Convert.ToString(i),
DataLoggerV4.Properties.Settings.Default.TerminalConfiguration, //E.g NRSE , RSE , Diff
-10,
10,
AIVoltageUnits.Volts);

lclDisplayedChannels.Add(i);
}

 

 

We are using the internal clock because at points we select multiple channels and need to read from them.

0 Kudos
Message 4 of 5
(4,272 Views)

Hi Henrik

 

The source is not open it is connected to a callibrated source which has been checked with a callibrated ocilliscope. 

 

We are measuring voltage RSE or Differential and we are using a BNC-2090 series

 

Regards 

 

Chris 

0 Kudos
Message 5 of 5
(4,271 Views)