Reading from ADCs

If you have a simple question and just want an answer.
User avatar
asid61
Active Member
Posts: 36
Joined: Sat May 31, 2014 6:39 am

Reading from ADCs

Post by asid61 »

I was wondering how fast I can read from around 20 MCP3008 ADC chips using this board. I need a ton of analog inputs, which then need some minimal processing to convert the readings to frequency, and then I need to send them via USB to a computer. How many readings can I do in 1ms, and how fast can I send the data away using the Startkit? Do I need to send it to a Raspberry Pi first?Each reading requires 3 bits to select a channel and 10 bits to get the reading, plus a couple of dummy bits. There are 8 channels per MCP3008, times 20 of these chips for 160 total 10-bit analog channels. The data sent to the computer will just be frequency readings though. They use an SPI interface with MISO, MOSI, CLK, and CS.General post:Thank you so much for any help. I can't wait to recieve my board! These things are waaaaaaay cool, especially because of the insanely low price tag. I don't even know how it costs this little.


User avatar
infiniteimprobability
XCore Legend
Posts: 1126
Joined: Thu May 27, 2010 10:08 am

Post by infiniteimprobability »

Looks like the MCP3008 can handle clocking at 3.6MHz. Those sort of rates are a piece of cake for XMOS..

Each ADC sample takes 24 bits (3 bytes) so you'll be aquiring at 150KSPS max / number of channels = 18.75Ksps per analog input per ADC

To connect 20 and read them in parallel, you could tie together the clock CS and MOSI lines (with buffers). You'd still need 20 + 3 lines...

Those lines would preferably be 1b ports because they deserialise for you - you only need to read a byte at time (nice). That would take you to dual tile (16x 1b ports per tile available), but doable on an L16 or A16..

The overall data rates are not massive so you could look at a single tile and use 5 x 4b ports to receive the data and unpack it afterwards - 3.6M nibbles/sec per port. You could deserialise to 32b inside the port so a packed 32b word at 459 Kwords per second. It would require a little bit of careful coding to unpack it efficiently, but sounds possible.

I'd say this is a fit, definitely on dual tile and probably fine on a single tile, with some clever use of ports.

So in summary, I think you can run all 20 of your ADCs at max rate with XMOS. (you may need some level shifing though because the 3008 wants 5V to run flat-out, and XMOS is 3v3 I/O).

User avatar
infiniteimprobability
XCore Legend
Posts: 1126
Joined: Thu May 27, 2010 10:08 am

Post by infiniteimprobability »

I get it - so if you run at 1Ksps then you don't need to have a big 20b parallel SPI receive. You can connect all SPIs together (MOSIs to MOSIs, SCLKs to SCLKs, MISOs to MISOs) and then enable the CSs in turn. That will likely achieve the bandwidth you want and is much simpler. You just need to connect the CSs to individual output pins on any old port from XMOS. The 5 x 4b ports will do..

My orginal idea was to read all ADCs in parallel at the same time, which would work but means writing a custom SPI module - not hard though especially for a closed system like yours. 

Your idea is simpler though and you can just use module SPI master from us.

"How fast can the 1b pins of the Startkit enable and disable the ADCs?" erm - we can toggle pins every 16ns or so flat out, so I don't think you need to worry about that!