1
\$\begingroup\$

[Difference Eqution]:

$$LPF_D=\frac{0.1441z^2+0.2881z+0.1441}{z^2-0.6777z+0.254}$$ With a sample of \$T_s = \$ 8e-6 seconds, in scientific E notation.

The difference equation:

\$Y\$ = Output

\$U\$ = Input

$$Y_i =0.1441U_{i}+0.2281U_{i-1}+0.1441U_{i-2}+0.6777Y_{i-1}-0.254Y_{i-2}$$

I first came here with an Atmel Atmega328p asking if I can sample an audio signal while implementing a digital filter I created.

I got the audio sampling down but soon came to realize the processing power wasn't there for the Atmel Atmega. You guys showed me a new way to sample from the ADC which is the DMA. Saying its much faster. I had an ADC sampling at 36 KHz while that was going I wanted to implement a difference equation. I learned that the difference equation couldn't be executed within the 36 KHz sampling time. I took your suggestions and bought a STM32L43KC.

A massive upgrade. DMA, DSP, 80 MHz. over the weekend I got where I left off with the Atmel Atmega.

Got the ADC running with DMA on the STM32 chip, but I realized something. I would need to have an interrupt in the DMA (Transfer Complete Interrupt) when the ADC samples are ready. If I am sampling the ADC at 36 KHz and the interrupt is enable on the DMA would that mean the CPU is still going to be interrupted every 36 KHz? Which still leaves me no room for implementing that digital filter?

Unless this time the MCU I am using has a DSP and that can execute my difference equation within 27.7 us otherwise I am seeing my self in the same situation. How do people actually sample and do DSP at the same time?

The only way I am thinking is using two MCU. Have one do the sampling interrupt send it over SPI, UART and then the second MCU interrupt when it receives it and do the DSP.

Any thoughts on this guys?

All I want to do is sample an audio signal at a good enough frequency to avoid aliasing then implement a digital filter that I worked on and shove it into a DAC and hear it.

\$\endgroup\$
1
  • \$\begingroup\$ Comments are not for extended discussion; this conversation has been moved to chat. \$\endgroup\$
    – Voltage Spike
    Jun 8 '20 at 2:24
0
\$\begingroup\$

If you can't solve it with one MCU, you can't solve it with two MCUs either. If you send the ADC data to another MCU, it needs to receive it (perhaps via interrupts, or DMA) and you still are left with same issue that you have data coming in from somewhere at some rate and you need to process it, what then, a third MCU?

The point is you process ADC data in blocks of many samples, for example 1000 sample blocks. Set up memory for 2000 samples and set up the DMA in double-buffered or ring-buffered mode and make it generate interrups every 1000 samples when one block is complete. After processing one block set up a DMA to DAC to play the processed data.

\$\endgroup\$
3
  • \$\begingroup\$ So you are trying to say, instead of sampling it on the spot, store a X amount of samples into a buffer than once the buffer gets full do processing on it. Wouldnt it be faster to process each incoming ADC value? for example if I do use the buffer I would find it confusing when it will come to the difference equation. If i were to process each ADC sample on the spot I would know thats the current value. When storing in a buffer I would have multiply current values wouldnt that cause lag as well? \$\endgroup\$
    – Leoc
    Apr 27 '20 at 6:44
  • \$\begingroup\$ If you have to interrupt and go process each sample, instead of say 1000 samples, there is 999 more overhead invoking and returning from interrupt, which could be better spent for running code. If you interrupt for each sample, there is no benefit from using DMA then. And I don't see why it would be any different reading data from ADC or from buffer when processing it. Yes a buffer will introduce delay. If you want real-time processing then simply do it without DMA in the ADC conversion complete interrupt then. \$\endgroup\$
    – Justme
    Apr 27 '20 at 7:08
  • \$\begingroup\$ I see fair. So the challenge is if I can implement the digital filter in that 1000 sample before the other sample comes in then \$\endgroup\$
    – Leoc
    Apr 27 '20 at 18:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.