04-29-2017 07:45 PM - edited 04-29-2017 07:51 PM
Hi,
I'm using the NI USB-6212 and I'm trying to convert an analog signal to digital in real-time using some code I found online, found here (also attached):
The sample rate appears to be limited to 1000Hz, anything above 5000Hz and I get the Error -200279 after a few seconds. I would like to acquire the analog input at 50KHz.
I've read the NI Knowledge Base from here: http://digital.ni.com/public.nsf/allkb/AB7D4CA85967804586257380006F0E62
but I'm still confused how to approach this problem. Do I need to set up a producer/consumer design or is there any other way around this?
Thanks,
W
Solved! Go to Solution.
04-29-2017 07:49 PM - edited 04-29-2017 07:50 PM
(deleted)
04-29-2017 08:43 PM
The code you attached (and the example you cited) seem weird to me. I would have expected another algorithm to create the Digital Output (something like "Convert the voltage to a U16 or I16 number, then convert number to array of bits, and write the array to a Port). But the broader question is why are you getting the error?
I recommend forgetting about the Digital Out part and just write a (very small, very simple) VI that produces single A/D values at 1KHz. How are you configuing the DAQmx code? Are you using a MAX Task? What are the parameters? It should be possible to have a loop that runs at 1KHz, outputting one numeric (voltage) values per loop from a single-point A/D read, should be able to continue for weeks without failing. But it is failing for you, suggesting that there's a problem in the DAQ Analog Input code.
Bob Schor
04-30-2017 12:30 PM - edited 04-30-2017 12:31 PM
Hi Bob,
I should note that this is being used for an optical encoder. The input is light intensity (voltage) which produces a spike at ~10Hz. The spike has a shape to it, which I would like to convert to a rectangular pulse. The only output I need is either a 0 or a 1 indicating if the light intensity is low or high, respectively. I hope that clarifies why there is not another algorithm to convert to U16 or I16 (if I understood the first part of your response correctly).
I'm still new to LabVIEW, by "configuring the DAQmx code", do you mean how I am inputting the parameters? I've done it directly in LabVIEW, I did not use MAX Task. It is possible to run at 1KHz, in which it converts a sine wave to a rectangular wave. The Error -200279 only occurs when I set the Sample Rate on the Analog Input to 5KHz or above, then the error occurs after ~3 seconds. I think the problem is at higher sampling rates, the buffer is filling up and overwriting itself. So the issue might be somewhere downstream? Is there something in the While Loop that has a default setting of 1KHz? Because if I sample outside the While Loop at 5KHz, then the processes inside the While Loop won't be able to keep up. Please let me know if my understanding is incorrect.
Thanks,
W
04-30-2017 01:29 PM
Hi Bob,
I should add that the application of this code is for an optical encoder, so the only output I need are 0 and 1 for low light intensity (low AI voltage) and high light intensity (high AI voltage), respectively. (The analog input "spikes" have a shape to it, and I would like to convert that shape to a rectangular pulse.) That is why there is not another algorithm to convert the voltage to a U16 or I16 number.
I am still new to LabVIEW, when you say "configuring the DAQmx code", are you referring to where the parameters are input? If so, all the parameters are selected directly in LabVIEW at the front panel, I did not use MAX Task. The code has worked for converting a sine wave (10Hz) to a rectangular pulse when sampling at 1KHz. If I increase to 5KHz, I get Error -200279 after ~3 seconds. I can delay this error by increasing the samples per channel (I believe this increases the buffer size?), but it still occurs after ~10 seconds. This suggests to me something downstream is causing the error. I think the buffer is filling up faster than the data is processed and output, but I don't know to fix this.
Thanks,
W
04-30-2017 01:44 PM
You are only reading 1 sample at a time, so acquiring at 5kHz means everything in that loop has to occur at faster than 0.2 msec in order to keep up. You are relying on software timing and it just won't.
You should try accumulating all the samples that you can using N samples, do processing on the arrays, and output the digital output using hardware timing.
04-30-2017 05:09 PM
Moreover, with an optical encoder as a sensor, you'd be far better off with a counter input task in the first place. Look at examples related to counter input and position measurement.
-Kevin P