Sampling audio with STM32F7 - Page 1
Forum section: electronics / general

author: AitchJee
author_rank: Newbie
timestamp: January 07, 2020, 07:24:55 pm
content: HiI am currently working on a project which includes sampling audio from three different hydrophones to find the phase-shift between the different signals. The signals are between 20-40kHz. I am using a STM32F767ZI for the sampling and wondering if anybody can help me/ give me some guidance.I have managed to set up the peripherals with cubeMX and written code for ADC using the DMA for one signal, but i`m kind of stuck here. Ive understood that the DMA is circular, so that when its full, its first values are overwritten. What I don`t understand is how to gather the data from the buffer into a textfile or something i can use to do the signal processing and comparing afterwards? I have also tried to write code using a timer to trigger the ADC with DMA to get a specific frequency ( 100kHz).More specifically the questions i am asking is1. When the signal is sent through the DMA to a buffer, how do i transfer the data before the buffer is overwritten, and to where?2. How do I use a timer with ADC and DMA to get a specific frequency?Any help / examples of similar code will be appreciated, as i am having a hard time figuring out the ways of STM32 MCUs.

author: thm_w
author_rank: Super Contributor
timestamp: January 07, 2020, 10:43:28 pm
content: cubemx will give settings for either normal or circular buffer, which one is used is up to you.There are interrupts (and HAL callbacks) for DMA buffer full and buffer half-full, so you can grab the data from the buffer and process it or store it somewhere else.This might be relevant:https://stm32f4-discovery.net/2017/07/stm32-tutorial-efficiently-receive-uart-data-using-dma/You can use a timer to trigger the ADC start of conversion, either manually inside the timer interrupt, or perhaps directly as well. Check the F7 HAL for example projects, if you are using that.https://community.st.com/s/question/0D50X00009XkiAV/trigger-adc-conversion-with-a-timer

author: AitchJee
author_rank: Newbie
timestamp: January 07, 2020, 11:28:26 pm
content: Thank you for the replyRegarding the interrupts DMA full or half-full. My general worry is if the USART protocol with DMA is fast enough to store the data before the ADC overwrites the buffer with a high sampling frequency (e.g over 100kHz)?

author: thm_w
author_rank: Super Contributor
timestamp: January 08, 2020, 12:22:38 am
content: Quote from: AitchJee on January 07, 2020, 11:28:26 pmThe USART is just an example of DMA processing, in your case it would be ADC -> memory, instead of USART -> memory.16 bit @ 100kHz = 1.6mbps should be possible to store in memory. Actually the USART is probably capable of that too if necessary (~4Mbits/s). If we are just talking about one or two ADC channels.

author: MasterT
author_rank: Frequent Contributor
timestamp: January 08, 2020, 01:22:32 am
content: I'm sure F7 could process data at 100 ksps for all 3 channels, running fft say 8k, probably 32k. Than a few bytes of results to send over usart

author: dmendesf
author_rank: Frequent Contributor
timestamp: January 09, 2020, 03:09:42 am
content: If the frequency of input signal is known then run a goertzel from each half buffer and print only magnitude/phase of each channel.