cancel
Showing results for 
Search instead for 
Did you mean: 

ADC sampling with timer?

D.K.
Associate II

I am using stm32f4 discovery board. I will record sound approximately at 5.56 kHZ. So i use 10 bit resolution 480 clock cycle PCLK2 at 21Mhz . When i press the button it will take sample for 10 seconds. Sampling frequency is okay. For 10 seconds record i couldn't create an algorithm how should i go further? How will i combine timer and adc sampling?

6 REPLIES 6
Ozone
Lead

I suppose you mean the 10 seconds timer, and not a timer to trigger individual ADC conversions (which would be 1s / 5560).

How about counting the number of samples ? Not a problem if you know sampling frequency and duration in advance.

Or you could either setup a TIM unit for 10s, or use the SysTick counter (the latter may conflicht with Cube/HAL).

Isn't the data size problematic ?

You would need two bytes per sample, giving roughly 54kBytes for intermediate storage.

I think the sampling rate and core performance would allow for blockwise processing, and continuous sampling.

D.K.
Associate II

Yes, i mean 10sec timer not for triggering. Yes i know sampling freq. and duration. I am planning to setup a time for 10sec.

It might be problematic. 10secs adc samplings will be approx. 70kBytes. Then, i will send to the sd card.

I think the sample counting method would be the safest one, i.e. yielding the exact same amount of samples each time.

Using a timer can introduce jitter when interrupts occur inbetween (both start and stop).

> 10secs adc samplings will be approx. 70kBytes. Then, i will send to the sd card.

I would use smaller packages, otimally the size of a SD card block.

You could use double buffering, and continuously stream data to the SD card.

D.K.
Associate II

In 1 second 5560 sample. 10 sec 55600 sample you mean i will count 55600 without using timer?

S.Ma
Principal

Get a timer to generate the trigger ADC sampling point, generating 5.56kHz pulse

Feed this pulse to the ADC trigger input signal or pin. Maybe use 8 bit ADC for smaller buffer to get started with?

Set DMA to push ADC results in a cyclic RAM buffer, use the ADC_DMA half transfer callback to process double buffering (continuous conversion with processing time to be careful with). Set the half size (in samples) to get your 10 second (5560 bytes x 10 sec x 2 double buffer in RAM!)

10 seconds with raw audio seems RAM demanding...

D.K.
Associate II

Get a timer to generate the trigger ADC sampling point, generating 5.56kHz pulse

A: What about ADC frequency? Timer for trigger at each 5.56kHz. Is it right?

Feed this pulse to the ADC trigger input signal or pin. Maybe use 8 bit ADC for smaller buffer to get started with?

A: I can use of course 8 bit but the resolution will be low anyways.

Set DMA to push ADC results in a cyclic RAM buffer, use the ADC_DMA half transfer callback to process double buffering (continuous conversion with processing time to be careful with). Set the half size (in samples) to get your 10 second (5560 bytes x 10 sec x 2 double buffer in RAM!)

A: Why you said 2 double buffer. 1 buffer might be easy.

As i understand, i should use timer+adc+dma but in where i adjust 10 seconds and what will be adc frequency?