Multifunction DAQ

cancel
Showing results for 
Search instead for 
Did you mean: 

High speed control loop

Solved!
Go to solution

Hello everyone,

 

I've got two questions, one is hardware related the other one is a software issue. As they are related I'll just post one thread.

 

Hardware:

I'm trying to solve the following task:
Generate analog ramp AO (to control an external device, the waveform won't change during operation), acquiring two AI channels synchronously. Let's assume a sample size of 800. The signals of the AI channels are processed and depending on the result a second AO output is generated (which will probably generated by a second NI-device).

The whole process should be as fast as possible, let's say 100Hz.

I checked the "SynchAI-AO" example, which seems to be what I need, but I'm not sure if the USB-621x is feasible for this purpose (I think I'll need three DMA channels, but I couldn't find any specs on that)

According to the Manual USB-621x has only one ADC, so I guess it has to switch between the channels.

So aremy following assumptions correct:

max AI/AO sample rate is 250 kS/s --> for three channels ~80 kS/s per channel. By generating/acquiring a signal with a size of 800 samples I would have a repetition rate of around 100Hz ?!

I was wondering wether the signal generating/acquiring is possible with a NI USB-621x device?

 

This leeds to my software issus:

At the moment I only have a USB 6009 device, which can't produce hardware timed AO output, thats why I need another device.

Anyways I was playing around with acquiring AI data and came up with a strange problem:

Programming language is C++ and I'm using the DAQmxRegisterEveryNSamplesEvent and the contineous mode for readout, as I think that's the fastest way to do it.

bool ni_usb::setClkTiming(double samplerate, int numberOfsamples)
{
    mSamplerate = samplerate;
    mNumberOfSamples = numberOfsamples;
DAQmxCfgSampClkTiming(mTaskHandle,"",mSamplerate,DAQmx_Val_Rising,DAQmx_Val_ContSamps, mNumberOfSamples);

DAQmxRegisterEveryNSamplesEvent(mTaskHandle,DAQmx_Val_Acquired_Into_Buffer,mNumberOfSamples,0,&ni_usb::static_callback,(void *)this);

    int n = mNumberOfSamples*mNumberOfChannels;
    mData = new float64[n];
    return true;
}

 The strange thing is, that everything works fine, as long as the number of samples is >=1000, ni_usb::static_callback function is called and the data is read out.
 If the number of samples is <1000 the callback function isn't called at all.

So usb_controller.setClkTiming(48000,1000); works but usb_controller.setClkTiming(48000,999) doesn't. Does anyone have an idea why?

Therefore I can't simulate a repetition rate of 100Hz at the moment with the USB-6009 as .setClkTiming(48000,480) doesn't work.

 

best regards and thx for any help,

Julian

0 Kudos
Message 1 of 5
(3,082 Views)

Hi Julian!

 

Unfortunately, the answer to your first question is No:

with the USB-621x you cannot perform Hardware Synchronised AI/AO. The M-Series USB Cards are not able to do so.

You would have to use a PCI or a PXI card to perform Hardware Synchronized AI/AO. (NI-62xx onwards)

You can try and use Software Synch with your AI Tasks. This works fine if you use low frecuency. The frecuency range for software synch depends on your programm and on windows.

(Given that this is programmed and not hardware configured.)

 

As for your second question: I´m working on it.

 

Best Regards!

 

NI AE Support

0 Kudos
Message 2 of 5
(3,064 Views)

Hi,

 

thank you for you reply. I'll have a look at the PCI/PXI cards!

 

Just one remark on my second question: I was not right by saying it only works with number of samples >=1000;

I was assuming that because I tried 1000 and 2000 and it worked. In the meantime I found out that it works with the following number of samples:

125, 250, 500, 1000, 2000, 4000

all other numbers I tried didn't work.

 

Also there seems to be a optimum in choosing sample size / sampling rate in order to get a high data throughput.

By choosing 48kS/s and 4000 sample size I could achieve a repetition rate of almost 12 Hz (as expected without any overheads). Whereas I get only around 15 Hz (compared to 24 Hz expected) when choosing 48kS/s and 2000 sample size. I guess this is due to overheads while read out the AI ports.

 

thank you again for your help.

Julian

 

0 Kudos
Message 3 of 5
(3,062 Views)
Solution
Accepted by topic author amarillo

Hi again,

 

I found the solution, by trying out the same with the "ContAcq-IntClk" example:

 

"

DAQmx Error: Requested Every N Samples Event Interval is not supported for the given Data Transfer Mechanism and buffer size.

To keep DMA or USB Bulk as the Data Transfer Mechanism, modify the buffer size and/or the Every N Samples Event Interval so the buffer size is an even multiple of the Every N Samples Event Interval. To keep the same Every N Samples Event Interval and buffer size, change the Data Transfer Mechanism to Interrupts if supported.
Property: DAQmx_Every N Samples Acq Into Buffer Event Interval

"

By choosing 48kS/s the buffer size was automatically set to 100kS according to the NI-DAQmx help. That's why the number stated above were working!

It was my mistake that I didn't implement a proper exception handling to my program so far.

 

best regards,

Julian

0 Kudos
Message 4 of 5
(3,056 Views)

Hi Julian!

 

I´m glad to hear that it works now!

 

Best Regards!

 

NI AE Support

0 Kudos
Message 5 of 5
(3,051 Views)