LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Most efficient way to implement my own buffer

We are using a PCIe-6353

0 Kudos
Message 11 of 29
(1,289 Views)

@RaymondLo wrote:

Got it. This is the third rendition of the software in this lab. The guys before always just used tick counts or other LabView built-in software clocks. If that was good enough, I hope what I did was at least just as good time-wise. Without using real-time OS, is using the loop count to control the DO a sound strategy?


If you only have software-timed outputs, it might be the best you can do (and maybe that's good enough for your application). However, I saw your reply below that you're using a 6353, which has hardware-timed digital outputs up to 10Mhz, so you can do much, much better.


@RaymondLo wrote:

More importantly, for reading, can I count on the fact that 15,000 data points will always be exactly 1 second of data? I mean, I believe this timing is timed by the DAQ card, which promises 1M Hz of max DAQ rate, so I was hoping that the DAQ card would be more accurate than the Windows timer.


You're confusing two different concepts. The acquisition clock, which dictates how fast data is acquired and moved into a buffer, is very accurate. However, that same clock doesn't govern when data is transferred out of the buffer. When you ask to read 15 samples, you're simply waiting until there are at least 15 samples available - there could be more, if Windows was busy at the exact moment when the 15th sample was acquired. This averages out, because if there were 20 samples in the buffer when you asked for 15, then the next loop iteration you'll only have to wait for an additional 10 samples. So, the timing between samples will be accurate - 15000 data points will correspond to exactly 1s of data - but reading it in 15 point increments doesn't guarantee that the loop will run exactly once per millisecond.

 

Your PCIe-6353 supports hardware-timed digital output, meaning you can write a series of boolean values to a channel, and the board's on-board hardware will clock out those values at precise intervals. With a little more work you can almost definitely (I don't know the specific details of your board so I don't want to say certainly) synchronize the digital outputs with the analog inputs, if you need to do that.

Message 12 of 29
(1,280 Views)

Let me tell you a story about software timing.

 

A company that I worked for sold brain boxes to an uber-customer to control weapons firing.  One day this customer was testing one of the units sold to them, and lo 'n' behold, a missile (would have) fired when they pressed the chain gun trigger!  Turned out, the test used software timing (C-code with with loops that waited for x ms - sound familiar?), and this introduced jitter that was larger than the smallest pulse!  This caused an overlap in measurement that missed the tiny pulse, passing the test.  (Who dug through the code to find this?  I did!  I don't really know much about "C", but I do know a software-timed loop when I see one.)

 

Why they didn't use a signal generator of some sort is beyond me.  Fortunately, uber-customer did NOT force the company to re-test all the units over at said company's expense, although they could have.

Bill
CLD
(Mid-Level minion.)
My support system ensures that I don't look totally incompetent.
Proud to say that I've progressed beyond knowing just enough to be dangerous. I now know enough to know that I have no clue about anything at all.
Humble author of the CLAD Nugget.
Message 13 of 29
(1,279 Views)

Thanks. I think I am going to try and use the HW-timed DO since it's an option. I am not sure if the other guys in the lab care enough, but if the HW is there, I am going to try and use it.

Most of the code I have now can be kept anyway. It's just that I will be free to write to disc in 150 chunks (10ms) or even 1500 chunks (100ms), which would significantly help with CPU usage. RIght now I am constantly hitting high 70%s, which is annoying.

 

Can someone point me towards the right direction as to how to find out how to sync DO with the clock used for AI? Do I need to look for how to "DO with internal clock?" Or do i need to look for "how to DO with external clock?"

 

 

Basically, people running the experiments have a spreadsheet that specifies at which time interval to open or close which DO. I already can parse the spreadsheet into a 2D array. I need to be able to tell the PCIe-6353 to fire channels (specified by the spreadsheet) at specific times. This time needs to be in sync with the AI clock. i.e. if I need to fire DO1 at the first second, I want it to occur only with reading the 15,000th sample.

 

Thanks.

0 Kudos
Message 14 of 29
(1,268 Views)

When you use the DAQmx Timing for the digital output, one of the options for the Sample Clock should be the AI Sample Clock.  Just use that.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
Message 15 of 29
(1,266 Views)

Do I need to somehow link the Sample Clock VI of my Read process to the DO's sample clock VI? Or is it the case that if by choosing "AI Sample clock", they use the same clock. Do I put the DAQmx Write VI in its own while loop as I did with Read? Does the sampling rate control how often the DO process checks the clock? Or just simply what frequency the highs will be written at? i.e. When channel 1 is high and set at 10Hz, it will continously send 10 pulses per second? What if I simply want the signal to stay high at all times until I shut it off?

 

0 Kudos
Message 16 of 29
(1,259 Views)

@RaymondLo wrote:

Do I need to somehow link the Sample Clock VI of my Read process to the DO's sample clock VI? Or is it the case that if by choosing "AI Sample clock", they use the same clock. Do I put the DAQmx Write VI in its own while loop as I did with Read? Does the sampling rate control how often the DO process checks the clock? Or just simply what frequency the highs will be written at? i.e. When channel 1 is high and set at 10Hz, it will continously send 10 pulses per second? What if I simply want the signal to stay high at all times until I shut it off?

 


When you set the sample clock, a new digital output value will be written.  So if your sample clock is set to 10kHz and you want an output clock of 10Hz, you will need 1000 samples high and then 1000 samples low.

 

By setting the sample clock to AI Sample Clock, it will use the same clock as the analog input.

 

As far as where the DAQmx Write goes, I would have to study your architecture and requirements to give good advice.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
0 Kudos
Message 17 of 29
(1,248 Views)

Thanks. I have it set up now so that the DO is using AI Sample clock. Is there an option where I can say output this signal when the clock reaches 15000?

0 Kudos
Message 18 of 29
(1,243 Views)

@RaymondLo wrote:

Thanks. I have it set up now so that the DO is using AI Sample clock. Is there an option where I can say output this signal when the clock reaches 15000?


If for example you want to turn on after 15000 samples, you would write an array containing 15000 falses followed by a true. If I remember correctly you have a couple options about what happens when you reach the end of the buffer, including continuing to output the final value, or looping back to the beginning of the buffer. Read the DAQmx documentation to see what your options are.

0 Kudos
Message 19 of 29
(1,235 Views)

Just adding to the pile...

 

With the right hardware you can run a Timed Loop under Windows.

 

Ben

Retired Senior Automation Systems Architect with Data Science Automation LabVIEW Champion Knight of NI and Prepper LinkedIn Profile YouTube Channel
0 Kudos
Message 20 of 29
(1,229 Views)