How does this power supply circuit work? (MCU + LM317)
The opamp acts to make the junction of R6 and R7 the same voltage as Vc. And the R6/R7 junction is a fixed proportion of Vl. So 


Vl = Vc x (R6 + R7) / R7.


Because - the opamp works to set it's input terminals equal when negaive feedback is applied. Non inverting input is set to target voltage by PWM. If R6/R7 feeback point (call this Vf) is too low then opamp output will increase positively to increase Vadj on LM317 which will increase Vl and thus Vf. Opposite applies when Vf is too high. 

All the rest is "engineering" (or not :-) )

The opamp is effectively forming a dynamic value of the "datasheet's R2" in series with R4 on the circuit.

R5 drops 1.25V by design of the IC so R4 drops whatever else is required to allow the opamp to balance things as above.

This allows the opamp output to operate at a lower voltage than Vl. This is not especially needed here as the opamp operates from V2 which is at least 3+ Volts above the mzimum level Vl can get to (due to LM317 design) so R4 actually limits the lowest voltage that can be achieved by Vl (due to the division of R5 and R4.)

For best flexibility here R4 = 0 ohms!. Some opamps will not go to full Vdd but here there is ample headroom for almost any opamp as Vs-Vl = LM317 Vdropout_min + 1.25V or about 3.5V. An eg LM324 or LM358 would work OK there.



R3 is something of a mystery - it is not needed to make the circuit work. It adds a positive offset to the PWM voltage which should be unneeded. The circuit designer may have had something special in mind when he added it. Can you provide a link to the original article?