Pedal Pi sample rate

5 years 7 months ago #1505 by Ham
Pedal Pi sample rate was created by Ham
Hi
I have a PedalMega and am thinking of getting a PedalPi as well. I have read through the posts on how it works and can’t work out the sample rate from the code - can you explain that? There seem to be no clear timing functions.
I presume on the arduinos the sample rate is set as the interrupt frequency but this doesn’t apply to the Pi.
Thanks for any help
Paul

:guitarfende :pedalmxr:

Please Log in to join the conversation.

5 years 7 months ago #1506 by yojimbo
Replied by yojimbo on topic Pedal Pi sample rate
I'm no expert (But I'm willing to play one on the internet :silly: ) so someone correct me where I'm wrong/making things up. I believe this is one of the issues in using a raspberry pi / linux computer for this type of application. On an arduino or similar board, you control the entire execution loop with your program, so can get much more precise timings. There is no OS or other applications competing for compute time/resources. On the Pi, even if you set a interrupt / timer there is no guarantee of precise timing. This is an example of fly swatting with a shotgun, though...the Pi has a tremendously large processor for this application, so unless you are running a bunch of things on your Pi while trying to run the Pedal effects, you won't see any issue, but may notice a bit of noice/jitter from time to time. I do notice that on my pi zero w using wifi I have a bit of issue with some of the effects. I haven't dug in to find out if this is caused by wifi rf noise, or processor timing from handling the wifi stack/data input, but may try in the future.

For the examples given, I believe that the sampling frequency for the pedal_pi is limited by the SPI bus and the voltage input to the ADC. good background reading on the forum at: Link: DSP on Raspberry Pi and Using ADC with rPi

I think purists would not use a raspberry pi for audio applications, but this is a fun project that can teach you a lot about electronics, programming, DSP, audio, and make a fun guitar effects pedal in the process. I bought a board and built it with my 13 year old son who is really getting into guitar playing. REALLY fun project for the both of us!! I don't think the Pedal Pi is ready for the recording studio or performance stage, but for the $$$ it is GREAT!

Just my $0.02

Please Log in to join the conversation.

5 years 7 months ago #1509 by Ham
Replied by Ham on topic Pedal Pi sample rate
Thanks Yojimbo.
Oddly both the links have the critical bits missing. The ADC link has lost a diagram and code and the other one has a last line which inplies a link to somethink good but bo link.
I am thinking the rate must be limited by the SPI rate, and as it is reading 3 bytes then something like SPI / 24 but I can’t get that to be 50khz.

Please Log in to join the conversation.

5 years 7 months ago - 5 years 7 months ago #1510 by Ray
Replied by Ray on topic Pedal Pi sample rate

On an arduino or similar board, you control the entire execution loop with your program, so can get much more precise timings

you are right, pi is more powerful but arduino is more precise (timewise).

On the Pi, even if you set a interrupt / timer there is no guarantee of precise timing.

I was thinking about using a RTOS (Real Timo OS) for the pedal pi, but at this time there isnt a great easy-to-use RTOS for the Zero. On top of that Raspbian is fantastic.

I do notice that on my pi zero w using wifi I have a bit of issue with some of the effects. I haven't dug in to find out if this is caused by wifi rf noise, or processor timing from handling the wifi stack/data input, but may try in the future.

Yes, its a common issue. Wifi and the effects working at the same time creates a lot of noise. There is a topic in the forum explaining how to disable the wifi so the effects sound better. I guess the wifi process interrupts too often the kernel and cannot cope with all working at the same time.

I think purists would not use a raspberry pi for audio applications, but this is a fun project that can teach you a lot about electronics, programming, DSP, audio, and make a fun guitar effects pedal in the process. I bought a board and built it with my 13 year old son who is really getting into guitar playing. REALLY fun project for the both of us!! I don't think the Pedal Pi is ready for the recording studio or performance stage, but for the $$$ it is GREAT!

+1 :P

So, going to the point:
  • pedalSHIELD MEGA: the sample rate could be adjusted by software (sometimes is interesting to get longer delays at lower resolution) The ADC reads at the same speed as the PWM signal (in the code: "#define PWM_FREQ 0x00FF // pwm frequency - 31.3KHz"). If you want to read more about this check: www.electrosmash.com/forum/pedalshield-u...o-play-audio?lang=en (the post is for the UNO but it is equally valid for the MEGA)
  • Pedal Pi: Sample rate bottleneck is the ADC, the MCP3202 (www.farnell.com/datasheets/1669376.pdf) working at 3V3 has a sample rate a bit over 50Ksps (from datasheet: " 50 ksps maximum sampling rate at VDD = 2.7V")

Please Log in to join the conversation.

5 years 7 months ago #1512 by Ham
Replied by Ham on topic Pedal Pi sample rate
Hi Ray
I can’t see in the datasheet how the adc controls the timing - the spi clock is pi powered. How dies the pi know a sample is ready?
Sorry - I know I have missed something just can’t figure out what!

Please Log in to join the conversation.

5 years 7 months ago #1513 by Ham
Replied by Ham on topic Pedal Pi sample rate
I am a bit further. The adc seems to want the clock rate to be 0.9Mhz for 2.7v - I had assumed a faster spi clock rate would be ok as long as there was a pause between samples and that the sample rate was 50khz. The only piece missing is the code says the spi rate is 4Mhz not 0.9MHz.

Please Log in to join the conversation.

5 years 7 months ago #1515 by Ray
Replied by Ray on topic Pedal Pi sample rate
Hi again!

Hi Ray
I can’t see in the datasheet how the adc controls the timing - the spi clock is pi powered. How dies the pi know a sample is ready?
Sorry - I know I have missed something just can’t figure out what!

Sorry for not being very clear. The SPI bus is much faster than the external ADC, so the bottleneck is the ADC not the SPI. The Pi does not actively know when the new sample is ready, but it just reads the ADC in a loop and if the new sample is ready, great! you read the new sample. If the new sample is not ready, the pi will read again the "old" sample, but it is not catastrophic, you will just get a redundant sample. It's kind of oversampling.

I am a bit further. The adc seems to want the clock rate to be 0.9Mhz for 2.7v - I had assumed a faster spi clock rate would be ok as long as there was a pause between samples and that the sample rate was 50khz. The only piece missing is the code says the spi rate is 4Mhz not 0.9MHz.


Yes, the SPI is configured to work at 4MHz, maybe is a bit over killing as you only need 0.9MHz, but as I said before is not that bad, the pi has plenty of computing power and maybe you can even apply an averaging mechanism to eliminate noise from samples.

Please Log in to join the conversation.

Time to create page: 0.073 seconds
Powered by Kunena Forum
Joomla SEF URLs by Artio