0

Metro M4 high speed ADC (using DMA)
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

Metro M4 high speed ADC (using DMA)

by BryonMiller on Wed Jun 13, 2018 2:37 pm

Hi Everyone,

I've been having fun with my Metro M4 Express. One of the things I wanted to play around with getting analog samples at very high rates. I developed the code to enable a DMA channel and connect it to one of the analog inputs (A0..A5). I thought I'd share it in case anyone might find it useful.

See the attached zip with a directory containing adcdma.ino and a utility file called adcdmautil.ino. I'd be curious to hear back from anyone who might try this out.

Bryon
Attachments
adcdma.zip
(4.74 KiB) Downloaded 24 times

BryonMiller
 
Posts: 103
Joined: Fri Mar 04, 2016 10:34 am

Re: Metro M4 high speed ADC (using DMA)

by adafruit_support_mike on Thu Jun 14, 2018 3:41 am

Interesting.. thanks for posting the code!

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

Re: Metro M4 high speed ADC (using DMA)

by jrmclaugh on Wed Aug 01, 2018 11:41 pm

Hi BryonMiller!

I've gotten your sample running and am now trying to adapt it to my app.

I can't seem to find how to set/calculate the sample rate and whenever I try to do any actual processing on the data it locks up the Metro. Presumably it's too much work in the interrupt, but I'm not clear how to reduce frequency of that work to a manageable level. I'm investigating now, but any tips?

The useful registers seem to be the GCLK->PCHCTRL[ADC1_GCLK_ID], CTRLA PRESCALER bit, and the SAMPCTRL.

jrmclaugh
 
Posts: 4
Joined: Fri Jul 13, 2018 12:32 am

Re: Metro M4 high speed ADC (using DMA)

by BryonMiller on Thu Aug 02, 2018 10:21 am

Hello jrmclaugh,

I can't seem to find how to set/calculate the sample rate

You're right I did not provide a way to slow it down. I'd have to rescan the SAMD51 datasheet and recreate my thought process when I came up with this and see if I could post an example of slower sampling.

Rather than that let me tell you what I did. Full disclosure - I have not actually used the 1MSPS data but I did something very similar on a M0 machine. I made an oscilloscope with a feather M0. In this case the maximum sampling rate I could muster was 0.5M SPS. Many times, when using the 'scope, you don't need full speed, you might only need a subset of the samples. It all depended on the "sweep speed" desired. But almost always I would have a trigger condition I wanted satisfied. So I would scan each full-speed buffer looking for the trigger. Once the trigger occurred I would take points out of the full-speed buffer spaced at a sample-spacing corresponding to the desired sweep speed and place them into a sweep buffer. All calculations requiring anything but +/- math or greater/less comparisons (especially any floating point calculations) were performed in the main task, not the interrupt routine.

I also measured and saved the microseconds at the start of the interrupt routine and also at the end. With this data I could get a measurement of how busy the machine was. As you might imagine, the busiest time was when searching the entire buffer looking for the trigger. The actual act of taking a point out of the full-speed-buffer and saving it in the sweep buffer was relatively fast. While looking for the trigger condition I could easily have the M0 more than half consumed in the interrupt routine. The M4 is faster than the M0 so even with twice as much data per second I think moving my 'scope to a M4 would go smoothly. (I'm waiting for the M4 Feather to come into stock to find out.)

So for your case try to pull the data out of the high-speed buffer at whatever spacing corresponds to your needs. But no matter what, you are going to need enough of a machine to process the data and make results available at whatever speed you decide.

Post back here with your results!
Bryon

BryonMiller
 
Posts: 103
Joined: Fri Mar 04, 2016 10:34 am

Re: Metro M4 high speed ADC (using DMA)

by DanaK6JQ on Thu Aug 09, 2018 4:02 pm

BryonMiller wrote:Hello jrmclaugh,

I can't seem to find how to set/calculate the sample rate

You're right I did not provide a way to slow it down. I'd have to rescan the SAMD51 datasheet and recreate my thought process when I came up with this and see if I could post an example of slower sampling.

Rather than that let me tell you what I did. Full disclosure - I have not actually used the 1MSPS data but I did something very similar on a M0 machine.


I've done something similar, though without DMA, on the Metro M4 Express. I haplessly figured I would use Atmel START (Atmel Studio 7, Atmel-ICE) to port a DSP modem project I already have running on STM32F4xx parts to the SAMD51; the hardware averaging in the ADC is appealing.

Because I want a precise sampling rate for DSP, I configured a DPLL and Generic Clock to produce 9600 events/second, and configured that even to trigger conversion on the ADC. That's working as expected; note that you don't configure the ADC for free-running, and you don't need to start conversion, the event does it for you.

DanaK6JQ
 
Posts: 16
Joined: Thu Jun 15, 2017 2:38 pm

Please be positive and constructive with your questions and comments.