Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

higher sample rate #15

Open
ChironeX1976 opened this issue Jul 23, 2023 · 16 comments
Open

higher sample rate #15

ChironeX1976 opened this issue Jul 23, 2023 · 16 comments

Comments

@ChironeX1976
Copy link

ChironeX1976 commented Jul 23, 2023

Hello,
i was wondering how i can get a higher sample rate when reading a sensor. I use a Raspberry Pi with 8 gig RAM. CPU is set at 1200 Mhz. I am using the ADC-device to capture sound, so i need at least 20.000 samples per second.
When i run the by waveshare provided Main.py - TEST_ADC1_RATE at 38400SPS, the output is:

    - ID Read success 
    - REG_MODE2 success
    - REG_REFMUX success
    - REG_MODE0 success
    - REG_MODE1 success
    - SPS-setting: ADS1263_38400SPS
    - ...start and endtime= 1690130018.1033027 1690130018.8256269
    - ...elapsed time for 5000 samples= 0.7223241329193115
    - SPS-result singlechannelfrequency =  6922.100165464822

As you can see, i want 38400 samples per second and i get approx. 7000 samples per second.

Attached, also a plot of 10 seconds of audiosignal-recording. 10 seconds * 38400 SPS should be 384.000 points of data. The horizontal axis shows only 80.000 points.

What am i doing wrong?

Thanks for any advice.

Kris
Figure_1

@mahdiaslanimk
Copy link

Roughly the same problem here. @ChironeX1976 did you found any solutions?

@ChironeX1976
Copy link
Author

ChironeX1976 commented Dec 18, 2023 via email

@mahdiaslanimk
Copy link

mahdiaslanimk commented Dec 18, 2023

@ChironeX1976 Read the FAQ in this link. There you can find the reason of low sps and an example code with higher rate (in both c an python). Hope this helps.

@E-wallace0001
Copy link

E-wallace0001 commented May 23, 2024

I have just had a look at the c implementation on the pi zero2 W

Firstly, there are some optimizations you can do for the SPI communications; You can request multiple bytes from the lower level librarys, instead of going back and forth asking for each byte at a time. This will gain you approx 1KHz straight off.

Secondly, the clock is set to 1MHz, changing this will get you a much higher sampling rate. The clocks are hardcoded. BCM driver needs to set a clock divider, while the wiringpi, and dev lib need to be set. My clock seems to top out at 22MHz. This can be configured in /lib/config/dev_config.c under DEV_module_init.

With the above changes, 35KHz can be achieved with wiring pi.

I was a little bit surprised that not requesting the status bytes actually slowed down the sampling rate.

I feel a better interface to the underlying libraries would be beneficial.

Hope this helps.

@brendanwallison
Copy link

Hello, I was looking at buying this ADC for audio as well. I have a very basic question about the 38400 SPS. If you plug in multiple microphones, would the sample rate be divided by the number of microphones, or is this a per-channel figure?

@schwebke
Copy link

on my Raspberry Pi Zero 2 W I was able to speed up the python solution from 6.275 SPS to 20.500 SPS -- in case someone wants to give it try for more testing:
https://github.com/schwebke/High-Pricision_AD_HAT

@bibhu223
Copy link

Did anyone use Pi 5 for this ADC ? I am not able to run this with C as well as python .. because it doesn't have bcm2835 ...can anyone help me.

@mahdiaslanimk
Copy link

@bibhu223 to use the python library for RPi 5 do the following:

  • install rpi-lgpio library
pip install rpi-lgpio
  • delete the implementation condition at the end of the config.py file and force it to use RPi:
#if hostname == "raspberrypi":
#    implementation = RaspberryPi()
#else:
#    implementation = JetsonNano()

implementation = RaspberryPi()
  • run main.py (first cd to the folder containing this file)
Python3 main.py

@bibhu223
Copy link

IMG20241001084849
I have already tried this way ,, but it's showing error
Runtime error : Cannot determine SOC peripheral bas address

@bibhu223
Copy link

bibhu223 commented Oct 1, 2024

@mahdiaslanimk Thank you ,, i reboot the system now it's working on python ,, but it's very slow SPS , I was using pi zero W , In C the speed was very good .. but in this case 4kHz in single channel maximum .. How to increase the speed , One more thing the sample rate is not consistent , in my python program I am using some software smoothing and filtering ,which requires constant sampling rate ..but during data acquisition the sample is fluctuating...how to deal with this .

@bibhu223
Copy link

bibhu223 commented Oct 3, 2024

@ChironeX1976 , Have you tried with raspberry pi 5 with C , I am not able to run on C with pi 5 .

@mahdiaslanimk
Copy link

mahdiaslanimk commented Oct 3, 2024

@bibhu223 have you enabled SPI interface in the config:
sudo raspi-config

@bibhu223
Copy link

bibhu223 commented Oct 3, 2024

@mahdiaslanimk
n@raspberrypi:~/adc/hat/c $ sudo ./main
ADS1263 Demo
/***********************************/
Current environment: Debian
Please make JETSON !!!!!!!!!!
Segmentation fault
...This is error I am getting

@bibhu223
Copy link

bibhu223 commented Oct 4, 2024

@mahdiaslanimk yes it's running on python.
But the above issue is coming when I run in C . As I need little bit higher data rate ....so I was trying with C . But not able to run.

@mahdiaslanimk
Copy link

@bibhu223 i didn’t try the C codes. Have you tried @E-wallace0001 ‘s suggestions or @schwebke ’s codes to speed up data acquisition using python?

@bibhu223
Copy link

bibhu223 commented Oct 4, 2024

@mahdiaslanimk yes , but still if I am plotting the voltage data in real time ...the frequency of data rate is only 40-60Hz ,,

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants