egyptiandude
Posts: 19
Joined: Wed Jul 17, 2013 11:29 pm

High speed data acquisition AND real time processing

Wed Jul 17, 2013 11:34 pm

Hi everyone, I am very new to the raspberry pi and am looking to acquire analog data at a very fast rate ( > 20 Ksps) and subsequently process it and write it to a text file. I have a high speed ADC that connects via SPI, however, I have thusfar been unable to find a method to implement this that would give me the speed I need (e.g. first I found that python was to slow, but when I looked into C, then issues with the SPI overhead came in to limit the sampling rate to 8000sps). Is there any way to make this happen? Also, I am using raspian and an overclocked pi to 900 Mhz.

Thank you for any help!

-Egyptiandude

User avatar
elektrknight
Posts: 140
Joined: Sat Mar 02, 2013 1:25 pm

Re: High speed data acquisition AND real time processing

Thu Jul 18, 2013 2:00 pm

SPI overhead came in to limit the sampling rate to 8000sps
That is quite slow, what ADC are you using?
Placek Malinowy to jest to!

egyptiandude
Posts: 19
Joined: Wed Jul 17, 2013 11:29 pm

Re: High speed data acquisition AND real time processing

Thu Jul 18, 2013 2:22 pm

LTC 2315 5 Msps, 12 bit resolution

User avatar
elektrknight
Posts: 140
Joined: Sat Mar 02, 2013 1:25 pm

Re: High speed data acquisition AND real time processing

Thu Jul 18, 2013 2:41 pm

That is a fast chip, and can not a problem.
What C code are you using to talk to it?
Placek Malinowy to jest to!

DaveTheWalker
Posts: 36
Joined: Wed Jul 04, 2012 9:06 pm

Re: High speed data acquisition AND real time processing

Thu Jul 18, 2013 3:02 pm

You might consider a Guzunty CPLD to take some of the SPI overhead off the main processor...

PiGraham
Posts: 3568
Joined: Fri Jun 07, 2013 12:37 pm
Location: Waterlooville

Re: High speed data acquisition AND real time processing

Thu Jul 18, 2013 3:11 pm

TFTFB seems to manage to write image data at 3.5MB/s over SPI to an LCD.

320*240 pixel LCD 16 bit colour runs 23 fps while doing software decode of h264 video file (mplayer) from SD card.

I think the clock runs at 32 MHz for that.

25KHz should be no problem.

User avatar
elektrknight
Posts: 140
Joined: Sat Mar 02, 2013 1:25 pm

Re: High speed data acquisition AND real time processing

Thu Jul 18, 2013 3:14 pm

Guzunty CPLD or similar approach is probably the only way to utilize 5 Msps but he should be able to do 20 Ksps just fine without any other hardware support. Looks like strictly software issue.
Placek Malinowy to jest to!

DaveTheWalker
Posts: 36
Joined: Wed Jul 04, 2012 9:06 pm

Re: High speed data acquisition AND real time processing

Thu Jul 18, 2013 3:37 pm

good call Elektrknight ;) Still, everyone has an upgrade in mind for the future, right?!

User avatar
elektrknight
Posts: 140
Joined: Sat Mar 02, 2013 1:25 pm

Re: High speed data acquisition AND real time processing

Thu Jul 18, 2013 6:05 pm

everyone has an upgrade in mind for the future
Absolutely! Just do it in steps, first get the 20 Ksps going then go fast, real fast :-) But overclocking poor Pi to get 8 Ksps is pretty lame. Anyway, LTC2315-12 looks like a nice chip I need source it somewhere, it will be a perfect match for my Guzunty.
Placek Malinowy to jest to!

egyptiandude
Posts: 19
Joined: Wed Jul 17, 2013 11:29 pm

Re: High speed data acquisition AND real time processing

Thu Jul 18, 2013 7:46 pm

Hey guys thanks for such an awesome response. I'll look into the Fpga. Right now I'm just using a modified version of the spidev_test.c to acquire data from the adc. Am I going about this the wrong way?

DaveTheWalker
Posts: 36
Joined: Wed Jul 04, 2012 9:06 pm

Re: High speed data acquisition AND real time processing

Mon Jul 22, 2013 9:45 am

elektrknight wrote:Anyway, LTC2315-12 looks like a nice chip I need source it somewhere
http://uk.farnell.com/linear-technology ... LTC2315-12

