Electronic – arduino – Filter 5v pulse from micro input

arduinofiltermicrocontrolleropto-isolatorpulse

I am monitoring an external system which sends out a 5v pulse every 2 seconds when in normal mode. When the motor is working, it sends out a constant 5v designed to power a flashing light or LEDs as a warning system. When the pulse is not present, it is 0v. There is currently nothing connected to this, and I want to feed it into a micro so that I can monitor it (i.e., know when the device is active and send the appropriate signal to me).

There will be an optocoupler between the two circuits as these are powered independently (although now that I'm thinking about it, I certainly could integrate my micro into the existing framework, but that's not how it's currently setup).

I know I could programatically take out the pulse, by putting the input on an interrupt and waiting an appropriate amount of time before retesting, a kind of debounce. But I would like to know if I could do it by filtering out the pulse through circuitry.

My initial thought was to filter anything (for example) below 5Hz (since the pulse is at 1/2 Hz) and that I would need a high pass filter. But then someone pointed out to me I needed a LOW pass filter since the constant 5v I want to test for is actually at a lower frequency than the pulse.

As an additional point, the output of the filter will be driving a low impedence opto with no other load. I have no idea how to take this into consideration.

Any help would be appreciated.

Best Answer

If you truly want to filter the pulses via hardware, a low pass filter (LPF) is definitely what you want. It will PASS the low frequencies and attenuate the higher frequencies. You are looking for DC values which are of inherently lower frequency than any pulse train. The simplest way is to implement a first order LPF using a resistor and capacitor. The cutoff frequency is then

\$f_c = \frac{1}{2\pi RC}\$

schematic

simulate this circuit – Schematic created using CircuitLab

However, the response is going to be pretty slow. It will take a noticeable amount of time for the capacitor to charge up. Also there could be quite a bit of ripple depending on what size components you choose. To alleviate some ripple, you could use a second-order filter via the Sallen-Key topology.

schematic

simulate this circuit

If each resistor and each capacitor is the same value, the cutoff frequency will be the same as previously.

Whichever you choose, the output voltage will be dependent upon the duty cycle of the pulse. Therefore, if the pulse is low and high for equal amounts of time, and the amplitude is 5V, the output of the filters will be 2.5V. If you aren't using a comparator or ADC input on the microcontroller, you will need to implement a comparator as well. Since there will be some ripple on the output of the filter, a comparator with hysteresis will be necessary. From an Analog Devices article:

Comparator with Hysteresis and Calculations

Now you can probably see why using an input capture interrupt is probably the best bet. It is likely less work and definitely cheaper. Had your pulse frequency been higher, an analog solution may have been more useful.