# Is it possible to find the current sampling rate of MCP3008? [closed]

I am using MCP3008 with Raspberrypi Model B. MCP3008 is sampling the analog signal. But is there any way through which I can verify if it is correct or not. For example, I need a sampling rate of 1.5 kHz, so I read the sample every 666 us. But then I am not sure how to verify the number of samples it has acquired in one second.

## closed as unclear what you're asking by Milliways, Aurora0001, Dmitry Grigoryev, Darth Vader♦Sep 28 '18 at 13:11

Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.

• If you take a sample at a rate of 1.5 kHz, why do you need to verify how many you get in 1 second? – Dmitry Grigoryev Sep 25 '18 at 13:06

By current sampling rate I assume you mean the number of samples taken in the last second.

Take a time-stamp as you take a sample and increment a sample count. If the number of seconds in the time stamp is different from the previous number of seconds then display and then zero the sample count.

An example follows.

``````#!/usr/bin/env python

import time

second = int(time.time())
sample = 0

def bump_sample():
global second, sample
now = int(time.time())
sample += 1
if now != second:
print("{} samples/second".format(sample))
sample = 0
second = now

while True:
bump_sample()
time.sleep(0.0001)
``````

A good approach would be to ditch the delay functions inside Python (probably that's what's you on), inside Linux (means that you just hope for the operating system to be time-accurate, and it never is critically accurate). Exploit hardware interrupts which are super-well defined if used correctly. You will set an interrupt to occur and trigger your sampling period; take an idea from here:

https://www.socallinuxexpo.org/sites/default/files/presentations/Steven_Doran_SCALE_13x.pdf

keep in mind the conversion time that any ADC needs to deliver a sample and the maximum sampling rate which you can have based on your Vcc on the ADC pin (https://cdn-shop.adafruit.com/datasheets/MCP3008.pdf).