From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

Multifunction DAQ

cancel
Showing results for 
Search instead for 
Did you mean: 

Sampling frequency with DAQmx in .NET

Solved!
Go to solution

I am making my first application with DAQmx and .NET and have an issue with setting sampling frequency.

 

The setup is

Rack: 9188

Slot1: 9237

Slot2: 9237

Slot3: 3201

Slot4: 9421

 

My idea was that all channels are set up as global channels in NI MAX. In this way a channel can be configured with the right custom scaling and test run in MAX.

 

The .NET program then creates a Task, and adds the right channels to it (the _channels object is just a container for all objects):

Dim analogTask As New DAQmx.Task
_channels.analogTask = analogTask
_channels.LoadChannel = analogTask.AddGlobalChannel(config.loadChannelName)
_channels.TorqueChannel = analogTask.AddGlobalChannel(config.torqueChannelName)
_channels.TransverseForceChannel = analogTask.AddGlobalChannel(config.transversalForceChannelName)
_channels.TransversePosChannel = analogTask.AddGlobalChannel(config.transversalPosChannelName)

LoadChannel, TorqueChannel and TransverseForceChannel are Bridge type channels with custom scaling. The TransversePosChannel is Voltage type, also with custom scaling.

 

The sample clock is then configured and task is verified:

analogTask.Timing.ConfigureSampleClock(String.Empty, config.frequencyHz, _
    DAQmx.SampleClockActiveEdge.Rising, DAQmx.SampleQuantityMode.ContinuousSamples, config.frequencyHz)

analogTask.Control(DAQmx.TaskAction.Verify)

I then create an AnalogMultiChannelReader and a callback. NUM_SAMPLES_PER_READ is 500.

_analogReader = New DAQmx.AnalogMultiChannelReader(_analogTask.Stream)
_analogCallback = New AsyncCallback(AddressOf AnalogInCallback)

_analogReader.SynchronizeCallbacks = True _runAnalogSampling = True _analogReader.BeginReadWaveform(NUM_SAMPLES_PER_READ, _analogCallback, _analogTask)

 The callback looks something like this:

 

Private Sub AnalogInCallback(ByVal ar As IAsyncResult)
	Try
		Dim timeLoadData() As measuredData

		If ar.AsyncState Is _analogTask Then
			_daqData = _analogReader.EndReadWaveform(ar)
                         ... ... ...
... ... ... beginAnalogRead() End If Catch ex As Exception Try stopAllTasks() Finally RaiseEvent ErrorOccurred(Me, "DAQChannels.AnalogInCallback: " & ex.Message) End Try End Try End Sub

The issue is that the sampling frequency seems to be about 1.6 kHz no matter what I set in the ConfigureSampleClock call.

I have verified that 500 samples are returned at each call to the AnalogInCallback, but it is always called about three times / sec no matter what freqyency I have set.

 

I might have missed something obvious, but right now I am kind of stuck so I'd really appreciate your help here.

 

Linus Nilsson
0 Kudos
Message 1 of 3
(3,457 Views)
Solution
Accepted by topic author LinusN

Hello LinusM,

 

 

I do not see anything wrong with your code.

 

But please find the supported sampling rates for 9237 here:

http://digital.ni.com/public.nsf/allkb/593CC07F76B1405A862570DE005F6836

 

As you can see, minimum sampling rate is 1.6kS/s.

 

Can you please verify whether or not you are seeing the issue for higher sampling rates as well? For example @ 25 kS/s?

 

Thanks

 

Regards,

Christopher

Message 2 of 3
(3,411 Views)

Hi

 

Just as I expected the answer was incredibly simple! I kind of knew I missed something vital there.

Well, the solution is simple; I'll just run at 2kHz and discard 3 out of 4 samples.

 

Thank you!

Linus Nilsson
0 Kudos
Message 3 of 3
(3,407 Views)