cancel
Showing results for 
Search instead for 
Did you mean: 

ADC - figure out exact signal duration

parsec
Associate III
Posted on November 23, 2016 at 10:12

I've been looking for info on this subject for some time and cannot find any references, possibly because I'm not an EE and don't have full understanding of all the ADC terminology and consequently using the wrong search terms.

My question: How do I define or limit the total duration of a sampled signal? I want my  resulting signal (buffer) to contain exactly 512 milliseconds of data.

Details/how it is supposed to work:

1. Signal is sampled at 1 MHz, single channel continuous.

2. Sampling will be triggered by analog watchdog if signal exceeds set threshold level.

3. Use DMA, interrupt when buffer full.

It is &sharp3 that I am not clear on how to dimension to get the desired result. Do I calculate total signal duration by counting cycles/nanoseconds used for each individual sample and dimension the DMA buffer accordingly? Or make the watchdog interrupt start a timer that interrupts sampling after the desired time period has elapsed? Or what is the proper/recommended way of achieving this?

I don't necessarily need source code, just trying to understand the concept. Any pointers would be welcome.

#stm32f4-adc
4 REPLIES 4
AvaTar
Lead
Posted on November 23, 2016 at 13:03

> 2. Sampling will be triggered by analog watchdog if signal exceeds set threshold level.

 

I suppose that means starting the continuous sampling.

> I want my  resulting signal (buffer) to contain exactly 512 milliseconds of data.

 

> 1. Signal is sampled at 1 MHz, single channel continuous.

 

That would make 512.000 samples, one sample each microsecond for 512000 microseconds.

You already got a serious problem here - the is no STM32 with that much buffer space available (one megabytes for 16-bit samples).

The second problem is, DMA supports up to 64k items at once, not 512.000.

You need to ''partition'' you task.

parsec
Associate III
Posted on November 23, 2016 at 13:50

Thanks for answering AvaTar!

 

 

I suppose that means starting the continuous sampling.

Yes

That would make 512.000 samples, one sample each microsecond for 512000 microseconds.

 

 

It would be a problem except that I mistakenly wrote millis instead of micros 🙂 Signal is supposed to be exactly 512 micros duration. (We're switching from another MCU to STM32F415RG and need to maintain backwards compatibility with Windows software that is receiving and further processing this data.)

So any recommendations on the best proper method to stop sampling after 512 µs?

AvaTar
Lead
Posted on November 23, 2016 at 14:25

> It would be a problem except that I mistakenly wrote millis instead of micros 🙂

 

>...

 

> So any recommendations on the best proper method to stop sampling after 512 µs?

 

Well, small typos can change the context quite dramatically ...

That would make 512 samples (assuming 1 kByte), which should not be a problem.

My approach would be to configure the DMA for the required number of values (512

half-word sized items, i.e. 16 bit), and a TC interrupt (TransferComplete).

In the TC interrupt (that belongs to the DMA), you would need to deactivate the sampling.

I'm not convinced that an exact 1Msps rate can be achieved by continuous sampling, and

 would rather try triggering the ADC by a timer. In that case, one would need to stop the timer in the TC interrupt.

There are many SPL examples for using the ADC (also in continuous mode), and using ADC with DMA. Not sure about CubeMX, I don't use it.

Not sure if your analog watchdog functionality as trigger is possible with the same ADC channel, I never tried that.

You might need to disclose the MCU to get pointers to actual example code.

parsec
Associate III
Posted on November 23, 2016 at 17:26

Thanks for your input, now I feel more confident about which direction to take.

MCU is F415RG.

I will try using a timer to drive the ADC. Analog watchdog is mostly for convenience and it would be an elegant solution if it could actually start the timer when needed. But if it doesn't play well with timer driven sampling then no big deal, I'll just have to check for excursions from reference voltage level programmatically for each signal in that case.