juranga
Posts: 183
Joined: Fri Nov 06, 2015 11:39 am
Location: Basque Country

Read analog inputs at 4kHz

Wed Feb 15, 2017 8:07 am

I need to read 4 analog sensors at 4kHz rate. I have never used the raspberry pi at this rate so I do not know if this would be possible or if I will have to change to another board, microcontroler, FPGA...

Is it possible to achieve this rates with an embedded linux board like raspberry?

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

Re: Read analog inputs at 4kHz

Wed Feb 15, 2017 9:01 am

That should be fine. The standard Linux SPI driver handles about 20k reads per second (Pi3 70k). Four x 4k is 16k so you should have some spare.

juranga
Posts: 183
Joined: Fri Nov 06, 2015 11:39 am
Location: Basque Country

Re: Read analog inputs at 4kHz

Wed Feb 15, 2017 9:26 am

What do you mean with standard Linux SPI driver? Do I need to use SPI in order to read analog data at this rate?

I thought that just using read analog with would be enough? Any link or information would be really appreciated!

User avatar
rpdom
Posts: 14686
Joined: Sun May 06, 2012 5:17 am
Location: Chelmsford, Essex, UK

Re: Read analog inputs at 4kHz

Wed Feb 15, 2017 9:29 am

juranga wrote:I thought that just using read analog with would be enough?
The Raspberry Pi doesn't have any analogue inputs. You need to use an external a2d chip.

BMS Doug
Posts: 3824
Joined: Thu Mar 27, 2014 2:42 pm
Location: London, UK

Re: Read analog inputs at 4kHz

Wed Feb 15, 2017 9:33 am

The raspberry Pi does not have any Analogue inputs, so you will need another device to convert the analogue inputs into digital signals and communicate those to the pi.

The ADC (Analogue to Digital Converter) you choose will probably need to connect via SPI in order to achieve the read rate you desire (you would need to confirm that your chosen ADC is also capable of the same read rate).
Doug.
Building Management Systems Engineer.

juranga
Posts: 183
Joined: Fri Nov 06, 2015 11:39 am
Location: Basque Country

Re: Read analog inputs at 4kHz

Wed Feb 15, 2017 10:17 am

Great answers! I thought that RPi had analog inputs! Really thanks for your answer!

juranga
Posts: 183
Joined: Fri Nov 06, 2015 11:39 am
Location: Basque Country

Re: Read analog inputs at 4kHz

Wed Feb 15, 2017 10:48 am

Another question.

Using 4 ADCs at 4KHz using SPI. As joan said "The standard Linux SPI driver handles about 20k reads per second (Pi3 70k). Four x 4k is 16k so you should have some spare". So I guess that CPU would not have almost any free time to do other tasks. For example, filter data, do some analysis, sending through wireless communication filtered data, etc...

BMS Doug
Posts: 3824
Joined: Thu Mar 27, 2014 2:42 pm
Location: London, UK

Re: Read analog inputs at 4kHz

Wed Feb 15, 2017 11:13 am

juranga wrote:Another question.

Using 4 ADCs at 4KHz using SPI. As joan said "The standard Linux SPI driver handles about 20k reads per second (Pi3 70k). Four x 4k is 16k so you should have some spare". So I guess that CPU would not have almost any free time to do other tasks. For example, filter data, do some analysis, sending through wireless communication filtered data, etc...
I think you would be able to do that with a Pi3, Quad core 1.2GHz processor.
Doug.
Building Management Systems Engineer.

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

Re: Read analog inputs at 4kHz

Wed Feb 15, 2017 11:16 am

juranga wrote:Another question.

Using 4 ADCs at 4KHz using SPI. As joan said "The standard Linux SPI driver handles about 20k reads per second (Pi3 70k). Four x 4k is 16k so you should have some spare". So I guess that CPU would not have almost any free time to do other tasks. For example, filter data, do some analysis, sending through wireless communication filtered data, etc...
You will have to test. I don't know what is limiting the SPI driver transaction rate, I don't think it is CPU bound. I think you will be fine.

juranga
Posts: 183
Joined: Fri Nov 06, 2015 11:39 am
Location: Basque Country

Re: Read analog inputs at 4kHz

Thu Feb 16, 2017 7:42 am

That's great! Thank you for your answers!

I am going to take advantage of your wisdom and ask another question :oops: :oops:
You have said that it may be possible (I would have to test) to achieve what I said with the RPi 3. Would be easier to achieve the same thing using another embedded linux platform (i.e. industrial embedded board)?

I mean, Raspbery Pi 3 is quite powerful, so I do not know if using another board would help me to achieve better performance. Maybe having a 4 channel ADC integrated in the board will make it easier (I do not know).

Other solution would be using a FPGA, I guess that an FPGA could easily handle this requirements.


This is a little of-topic but I am very interested in study different alternatives and I have seen that you you both know about this.
Many thanks in advance!!

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

Re: Read analog inputs at 4kHz

Thu Feb 16, 2017 8:54 am

juranga wrote:That's great! Thank you for your answers!

I am going to take advantage of your wisdom and ask another question :oops: :oops:
You have said that it may be possible (I would have to test) to achieve what I said with the RPi 3. Would be easier to achieve the same thing using another embedded linux platform (i.e. industrial embedded board)?
...
I'd be surprised if any model Pi couldn't handle your requirements (as so far stated).

jahboater
Posts: 4585
Joined: Wed Feb 04, 2015 6:38 pm

Re: Read analog inputs at 4kHz

Thu Feb 16, 2017 10:57 am

juranga wrote:Would be easier to achieve the same thing using another embedded linux platform (i.e. industrial embedded board)?
The Odroid-C2 has two 10-bit ADC's in the GPIO. I have no idea how fast they are though.

User avatar
[email protected]
Posts: 2020
Joined: Tue Feb 07, 2012 2:14 pm
Location: Devon, UK
Contact: Website

Re: Read analog inputs at 4kHz

Thu Feb 16, 2017 2:12 pm

juranga wrote:I need to read 4 analog sensors at 4kHz rate. I have never used the raspberry pi at this rate so I do not know if this would be possible or if I will have to change to another board, microcontroler, FPGA...

Is it possible to achieve this rates with an embedded linux board like raspberry?
It may be possible, but you've not said what device you're sampling. This video is sampling at just over 8Khz over the SPI bus, and playing it back at the same rate (via an extremely crude interface on a Pi v1 almost exactly 4 years ago...)

https://www.youtube.com/watch?v=uSCBj6rabIU

I really DO NOT recommend using the Pi's SPI interface for audio though. There are far far better ways of doing audio.

-Gordon
--
Gordons projects: https://projects.drogon.net/

juranga
Posts: 183
Joined: Fri Nov 06, 2015 11:39 am
Location: Basque Country

Re: Read analog inputs at 4kHz

Fri Feb 17, 2017 7:18 am

It would be an accelerometer. So I would not be as demanding as audio.

User avatar
Pekka
Posts: 20
Joined: Mon Nov 19, 2012 4:11 pm

Re: Read analog inputs at 4kHz

Mon Feb 20, 2017 5:47 am

This might provide a start:
viewtopic.php?f=37&t=170122

Return to “C/C++”