Electronic – Failed to use a low pass filter in order to convert PWM input to digital output

filterlow passpwm

I want to convert a servo control signal to a digital 5V or 0V output.

This is the format of my PWM signal:

enter image description here

The different thing is my input pulse width will be either 1ms (minimum) or 2ms (maximum.) There can be a slight noise but there are no values like 1.5 ms. Only 1 or 2.

I tried to create a circuit that does this:

enter image description here

When I measure Vout:

  • 1 ms pulse width: 170 mV
  • 2 ms pulse width: 295 mV

I really do not know why it did not work.
I was expecting this:

  • 1 ms pulse width: 0V
  • 2ms pulse width: 5V

Do you guys know why didn't it work and what I can do to improve it?

Best Answer

From the link in the diagram, I assume you are using a microcontroller, possibly an Arduino?

In that case, I would connect the PWM input to an interrupt pin and use the pin-change interrupt to trigger an Interrupt Service Routine (ISR) to measure the on-time of the pulse. The ISR would set/reset a flag to indicate whether it was 1 ms or 2 ms.