ADC and timer(s): Measuring moving average peak voltage of PWM signal with varying amplitude
I want to measure a moving average of the amplitude of a fix frequency, fixed dutycyle PWM signal with slowly varying amplitude but in a noisy environment (DC motors).
I want to use as little as possible CPU power to do this and have the ADC do this for me. I have an internal signal coming from a timer that is in sync with the signal to measure. I can use this as a trigger.
Below is what I try to do:

- use the internal trigger from the timer on the chip that actually generates the PWM signal
- wait 1/4th of the onPeriod before taking any samples to filter out rising time or overshoot
- then take N samples and filter out noise by taking the arithmetic average
- keep a constant moving average of the M past cycles (3 in the drawing, 100 in reality)
- Store this result in an ADC register such that the application can always retrieve the last 100ms average
So far, I figured out 1 (interconnect of timer output channel and ADC external trigger) and 3 (oversampling) by reading the reference manual and think I can do 2 by using a basic timer inbetween first timer output and ADC. But I completely struggle with 4 and 5.
Can this be done? I am using STM32L4 and F4/7.
