LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Samples to Read and Sample Rate while using a fast external clock

Solved!
Go to solution

Hello,

 

I'm using a NI USB-6212 to run a combustion research engine. I have a pressure transducer in the head and a rotary encoder on the crankshaft. I'm using the pulses from the Quad A channel of the rotary encoder as an external sample clock to sample the pressure with. The idea is that I want almost the same number of points in each pressure trace so that it's easy to average them together. I appear to be able to achieve this at low speeds but I'm having issues at high speed.

 

Can anyone tell me what I should have my sample rate and samples to read set at and how it effects my sampling when using an external clock? Will samples per channel have an effect on the buffer size and will that matter? When I had them set high (10-100 kHz and about 1/10*rate for the samples to read) it hardly read but as I set them lower and lower it read faster. Playing with those settings a bit seem to affect how well it samples at different speeds. The engine is spinning at 3600 RPM and my encoder puts out 2500 pulses per revolution on one channel so I'm looking at an effective sample rate of 150 kHz. However I haven't gotten the program to sample with the engine running full speed. I've hooked the encoder output up to a scope and it reads fine.

 

Is there any chance the counter filtering I see in the 621x manual is inadvertently enabled?

 

Thanks,

Xander

0 Kudos
Message 1 of 10
(2,937 Views)

Hi Xander18,  

 

Are you sampling on 2 different channels on the USB-6212? One for the pressure transducer and one for the encoder?  

Bobby Breyer
Applications Engineer
National Instruments
0 Kudos
Message 2 of 10
(2,918 Views)

No, I'm using the encoder on a PFI input as a sample clock. But that's a 400 samples/second unit so I think I should be okay with it.

0 Kudos
Message 3 of 10
(2,914 Views)

The weird thing is when I had 150k for the rate and about 1/10th that for the number of samples the encoder was entirely nonresponsive and nothing happened. I started dropping both numbers, maintaining about that ratio, down to 50 Hz and 5 samples and all of a sudden the encoder was very responsive. So I was starting to think that with each pulse of the encoder it was sampling 5 samples at 50 Hz. Then the next pulse comes along and it takes 5 more samples.

 

However, when I dropped down to 1 Hz and 1 sample it did nothing. I started playing with the numbers around there by trial and error and nothing came of it until I got back up to 50 Hz. But it still wasn't sampling at all when I was running the engine at 3600 RPM. Clearly there's a relationship here I don't understand.

0 Kudos
Message 4 of 10
(2,907 Views)

Xander,

 

Okay, I'm going to need to see a bit more of your setup.  Can you post a simplified version of your code, along with a wiring diagram showing where you're wiring your inputs to your USB-6212?  

Bobby Breyer
Applications Engineer
National Instruments
0 Kudos
Message 5 of 10
(2,900 Views)

I can post the whole thing but I'll talk a little about it. It's a producer consumer loop with a continuous analog input sample from external clock program in the producer loop. Right now the consumer loop has a simple write to spreadsheet VI in it but eventually I want to average each revolution (well, two since it's a four stroke but that's neither here nor there) of pressure traces and spit out a single curve.

 

The wiring is simple. I have a voltage supply feeding the encoder and the quadrature A input on PFI 8 of the 6212 DAQ. I also have the Z index plugged in but nothing else to it. The analog input is a BNC right to AI 0. I can make a diagram if you want one. I've scoped the rotary encoder output and it looks great, very square with small relative rise times.

0 Kudos
Message 6 of 10
(2,897 Views)
Solution
Accepted by xander18

Xander18,

 

I would suggest you move your initialization VIs outside of the while loop, along with your close DAQmx VI.  From my end, it looks like a new task is being made for each loop, which takes time.  Try that out and let me know how it goes.

 

Bobby Breyer
Applications Engineer
National Instruments
0 Kudos
Message 7 of 10
(2,885 Views)

I'll try that and report back. Any tips for what my Samples to Read or Number of Samples per Channel should be set at?

0 Kudos
Message 8 of 10
(2,881 Views)

That worked! Thanks a ton. I've been banging my head off of this code for months now.

0 Kudos
Message 9 of 10
(2,866 Views)

Xander,

 

Great! I'm happy we could resolve this issue.

Bobby Breyer
Applications Engineer
National Instruments
0 Kudos
Message 10 of 10
(2,848 Views)