cancel
Showing results for 
Search instead for 
Did you mean: 

Peak detection with adc

XZhen.2
Associate II

Hi guys.

I have 2 GPIOs, one is used as a PWM, the other one is used as ADC.

and the peak comes in the falling edge of the PWM singal.and the plus width is only like 2us.

I want to get the value of the peak voltage using ADC.

The problem is, if I use a interrupt like PWM falling edge, then start the adc, it will take more than 2us. so I cannot get the right value.

is there any solutions to this problem?

PS: I am using STM32G4,fast enough I think.

4 REPLIES 4
gregstm
Senior III

Is it possible to use a simple peak detection circuit (using a diode and capacitor)? Perhaps another gpio pin could be used to reset the peak if needed (via a FET).

Hi grestm.

I need to use the value of the peak voltage in my algorithm.

i know the exact timing of the peak voltage shows, but cannot manage to messure it due to the siganl frequency is about 500k.

That chip has a fast ADC. You should be able to hardware trigger the ADC using the waveform/GPIO edge and DMA the result to a buffer - and use the DMA half-full interrupt to process the buffered data at a more relaxed rate.

SStor
Senior

Simply start ADC in continuous mode with automatic transfer in circular DMA buffer and ~1µs sampling time.

On edge interrupt read sample position in circular DMA buffer and corresponding value at this position.

So you have also some more samples around the edge available.