DAQ speed problem. spi, ADC MCP3008

General project help for Adafruit customers

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
lume
 
Posts: 1
Joined: Fri May 27, 2016 12:53 pm

DAQ speed problem. spi, ADC MCP3008

Post by lume »

Hi guys, I'm new using Raspberry.

I'm trying to design a digital stethoscope using:
- 6 electret microphones (MAX4466)
- 8 channels and 10 bits ADC (MCP3008). I will use just 6 channels.
- SPI
- Raspberry pi 3B

The frequencies I want to sample are lower than 1KHz, so I connected a RC filter at each ADC input.
In order to draw the signal I read I need to sample 10 times faster than the signal I am reading, so I need to sample at 10000 KHz each channel. I thought this shouldn't be a problem, but it seems I wasn't right :(
I want to save the samples in a .csv file in order to draw the graph on the computer later.

The problem is: I can't get more than 2000 samples/s. Why?
Is it the SPI configuration or is it because I can't write on the .csv file so fast?

In order to solve the problem I was trying to get 40000 samples as fast as possible with just one microphone (it takes 20sec).
I checked if the problem was to write in the .csv file, generating values and it worked properly... So I don't know how to solve it. Is it an SPI problem?

This is my code:

Code: Select all

import time
import csv
import datetime
import random

# Import SPI library (for hardware SPI) and MCP3008 library.
import Adafruit_GPIO.SPI as SPI
import Adafruit_MCP3008

# Software SPI configuration:
CLK  = 18
MISO = 23
MOSI = 24
CS   = 25
mcp = Adafruit_MCP3008.MCP3008(clk=CLK, cs=CS, miso=MISO, mosi=MOSI)

print('press Ctrl-C to quit...')

array = []
for x in range (0,40000):
        # Read the ADC channel values in a list.
    values = [0]*8
    for i in range(1):
        # The read_adc function will get the value of the channel.
        values[i] = mcp.read_adc(i)
    array.append(values[0])

# Create a new .csv file that will contain the measurements
with open('/home/pi/Desktop/array/freqtest.csv', 'w') as csv_file:
    writer = csv.writer(csv_file)
    # Write a header row with the name of the column.
    writer.writerow(['Ch0 '])

    writer.writerow([array[:]])
Thank you in advance :)

User avatar
adafruit_support_mike
 
Posts: 67485
Joined: Thu Feb 11, 2010 2:51 pm

Re: DAQ speed problem. spi, ADC MCP3008

Post by adafruit_support_mike »

The MCP3008 only has one actual ADC. The input pins go through a multiplexer so you can select the pins you want to use for any given reading.

If you want to measure 6 signals at 10kHz, you'd need to take the sampling rate up to 60kHz total.

The MCP3008 can do that (its maximum sampling rate is 200ksps when running from a 5v supply), but you'll probably need to write your own support library. IIRC, ours just waits for a fixed time between telling the chip to start a measurement and reading the output.

Locked
Please be positive and constructive with your questions and comments.

Return to “General Project help”