0

Resource for DSP on M4?
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

Resource for DSP on M4?

by dmulkey on Tue Mar 05, 2019 5:44 pm

Hi there,

I'm hoping to use one of the M4 boards to the fullest extent of their 1 MS/s ADC and DAC. I want to take in a signal, do some fairly straightforward math on it, and spit out the new signal.

I can find examples for doing this in CircuitPython, but my understanding is that can't run faster than a few Hz.

Are there any DSP-novice examples for doing this or for how to get started with the CMSIS library?

Thanks for your time.

dmulkey
 
Posts: 3
Joined: Tue Mar 05, 2019 5:39 pm

Re: Resource for DSP on M4?

by adafruit_support_mike on Wed Mar 06, 2019 12:18 am

I'm afraid we don't know of any DSP code yet.

CircuitPython will always be slower than compiled code, because the interpreter has to do a lot or work behind the scenes. As a rule of thumb, you can expect any interpreter to be about 10x slower than compiled code.

To use the ADC at anything approaching its 1Msps rate, you'll have to use the DMA engine or work with low-level C code. Every peripheral in a SAMD microcontroller has its own clock source, which may or may not have any connection to the microcontroller's CPU clock. Devices operating at different rates can't communicate at will, so there's a clock synchronization system that finds a rate and frequency where the devices can talk. Any time you do something outside that synchronized loop, you have to re-sync the CPU and peripheral.

analogRead() does a sync every time it's called, which imposes more of a limit on sampling rate than the CircuitPython interpreter would.

This thread has a zipfile of code that uses DMA to pull information from the ADC faster than analogRead() can do:

viewtopic.php?f=63&t=136914&p=689277

adafruit_support_mike
 
Posts: 58340
Joined: Thu Feb 11, 2010 2:51 pm

Re: Resource for DSP on M4?

by dmulkey on Wed Mar 06, 2019 1:27 pm

Thanks Mike. Maybe I should step back and instead of asking a specific question about one way to do what I want, I should ask a high-level question of how to do what I want.

What's the easiest way to stick A/D --> math --> D/A in a control loop faster than 5 kHz with low jitter? I imagined the M4 boards might be a good candidate, but what would you say? If that's an unrealistic expectation, what is realistic easily and what would the hard way to make it work? The math isn't anything crazy, it's just something I can't really implement in analog components.

Cheers,

dmulkey
 
Posts: 3
Joined: Tue Mar 05, 2019 5:39 pm

Re: Resource for DSP on M4?

by adafruit_support_mike on Thu Mar 07, 2019 12:28 am

The SAMD51 operates at 120MHz, so the math part shouldn't cause much delay.

We have CircuitPython code that plays audio files through the DAC, so getting speed there shouldn't be a problem. The low-level parts of that code are written in C, and you're welcome to use that code as a reference for your own:

https://github.com/adafruit/circuitpyth ... le/audioio

DMA-based sampling seems to be the fastest way to run the ADC, since it takes the microcontroller out of the time-critical loop. The DMA engine can pull data from the ADC as it's generated and store it in memory, and the microcontroller can read the memory on its own time.

adafruit_support_mike
 
Posts: 58340
Joined: Thu Feb 11, 2010 2:51 pm

Re: Resource for DSP on M4?

by dmulkey on Fri Mar 08, 2019 12:24 pm

Thank you Mike! I'll take a look at all of that then.

Cheers,

dmulkey
 
Posts: 3
Joined: Tue Mar 05, 2019 5:39 pm

Please be positive and constructive with your questions and comments.