LabVIEW Interface for Arduino Discussions

cancel
Showing results for 
Search instead for 
Did you mean: 

How to have a sample rate over 10khz with arduino mega 2560 and labview?

I'm working in a project with arduino mega and labview, I need to use it like a acquisition card, but I need a minimun sample rate of 10Khz, when I tried to overcome 5Khz, the signal in scope was distorted (example continuous sample -LIFA). Is possible have a sample rate of 10Khz with arduino? How I could do that?.

thanks!

0 Kudos
Message 1 of 5
(26,568 Views)

Hey gabrielo91,

It is possible to sample that fast with an Arduino and LabVIEW, but it doesn't really fit with the way the LabVIEW Interface for Arduino works.  In order to get this to work you would basically have to re-write the majority of LIFA or just start from scratch and creat your own interface between LabVIEW and the Arduino. 

You would probably be better off getting a proper DAQ device.  If you're looking for low cost check out the NI-6009 http://sine.ni.com/nips/cds/view/p/lang/en/nid/201987

If you're a student or in academia the myDAQ is better option: http://www.ni.com/mydaq/ or the myRIO if you prefer something embedded (you can LV on the myRIO, Program the FPGA on myRIO using LV, and use myRIO as an embedded Linux device).  http://www.ni.com/myrio/

-Sam K

LIFA Developer

Message 2 of 5
(11,601 Views)

Hi Sammy! Thanks for your response, I know about myDAQ (its great!), but it is a student project and is necessary that I develop the entire tool. I suppose that I will start from scratch the labview-arduino interface. Any advice, tip or bibliography before begin?

Again, Thanks so much!

0 Kudos
Message 3 of 5
(11,601 Views)

You're going to have trouble hitting that rate with an Arduino.  The ADCs (analog to digital converters) on the ATMEL328 on the arduino uno have a theoretical maximum sample rate of something like 100KHz (I don't recall the exact rate, but lets just say: fast enough).

So lets say we sample at 10 KHz with a 10 bit ADC.  This means we get 10,000 * 10 bits of data per second 100K/8 = 12.5KB (Kilo Bytes, not bits) per second.  The ATMEL 328 on an arduino uno has 2 KB of RAM which means we could fill the total ram on the microcontroller every .16 seconds.  The take away here is we cannot buffer much data on the Arduino.

Now lets look at the interface.  The Arduino Uno does serial over USB using another ATMEL 328 (or an FTDI on older boards).  There is some buffering and other stuff that is going to slow down your throughput but lets say you run at a baud rate of 115200 (or 115200 bits per second).  At 10KHz and 10 bits per sample we would need to transfer 100,000 bits per second, which is just under that limit, however the baud rate of 115200 does guarantee a throughput of 115200 bits per second, you have to take into acount start and stop bits, bus collisions since we are using USB (a non deterministic bus), and much more.  In addition there are things on the Arduino that are going to take some amount of time, preventing us from transfering at our maximum rate.  For example the time it takes for the ADC to settle, the time to get the data from the ADC register to SRAM then from SRAM to the UART send buffer, etc.

So now you start to see why proper DAQ devices, especially those with many channels, fast sample rates and high sample resolutions can get quite expensive.

Now for some suggestions:

The serial over USB and small amount of RAM are going to be limiting factors.  I recommend using something like the chipKIT Max32.  It has 128K of RAM (64 times more than the Arduino Uno).  This will allow you to buffer more samples on the device before sending chunks of data to LabVIEW.  The Max32 also gives you the option of using 'USB for Serial' (it's in the board type selection box in MPIDE).  This allows you to use the Arduino style serial API, but instead of actually transfering serial data to another chip and then that chip converting the data to USB packets and sending them, it uses the USB device controller on the PIC32 microcontroller that all of your code is running on.  This allows you to get much faster speeds because you are no longer actually sending RS232 style serial data and can take advantage of the extra speed USB provides.

As for the code, I would try to use interrupts to trigger an A to D conversion at regular intervals (say .1mS if you want 10KHz).  Store each sample in a circular buffer (wikipedia if you don't know what this is).  The buffer will need a pointer to the next sample to send and the next slot to store data in.  When you're program is not interrupted for a sample it should be piping as much data out over USB as possible but try to do it in large chunks rather than a byte at time.  USB sends data in packets and a byte a time will result in many packets even if the packet payload could contain many more bytes.

It might be a good idea to lower the sample resolution to 8 bits so you don't have to mess with byte packing.  For example if you have a 10 bit sample you have to send 2 full bytes, or pack data together to send the 8 LSb of the first sample, then the second byte with the 2 MSb of the first sample the the 6 LSb of the next sample.  This packing takes time on the uController but saves time on the transfer.  You'll have to play around with this and see what rates you're actually able to hit.

On the LabVIEW side you'll get an array of numbers.  You can easily build these into a wave form by adding a T0 and DT (there is a build waveform vi, I don't recall exactly what it's called) and then display it on a waveform graph.

If you want to get fancy you could also have an interrupt for receive data that allows you to send a packet with a new DT (time between samples).  This would allow you to change the sample rate on the fly.

If you're project is to build a DAQ device you can certainly make a simple one using an Arduino (or better yet a chipKIT).  However if you're project is to build some other system and the DAQ piece is just a small component of the larger system it is well worth buying a cheap DAQ device to save yourself the time it will take to build it from scratch.

Sorry for the massive post, but I'm going off the grid for a few days so it had to be one massive brain dump.  Good luck, let us know how it goes.

-Sam K

LIFA Developer

www.labviewhacker.com

Google Plus

Message 4 of 5
(11,601 Views)

Using the approach given this web page you can get 50 KHz.

<https://www.inkling.com/read/arduino-cookbook-michael-margolis-2nd/chapter-18/recipe-18-9>

This web page says 100 KHz when logging to a SD card.

<http://forums.adafruit.com/viewtopic.php?f=31&t=30557>

This web page says 5 million samples per second when using an external ADC.

<http://hackaday.com/2013/07/08/arduino-oscilloscope-at-five-megasamples-per-second/>

For detailed information from Atmel see.

<http://www.atmel.com/dyn/resources/prod_documents/DOC2559.pdf>

Hrh1818

0 Kudos
Message 5 of 5
(11,601 Views)