I am looking for a way to filter the signal from the pulseIn function. I want to get rid of both spikes on the falling and rising edge.
I tried using two filters
Exponentially-Weighted Moving Average (EWMA) -> failed to remove the second spike (falling edge) Debounce -> the value is not updated until a constant speed is reached. In my case it can take up to 30 seconds. Therefore, it is not applicable in my situation.
Board: Atmega2560 (Arduino Mega)
uint32_t pulse = pulseIn(13, LOW, 60000);
Signal that I measure -> from 20Hz (50% duty) to 1100Hz(50% duty)
The problem is not in the electronics. The circuit works just fine. I feed the signal from the PWM generator. On the oscilloscope I can see the correct signal. I take the measurement directly on the microcontroller leg. Not even the slightest ripple.
PulseIn, instead of returning a value of '0' immediately,
returns slowly increasing values
Strong chance it's just noise on the leg (hard to see with a CRO or DMM) or line capacitance . Just add a small capacitor from the leg to GND, or R+C if needed..