Counter/Timer

cancel
Showing results for 
Search instead for 
Did you mean: 

How to configure PCI-6052E for synchronizing both an analog channel and a counter channel?

The application we use PCI-6052E is pretty straight, based on .net and C# for development.
 
One analog channel is setup to read the analog signals from PMT, and another counter channel is to count encoder outputs from motor driving the rotation stage. So, our goal is to use encoder counts to timestamping analog input data from PMT.
 
The way I did for this is described below:
 
We used the onboard internal clock for sampling the analog signals, and also use this same clock as the gate signal for activating the counter reading.
 
In C#:
 
{
.....
 
// set up the analog channel
analogInTask = new Task();
                   
analogInTask.AIChannels.CreateVoltageChannel(mcPhysicalChannel, "",
                        AITerminalConfiguration.Rse, Convert.ToDouble(mcMinValueNumeric),
                        Convert.ToDouble(mcMaxValueNumeric), AIVoltageUnits.Volts);
// use the internal clock
analogInTask.Timing.ConfigureSampleClock("", Convert.ToDouble(mcRateNumeric),
                        SampleClockActiveEdge.Rising, SampleQuantityMode.ContinuousSamples,
                        mcSamplesPerChannelNumeric);
// create the analog channel
analogInReader = new AnalogSingleChannelReader(analogInTask.Stream);
 
// rotation counter setup
tkRotCounter = new Task();
tkRotCounter.CIChannels.CreateCountEdgesChannel(counterNames[1], "",
                        edgeType, Convert.ToInt64(0), countDirection);
//
tkRotCounter.Timing.ConfigureSampleClock("/Dev1/ai/SampleClock", Convert.ToDouble(mcRateNumeric),
                        SampleClockActiveEdge.Rising, SampleQuantityMode.ContinuousSamples,
                        mcSamplesPerChannelNumeric);                  
                                       
//
RotCounterReader = new CounterReader(tkRotCounter.Stream);
 
// synchronization
analogInReader.SynchronizeCallbacks = true;
RotCounterReader.SynchronizeCallbacks = true;
// verification 
analogInTask.Control(TaskAction.Verify);
tkRotCounter.Control(TaskAction.Verify);
 
// specify callback functions 
analogCallback = new AsyncCallback(AnalogInCallback);
rotCounterCallback = new AsyncCallback(RotCounterInCallback);
 
......
}
 
Two tasks are created for analog and counter reading, and they share the same internal sampling clock (90kHz).
Two asynchronized callback funtion are used to fetch the data available from the buffer.
 
After the above configuration, we use the following C# code the start the process with a trigger signal.
 
{
...
analogInReader.BeginReadMultiSample(mcSamplesPerChannelNumeric, analogCallback, null);
RotCounterReader.BeginReadMultiSampleInt32(mcSamplesPerChannelNumeric, rotCounterCallback, null);
...
}
 
I am not sure whether the above configuration is correct or not, since it looks like we have some mismatch issues between the analog channel and the counter channel?
 
Your information is highly appreciated!
 
Thanks.
 
Daniel Xu
 
 
 
0 Kudos
Message 1 of 2
(3,740 Views)
Hello Daniel. 
 
Thank you for posting to the NI Discussion Forums. 
 
Can you please elaborate on the "mismatch issues" that you were talking about "between the analog channel and the counter channel?"  Does this mean that the acquisitions are not synchronized to your liking?  If this is the case, what type of delay are you seeing between the acquisition of the analog and the counter channels? 
 
Brian F
Applications Engineer
National Instruments
0 Kudos
Message 2 of 2
(3,715 Views)