Real-Time Measurement and Control

cancel
Showing results for 
Search instead for 
Did you mean: 

slowing down the loop rate

I have written this VI. It is looped at the rate of 100ms per loop. I'd like to slow it down, but when I change the number In the loop timer
the program will run for a short period of time and then shut it self off. I receive no error messages.
My question is how can I slow this loop down and my VI will continue to run.
I'm attaching a snap shot of my VI.
0 Kudos
Message 1 of 5
(3,414 Views)
Hello. 
 
Thank you for posting to the NI Discussion Forums. 
 
The reason that your program is stopping is because an error is occuring at the DAQ Assistant if you slow down the loop execution.  To prove this, I created an indicator off of the error out terminal of the DAQ Assistant.  This indicator was populated with the error -200279 when I ran the program with a loop delay of 10000 ms.  This error means "Attempted to read samples that are no longer available. The requested sample was previously available, but has since been overwritten.  Increasing the buffer size, reading the data more frequently, or specifying a fixed number of samples to read instead of reading all available samples might correct the problem." 
 
So, basically, the loop is iterating too slowly to process all of the data that has been acquired by your DAQ Assistant.  This data is placed in a buffer, but the buffer is only so big.  Once this buffer is full, other useful data will get overwritten in the buffer, which then spawns this error.  I would recommend adjusting the rate at which you read samples from your DAQ card if you wish to increase the delay in the loop.  Also, if your application requires a fast acquisition, with a slow loop iteration, you could increase the buffer size, which would delay the problem only temporarily. 
 
So, the best question at this point is, why do you need the loop to execute slower?  There may be another architecture that we could implement that would better fit your applications needs. 
 
Brian F
Applications Engineer
National Instruments
0 Kudos
Message 2 of 5
(3,397 Views)
I need to slow down the loop because my solid state relays have a rated life. I don't need for them to turn on and off as fast as they do at the 100 ms rate. I have tried to slow the sample rate down but  I have the same resultes. I can run this if I choose the run Continusly button, but I would really like to fix the problem.
0 Kudos
Message 3 of 5
(3,383 Views)
I think there may be some confusion as to what is actually occuring in your program. Below is a short summary of what is going on:
 
1) The DAQ Assistant is configured to automatically (in hardware) acquire data at a rate of 1 kHz. Because you don't know exactly how frequently you will be pulling the data points into LabVIEW, by setting Samples to Read you are allocating a 100 point buffer in RAM. Note that at a rate of 1 kHz, storing 100 points means that you can hold 0.1 seconds of data total. Attempting to check the buffer less frequently than 0.1 seconds will cause a buffer overflow error.
 
2) The DAQmx Write in your loop is configured for software timing. This means that you want to output only one sample per loop iteration.
 
3) A loop timer sets (roughly) the rate of your loop. Note that Windows can switch between tasks (anti-virus, LabVIEW, MS Word, etc) so it is impossible to say whether the delay will be 0.1 seconds, 0.099 seconds, or 0.012 seconds. Any of these are possible, which is the reason that you are buffering the DAQ Assistant analog input data.
 
It sounds like you wish to update your relays at a slower rate, which means that (as currently programmed), you need to increase the loop delay from 100 ms to something larger. But, when you do this you receive an error that says your DAQ Assistant buffer is overflowing! This is because your analog input buffer can only hold 0.1 seconds of data as programmed.
 
This can be fixed fairly easily. If you are simply attempting to collect analog data at 1 kHz all of the time and output digital data at a much slower rate, you can adjust the Number of Samples to Read on the DAQ Assistant to a larger value. For example, if you wish to output digital data every 1 second, and constantly input analog data at 1 kHz, you can set the Number of Samples to Read to a value of 1000 points. Since the DAQ Assistant continuous read is a blocking call (we must wait until the Number of Samples to Read are available), there is no need for a time delay in your loop; you can delete this.
 
If you wish to grab only the first 100 data points at 1 kHz after a digital output (e.g. every 1 second), you should use the N sample mode instead of continuous acquisition.
 
I hope this helps!
 
Casey Weltzin
Applications Engineer
National Instruments
0 Kudos
Message 4 of 5
(3,372 Views)
Thanks,
 That did the trick. now my relays don't turn on and off at such a high rate.
0 Kudos
Message 5 of 5
(3,361 Views)