There is an application note on the Microchip website describing just exactly what you want. It uses a PID algorythm. Peter