Skip to main content
XZhen.2
Associate II
May 17, 2022
Question

Peak detection with adc

  • May 17, 2022
  • 4 replies
  • 2803 views

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.

This topic has been closed for replies.

4 replies

gregstm
Senior II
May 17, 2022

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).

XZhen.2
XZhen.2Author
Associate II
May 17, 2022

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.

gregstm
Senior II
May 17, 2022

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.

Senior
May 17, 2022

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.