Converting mark space ratio to DC
You want a plain old low pass filter.  What you show is a peak detector, which won't give you the average level.

One way to look at this is that you have a low frequency signal you want to measure, but it has 500 Hz to 100 kHz pulses superimposed on it.  The solution is to filter out frequency components of 500 Hz and higher, leaving the desired signal.  A simple series of R-C filters will do this.  The exact design of the filter depends on what the upper frequency content of the duty cycle signal is, and the minimum signal to noise ratio you require.  You didn't specify those, so here is a quick stab at it:



The rolloff of each R-C is 100 Hz, so 500 Hz will be attenuated by about 5 each stage, and 53 = 125 for all stages.  Actually the 500 Hz attenuation will be a bit more than that, but this gives you a quick minimum figure.  Put another way, this is good to 7 bits accuracy.

As a separate issue, you should put the opamp after this filter, not before it.  The opamp response to sudden steps will be non-linear, distorting the result.  The filter also adds significant impedance, which following with a buffer fixes.