Farnell have an evaluation board, which might be a nice way to get into testing with this chip.

If you're outside the UK, Digikey also have it:

http://www.digikey.com/product-search/e ... LTC2315-12

egyptiandude
Posts: 19
Joined: Wed Jul 17, 2013 11:29 pm

Re: High speed data acquisition AND real time processing

Wed Aug 07, 2013 5:34 pm

I figure I might as well update this forum with happening since its posting! First of all, thank you guys again for the response; here are my results:

I was able to get the fastest transfer speeds using the bcm2835 library's SPI feature (after, I went through the bcm2835.c file and removed all the 10us delays)... about 40 Ksps in total = 20 Ksps per chip select. This was 2x as fast as using the wiringPi equivalent OR using a modified version of spidev_test, which utilizes ioctl() to manage transfers.

The central part of the code was as follows:

**note, the values were stored into a buffer and then dumped every 1000 iterations into 2 separate text files using a for loop and fprintf. The above sampling rates INCLUDE all of the overhead due to signal processing, post processing GPIO usage (powering an LED, etc.), writing to two files, and segmenting the data into 500 ms blocks via the gettimeofday() function (9999 was printed in the files to denote the beginning of a 500 ms block). Therefore, for anyone who uses this method, >20Ksps is definitely achievable with minimal extra code.

Code: Select all


    /*initialize all buffers and variables above*/ 
while(1){
    if (!bcm2835_init())
       return 1;

    bcm2835_spi_begin();
    bcm2835_spi_setBitOrder(BCM2835_SPI_BIT_ORDER_MSBFIRST);      // The default
    bcm2835_spi_setDataMode(BCM2835_SPI_MODE0);                   // The default
    bcm2835_spi_setClockDivider(BCM2835_SPI_CLOCK_DIVIDER_4); // The default
    bcm2835_spi_chipSelect(BCM2835_SPI_CS0);                      // The default
    bcm2835_spi_setChipSelectPolarity(BCM2835_SPI_CS0, LOW);      // the default

//acquire data from first input 0_0
        bcm2835_spi_chipSelect(BCM2835_SPI_CS0);
        bcm2835_spi_transfern(buf, sizeof(buf));
        /*incoming stream consists of 14 bits, MSB first. 2 setup bits followed by the 12 bit digital input. Following bits are garbage.*/
        uint16_t received = ((uint16_t)buf[0] << 8) | (uint16_t)buf[1];
        received = received >> 3;
        rx_buffer[counter] = received;

        //acquire data from second input 0_1
        bcm2835_spi_chipSelect(BCM2835_SPI_CS1);
        bcm2835_spi_transfern(buf, sizeof(buf));
        /*incoming stream consists of 14 bits, MSB first. 2 setup bits followed by the 12 bit digital input. Following bits are garbage.*/
        uint16_t received2 = ((uint16_t)buf[0] << 8) | (uint16_t)buf[1];
        received2 = received2 >> 3;
        rx_buffer2[counter] = received2;
}
Feel free to PM me if anyone has questions regarding the timing, file writing, or modification of the bcm2835 file.

cheers,
Egyptiandude

Vick45
Posts: 1
Joined: Fri Dec 13, 2013 11:56 pm

Re: High speed data acquisition AND real time processing

Mon Dec 16, 2013 8:25 am

Hello,
I am doing something really similar and am new to C and Raspberry Pi. Could you post the code that reads it from the buffers and into the text files?
It will be very much appreciated!
Thanks

minnesotandude
Posts: 3
Joined: Mon Apr 17, 2017 3:38 am

Re: High speed data acquisition AND real time processing

Tue Apr 18, 2017 3:43 am

I too am wondering if the driver can be posted in full, or at least guidance given. I'm not sure how to write the buffer, don't we need access to the kernel? I'm also trying to have Simulink read from the buffer to do an FFT and windowing on it.

User avatar
joan
Posts: 14096
Joined: Thu Jul 05, 2012 5:09 pm
Location: UK

Re: High speed data acquisition AND real time processing

Tue Apr 18, 2017 7:59 am

minnesotandude wrote:I too am wondering if the driver can be posted in full, or at least guidance given. I'm not sure how to write the buffer, don't we need access to the kernel? I'm also trying to have Simulink read from the buffer to do an FFT and windowing on it.
The last post is quite old. They have probably all moved on. If you have a particular question it may be best to start a new post.

Return to “Other projects”