I'd like to implement the following device: it accepts PWM input 5V p-p, and then produce logical zero (GND) at the output when any signal (duty cycle >0) is present and logical one (VCC) otherwise. My first idea was to use RC integrator with an rail-to-rail op-amp and it works, but has a flaw - when PWM signal disappears from the input, it took some time to discharge the capacitor (i.e. output goes slowly from zero to one), although I would like transitions to become as fast as possible. Schematic goes below.
R1 used to adjust threshold. I also tried to feed op-amp output to noninverting input of another op-amp in same comparator configuration, but it produce constant output regardless of whether PWM input is present. Schematic looks like this:
I think I either doing something wrong regarding second op-amp, or missing some concept of using it. Any help will be highly appreciated.