Measurement Studio for .NET Languages

cancel
Showing results for 
Search instead for 
Did you mean: 

Drift

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 1
(4,999 Views)