Real-Time Measurement and Control

cancel
Showing results for 
Search instead for 
Did you mean: 

Reducing period below 1 ms in a timed while loop

 

Hello,

 

I've been asked to increase the sample rate from 200 Hz to 3000 Hz of TDMS data written to a real-time VI. Above 1000 Hz I have a problem with the data becoming scrambled - timestamps logged out of order. I've tracked the problem to a timed while loop. I've attached a screenshot of the back panel where data is read from the NI-9205 on the Real-time cRIO-9144. A timed while loop is used to control how fast the data is read. Above 1000 Hz sample rate, the period (dt) is rounded to either 1 or 0 because the Terminal Data Type of dt is 64-bit integer. Thus at a sample rate of 3000 Hz, for example, the dt = 0.33333 ms, but this is rounded to 0 in I64 representation. I could possibly replace the timed while loop with a regular while loop but how can I control the period to a fraction of a millisecond?

 

Can you please offer any suggestions how I can overcome this problem to use a sample rate of 3000 Hz? Please let me know if you need more information.

 

Regards,

Bill

0 Kudos
Message 1 of 2
(5,608 Views)

Hi Bill,

 

I recommend you take a step back before continuing with the current approach.  

 

If you're using the 9144 EtherCAT slave chassis to access the 9205 channels via the Scan Engine, the maximum scan rate is a function of the EtherCAT master, the number of EtherCAT slaves, I/O modules, and I/O channels.  For example, if you're using the cRIO-9074 as the EtherCAT master, and you have one chassis of 9205 channels, the minimum cycle time has been benchmarked at 2.99ms (334Hz).

 

In other words, it wouldn't be possible to achieve 3KHz in this configuration.  I recommend you take a look at White Paper 10596: Benchmarks for the NI 9144 EtherCAT Slave Chassis for a basic understanding of EtherCAT I/O and to determine if your hardware can meet the new requirement.

 

Assuming your EtherCAT master and IO count can meet the new requirement (and the rest of the application supports this), then there are several techniques to build the waveform.  You can continue to use the Timed Loop synchronized to the Scan Engine (configure the engine to run at 3KHz).  Instead of wiring the calculated period to the dt terminal, use a constant 1.  This means iterate the loop once per tic of the scan engine.  You'll want to keep an eye on the Finished Late terminal on the left data node to determine if the loop is keeping up with the requested rate.

 

(By the way, the units of dt are with respect to the loop timing source, so if you had selected the 1MHz clock, you'd wire 333 into the terminal for a loop rate of 3003Hz).

 

Another option is to use the Synchronize to Scan Engine VI in a regular While Loop.  If you want to prioritize the acquisition, you can set the VI priority accordingly, but by the looks of things you'll have to change other parts of the code.  See the Caution in the help.

 

Regards,

 

Steve K

0 Kudos
Message 2 of 2
(5,599 Views)