PWM with op-amp, but can't figure out formulas/how it works
Okay, the basic function of this circuit is as an oscillator. The frequency and the duty cycle both vary with the input voltage. Maximum frequency is at Vin = 2.5V where the duty cycle is 50%. I'm just stating that.
The capacitor charges or discharges through R3 toward Vout of the comparator (which we can reasonably approximate with either 0V or 5V in this particular case of the MAX998 with the relatively high resistor values given (datasheet says typical 0.1V drop with 2mA current).
So let's calculate the thresholds as a function of the input voltage:
It's just a voltage divider, the voltage at the non-inverting input of the comparator is
Vp = Vin/2 + Vout/2, or Vin/2 + 2.5V for the capacitor charging and Vin/2 for the capacitor discharging.
Note that the common mode voltage range of this particular comparator is only up to 5V - 1.2V = 3.8V, above which the output is &quot;unpredictable&quot; unless at least one of the inputs is within CM input range.
So we may conclude that the maximum input voltage for reliable operation is 2.6V using the MAX998. This will limit the maximum reliable &quot;on&quot; duty cycle. The input common mode voltage extends a bit below ground so we can apply an input slightly below ground to get 0% duty cycle.
Now, we only have to calculate the time it takes to charge/discharge between the two threshold voltages as a function of the input voltage. Sadly, the equations in the EDN article you linked seem to have some problems such as unmatched parenthesis.
Given that voltage v(t) of a capacitor being charged from Vi towards Vf is
v(t) = Vi + (Vf - Vi)(1-exp(-t/tau))
I get for charge and discharge times:
tc = -\$\tau\ln(1- \frac{5}{10-V_{IN}}) \$
td = -\$\tau\ln(1- \frac{5}{5+V_{IN}}) \$
where \$\tau\$ = RC
So the maximum frequency (when Vin = 2.5V) is about 0.455/RC
We can calculate the maximum duty cycle with Vin = 2.6V, and it's about 51%.
And the frequency with Vin = 0.1V is about 0.22/RC with a duty cycle of about 15%.